@junpenglao, thanks for your reply. I modified my code as per your suggestions. However, I got this error when I tried doing so :
AsTensorError: ('Cannot convert <function mu at 0x1c2ab42ea0> to TensorType', <class 'function'>)
I tried modifying the code further by converting the return value of the function to a tensor. This is the modified code :
basic_model = pymc3.Model()
with basic_model:
start=pymc3.Uniform('start',0,0)
a=pymc3.Uniform('a',0.01,0.1)
b=pymc3.Uniform('b',0.001,0.01)
e=pymc3.Normal("e",mu=0,sd=a+b*x)
def mu(e):
t = tt.dscalar('t')
t.tag.test_value = np.zeros(())
z=(1+0.2*((1+t)**float(3)-1))**float(-0.5)
def f1(xp):
integrate = Integrate(z,t)
val=integrate(start, x+e)
return val
f2=f1(x+e)
return tf.convert_to_tensor((f2*(1+x+e)))
y=pymc3.Normal('y',mu=mu,sd=0.5,observed=y_obs)
But I still get the same error. This is the full traceback :
Traceback (most recent call last):
File "<ipython-input-10-b47f07234c39>", line 21, in <module>
y=pymc3.Normal('y',mu=mu,sd=0.5,observed=y_obs)
File "/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py", line 38, in __new__
dist = cls.dist(*args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py", line 49, in dist
dist.__init__(*args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/pymc3/distributions/continuous.py", line 386, in __init__
self.mean = self.median = self.mode = self.mu = mu = tt.as_tensor_variable(mu)
File "/anaconda3/lib/python3.6/site-packages/theano/tensor/basic.py", line 200, in as_tensor_variable
raise AsTensorError("Cannot convert %s to TensorType" % str_x, type(x))
AsTensorError: ('Cannot convert <function mu at 0x1c2ab42ea0> to TensorType', <class 'function'>)
Is there any alternate way to define this function? I also tried using tf.py_func(), but this too doesn’t seem to work. Thanks in advance.