I am trying to use write my own stochastic
and deterministic
variables with pymc3, but old published recipe for pymc2.3 explained how we can parametrize our variables no longer works. For instance I tried to use this direct
approach and it failed:
def x_logp(value, x_l, x_h):
if ((value>x_h) or (value<x_l)):
return -np.inf
else:
return -np.log(x_h-x_l+1)
def x_rand(x_l,x_h):
return np.round((x_h-x_l)*np.random.random_sample())+x_l
Xpos=pm.stochastic(logp=x_logp,
doc="X position of halo center ",
observed=False,
trace=True,
name='Xpos',
random=x_rand,
value=25.32,
parents={'x_l':0,'x_h'=500},
dtype=float64,
plot=True,
verbose=0)
I got the following error message:
ERROR: AttributeError: 'module' object has no attribute 'Stochastic' [unknown]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Stochastic'
or if I want to define an Exponential prior with the class that I have written:
class LogPrior(object):
def eval(self, value):
return 0.
def __call__(self, value):
return self.eval(value)
def sample(self, n=None):
""" Sample from this prior. The returned array axis=0 is the
sample axis.
Parameters
----------
n : int (optional)
Number of samples to draw
"""
raise ValueError("Cannot sample from a LogPrior object.")
def __str__(self):
return "<LogPrior>"
def __repr__(self):
return self.__str__()
I am wondering how could I define my own priors with pymc3
without using the available pymc
distributions?