bayesian

R bnlearn eval inside function

落花浮王杯 提交于 2019-12-20 02:39:17
问题 I am using the bnlearn package in R to train a Bayesian network. I have troubles with the following code (slightly modified bnlearn example code): library(bnlearn) data(learning.test) fitted = bn.fit(hc(learning.test), learning.test) myfuncBN=function(){ var = names(learning.test) obs = 2 str = paste("(", names(learning.test)[-3], "=='", sapply(learning.test[obs,-3], as.character), "')", sep = "", collapse = " & ") str2 = paste("(", names(learning.test)[3], "=='", as.character(learning.test

PyMC - variance-covariance matrix estimation

断了今生、忘了曾经 提交于 2019-12-19 04:59:51
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 5 years ago . I read the following paper(http://www3.stat.sinica.edu.tw/statistica/oldpdf/A10n416.pdf) where they model the variance-covariance matrix Σ as: Σ = diag(S)*R*diag(S) (Equation 1 in the paper) S is the k×1 vector of standard deviations, diag(S) is the diagonal matrix with diagonal elements S, and R is the k×k correlation matrix. How can I implement this using PyMC ? Here is some

How to combine the outputs of multiple naive bayes classifier?

好久不见. 提交于 2019-12-19 04:10:59
问题 I am new to this. I have a set of weak classifiers constructed using Naive Bayes Classifier (NBC) in Sklearn toolkit. My problem is how do I combine the output of each of the NBC to make final decision. I want my decision to be in probabilities and not labels. I made a the following program in python. I assume 2 class problem from iris-dataset in sklean. For demo/learning say I make a 4 NBC as follows. from sklearn import datasets from sklearn.naive_bayes import GaussianNB import numpy as np

Text Classification into Categories

雨燕双飞 提交于 2019-12-18 13:34:52
问题 I am working on a text classification problem, I am trying to classify a collection of words into category, yes there are plenty of libraries available for classification, so please dont answer if you are suggesting to use them. Let me explain what I want to implement. ( take for example ) List of Words: java programming language c-sharp List of Categories. java c-sharp here we will train the set, as: java maps to category 1. java programming maps to category 1.java programming maps to

pymc3: hierarchical model with multiple obsesrved variables

余生长醉 提交于 2019-12-18 13:27:54
问题 I have a simple hierarchical model with lots of individuals for which I have small samples from a normal distribution. The means of these distributions also follow a normal distribution. import numpy as np n_individuals = 200 points_per_individual = 10 means = np.random.normal(30, 12, n_individuals) y = np.random.normal(means, 1, (points_per_individual, n_individuals)) I want to use PyMC3 to compute the model parameters from the sample. import pymc3 as pm import matplotlib.pyplot as plt model

How to plot Bayesian prior and posterior distributions in one panel using R?

限于喜欢 提交于 2019-12-14 03:48:39
问题 I've tried several approaches, including qqmath , lattice densityplot() and a number of panel functions like panel.mathdensity and panel.densityplot . However, I couldn't get them to do what I want them to do. An internet search on this topic produces results which focus either on base plots in R or don't draw both distributions in one panel. I could use R base graphics, however, I also want to plot several distribution pairs and one panel for each pair. The books "RGraphics" and "Lattice:

pymc3 likelihood math with non-theano function

天涯浪子 提交于 2019-12-13 16:25:19
问题 I'm new to doing Bayesian inference. I'm trying to adapt a grid search code I wrote to Bayesian Monte Carlo Markov Chain approach, and I'm using PyMC3. My problem is that the code has to call a function that can't be rewritten in theano syntax. (The function relies on a piece of Fortran code in an f2py wrapper.) Here's the code I'm working with: with pm.Model() as model: # Independent parameters x = pm.Normal('x', sx, sd=incx*float(nrangex)/2.0) y = pm.Normal('y', sy, sd=incy*float(nrangey)/2

Coding a multiple integral function in R

二次信任 提交于 2019-12-13 16:06:33
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 2 years ago . With the goal of turning the following into a function, I was wondering how I can write the following double integral in terms of R codes?: ($\bar{x} = \mu$): 回答1: Assuming pi0 and pi1 implement your functions $\pi_0$ and $\pi_1$ in a vectorized way, a possible solution is: integral <- function(n, mu, s, pi0, pi1) { C <- (2 * pi)^(-n/2) C * integrate(f = function(sigmavec)

OpenBUGS error undefined variable

早过忘川 提交于 2019-12-13 13:20:31
问题 I'm working on a binomial mixture model using OpenBUGS and R package R2OpenBUGS . I've successfully built simpler models, but once I add another level for imperfect detection, I consistently receive the error variable X is not defined in model or in data set . I've tried a number of different things, including changing the structure of my data and entering my data directly into OpenBUGS. I'm posting this in the hope that someone else has experience with this error, and perhaps knows why

Bayes Learning - MAP hypotesis

烂漫一生 提交于 2019-12-13 10:52:09
问题 Suppose I have a set of hypotesys H = {h1, h2} mutual exclusive. For them P(h1) = 0.2 and p(h3) = 0.3 (prior distribution). Suppose we know also that P(Y=0 | h1) = 0.2 P(Y=0 | h2) = 0.4 where Y is an attribute (target) that can have two values {1,0}. Suppose finally that you observe the event Y = 0. Which one is the MAP (Maximum a posteriori) hipotesys? MAP is h1 MAP is h2 there's no enough element to find MAP MAP h1 = MAP h2 nobody of the possible answer above 回答1: Such question should be