While I am progressing in self-educating me about PyMC, I have been using Osvaldo Martin´s Bayesian Analysis with Python -2nd edition book together with Cameron Davidson-Pilon´s book: Bayesian Methods for Hackers which together with some on-line tutorials.
Some limitations I am facing, is most of the code in the books above were written either in PyMC 3 or even in some PyMC2 (for Davidson-Pilon´s book) versions. Anyhow, I am doing my best to translate the codes to PyMC4 after forking the github.
I need a little help with this one, which looks like was writen for PyMC2:
I updated the initialization syntax of the model to a context manager:
with pm.Model() as texting_model: #Priors: lambda_1 = pm.Exponential("lambda_1", alpha) lambda_2 = pm.Exponential("lambda_2", alpha) tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data)
but the likelihood is defined through a step function named lambda_ according to:
@pm.deterministic def lambda_(tau=tau, lambda_1=lambda_1, lambda_2=lambda_2): out = np.zeros(n_count_data) out[:tau] = lambda_1 # lambda before tau is lambda1 out[tau:] = lambda_2 # lambda after (and including) tau is lambda2 return out
When I pass the data to the model through a likelihood, which calls the step function lambda_
with texting_model: observation = pm.Poisson("obs", mu=lambda_, value=count_data, observed=True)
PyMC4 return an error as mu cannot be defined by a function:
TypeError: float() argument must be a string or a number, not ‘function’
Help is appreciated here.