Dear John,
sorry for the delay, I was travelling. Thank you, the last model is
exactly what I meant (this was the first thing I tried but it didn't
work for me - now I realized that due to bad mixing and not incorrect
syntax as I assumed). I also think, I made the mistake of taking a too
simple example compared to what I actually need to do. My actual
problem is that I'm trying to model my errors by asymetric gaussian -
for each y[i] I have sigma1[i] and sigma2[i] which give the stdev in
one and other direction, My naive guess would be:
from numpy import *
import pymc
from scipy import stats
N = 27
#value of super secret parameters for the data
dataSlope = .4
dataB = 100
#generate some fake data
dataX = stats.distributions.norm(loc = 50, scale = 40 ).rvs(N)
dataY = dataX*dataSlope + dataB + stats.distributions.norm( loc = 0,
scale
= dataS).rvs(N)
#these standard deviations are known
dataS1 = ones(N) * .7*sqrt(dataY)
dataS2 = ones(N) * .3*sqrt(dataY)
switch = pymc.Uniform('switch', 0, 1, size=len(dataX))
#broad priors for the slope/intercept
slope = pymc.Normal('slope', mu = 0, tau = 1.0/(600.0**2))
intercept = pymc.Normal('intercept', mu = 0, tau = 1.0/(600.0**2))
# equation for the line
@pymc.deterministic
def line (x = dataX, slope = slope, intercept = intercept):
return x * slope + intercept
@pymc.stochastic
def noise(switch=switch, dataSn=dataSn, dataSp=dataSp):
temp = zeros(len(dataSn))
for i in range(len(dataSn)):
if switch[i] < 0.5:
varian=dataS1[i]
temp[i] = -1.0*abs(pymc.Normal(mu = 0.0, tau =
varian**-2))
else:
varian=dataS2[i]
temp[i]= 1.0*abs(pymc.Normal(mu = 0.0, tau =
varian**-2))
return temp
#data
y = Lambda('y', lambda line=line, noise=noise: line + noise,
observed=True, value=dataY)
The switch stochastic 'switches' between the two gaussians. This
doesn't work, but I hope it is clear what I want to achieve. Do I need
in this case the container, if yes what is the proper syntax and is
MCMC going to be able to get the likelihoods itself or do I need to
define it?
Thank you very much! I'm really glad about how helpful and friendly
the pymc comunity is (and I'm not saying it only because I need
help! :) )
Cheers,
Robert