I am working with with some dataset and thought of using Laplace as likelihood distribution. So, I designed a model that takes the mu parameter as piror using normal distribution and b parameter as prior using exponential distribution. When I ran the code I get error with unexpected keyword argument ‘mu’. Why is that? I checked the documentation and the parameters are mu and b.
Can you post the relevant code snippet or error traceback?
I checked the source code of Laplace
and it has a mu parameter as described in the docstring.
Here is the code:
def S2_0_Bayesian_Interface(data):
########################################################################################################################
with pm.Model() as model_0:
# Prior Distributions for unknown model parameters:
b_0 = pm.HalfNormal('b_0', sd=5)
mu_0 = pm.Normal('mu_0', mu=0, sd=5)
# Observed data is from a Likelihood distributions (Likelihood (sampling distribution) of observations):
observed_data_0 = Laplace('observed_data_0', mu=mu_0, b=b_0, observed=data)
# Printing the result of log_likelihood:
# print('log_likelihood result:', model_0)
# draw 5000 posterior samples
trace_0 = pm.sample(draws=1000, tune=1000, chains=3, cores=1, progressbar=True)
# Obtaining Posterior Predictive Sampling:
post_pred_0 = pm.sample_posterior_predictive(trace_0, samples=1000)
print(post_pred_0['observed_data_0'].shape)
print('\nSummary: ')
print(pm.stats.summary(data=trace_0))
print(pm.stats.summary(data=post_pred_0))
########################################################################################################################
return trace_0, post_pred_0
but when I ran the code, it says that it does not have observed parameter
I can’t reproduce any problem from your code snippet. This runs completely fine for me (pymc3==3.11.4
).
import pymc3 as pm
import numpy as np
data = np.random.normal(size=3)
with pm.Model() as model_0:
# Prior Distributions for unknown model parameters:
b_0 = pm.HalfNormal('b_0', sd=5)
mu_0 = pm.Normal('mu_0', mu=0, sd=5)
# Observed data is from a Likelihood distributions (Likelihood (sampling distribution) of observations):
observed_data_0 = pm.Laplace('observed_data_0', mu=mu_0, b=b_0, observed=data)
# Printing the result of log_likelihood:
# print('log_likelihood result:', model_0)
# draw 5000 posterior samples
trace_0 = pm.sample(draws=1000, tune=1000, chains=3, cores=1, progressbar=True)
# Obtaining Posterior Predictive Sampling:
post_pred_0 = pm.sample_posterior_predictive(trace_0, samples=1000)
print(post_pred_0['observed_data_0'].shape)
print('\nSummary: ')
print(pm.stats.summary(data=trace_0))
print(pm.stats.summary(data=post_pred_0))
well, the package version I’m using is 3.11.2 and when I replaced my version of code to include your way, I keep on getting following errors:
TypeError: Laplace() got an unexpected keyword argument 'mu'
If I removed mu=
and b=
and kept observed=
then I get
TypeError: Laplace() got an unexpected keyword argument 'observed'
Then try to update to latest release.
On Github you can search the tickets for Laplace. Maybe this was a bug that got fixed?
An check your import - you’re writing Laplace
not pm.Laplace
. From the code you posted we can’t rule out that this isn’t even the PyMC Laplace class.
thank you for the help. I managed to get it to work. it turns out I had to just update the package.