I'm pretty new to PyMC, and I'm trying to implement a fairly simple Bayesian correlation model, as defined in chapter 5 of "Bayesian Cognitive Modeling: A Practical Course", which is as defined below:
I've put my code in an ipython notebook here, a code snippet is as follows:
mu1 = Normal('mu1', 0, 0.001)
mu2 = Normal('mu2', 0, 0.001)
lambda1 = Gamma('lambda1', 0.001, 0.001)
lambda2 = Gamma('lambda2', 0.001, 0.001)
rho = Uniform('r', -1, 1)
@pymc.deterministic
def mean(mu1=mu1, mu2=mu2):
return np.array([mu1, mu2])
@pymc.deterministic
def precision(lambda1=lambda1, lambda2=lambda2, rho=rho):
sigma1 = 1 / sqrt(lambda1)
sigma2 = 1 / sqrt(lambda2)
ss1 = sigma1 * sigma2
ss2 = sigma2 * sigma2
rss = rho * sigma1 * sigma2
return np.power(np.mat([[ss1, rss], [rss, ss2]]), -1)
xy = MvNormal('xy', mu=mean, tau=precision, value=data, observed=True)
M = pymc.MCMC(locals())
M.sample(10000, 5000)
The error I get is "error: failed in converting 3rd argument `tau' of flib.prec_mvnorm to C/Fortran array"
I only found one other reference to this error (in this question) but I couldn't see how to apply the answer from there to my code.
ss1 = sigma1 * sigma2
you should writess1 = sigma1 * sigma1
. Unfortunately, the results still are not "correct" all the time somehow.