I’m using pymc3 .I use normal likelihood, my parameters are mu1 sigma1 and a. When I’m using pm.Normal as my likelihood,I need to make mu=Ft(mu1,sigma1,a).The function of Ft is to convolve array ft1 and array nor_resp, I defined it by myself, like this:
def Ft(A,sigma2,mu2,a):
t_min=0
t_max=(t4_s.shape[0]-nor_resp.shape[0]+1)*(t4_s[1]-t4_s[0])
num=t4_s.shape[0]-nor_resp.shape[0]+1
t=np.linspace(t_min,t_max,num)
tau=1/sigma2**2
ft11=A*np.sqrt(tau/(2*np.pi))*np.exp(-tau/2*(t+a-mu2)**2)
ft1=ft11.numpy()
signal.convolve(ft1,nor_resp, mode='full',method='auto')
return ft
#%%
with pm.Model() as final_model:
amp = pm.Uniform('amp',lower=-1.0,upper=0)
mu1 = pm.Uniform('mu1', lower=-50,upper=50)
sigma1 = pm.Uniform('sigma1',lower=0,upper=50)
a1=pm.Uniform('a1',lower=-10,upper=10)
y_observed=pm.Normal(
"y_observed",
mu= Ft(amp,sigma1,mu1,a1),
sigma=noise_sig,
observed=v4_s,
)
output = pm.Deterministic('output',Ft(amp,sigma1,mu1,a1))
prior = pm.sample_prior_predictive()
posterior_f = pm.sample(draws = Samples, target_accept = 0.9,chains=4,cores=1)
posterior_f = pm.sample_posterior_predictive(posterior_f)
az.plot_trace(posterior_f, var_names = ['amp','mu1','sigma1','a1'])
only_background=az.summary(posterior_f, var_names = ['amp','mu1','sigma1','a1'])
But I got an error, it seems to come from the convolution in Ft:
signal.convolve(ft1,nor_resp, mode='full',method='auto')
When using convolve,I need to gave two arrays to it, but when I call Ft,it seemsI passing a parameter of type TensorVariable to it.This might cause the problem.
I don’t know what to do, any advise is helpful,Thanks.