Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
Probabilistic-Programming-and-Bayesian-Methods-for-Hackers copied to clipboard
3 Switchpoints for Text Example in Ch1
Hi,
I see there is a PyMC example using the .deterministic annotation. Is there an easy way to do this for PyMC3?
I tried this but it's incorrect.
lambda1 = pm.Exponential("lambda_1", alpha)
lambda2 = pm.Exponential("lambda_2", alpha)
lambda3 = pm.Exponential("lambda_3", alpha)
tau1 = pm.DiscreteUniform("tau1", lower=0, upper=69)
tau2 = pm.DiscreteUniform("tau2", lower=tau1, upper=70)
idx1 = np.arange(n_count_data)
lambda_s1 = pm.math.switch(tau1 >= idx1, lambda1, lambda2)
idx2 = np.arange(n_count_data)
lambda_s2 = pm.math.switch(tau2 >= idx2, lambda2, lambda3)
obs1 = pm.Poisson("obs1", lambda_s1, observed=count_data)
obs2 = pm.Poisson("obs2", lambda_s2, observed=count_data)
Not sure if this is what you are looking for. I did it this way:
with pm.Model() as model:
alpha = 1.0/count_data.mean() # Recall count_data is the
# variable that holds our txt counts
lambda_1 = pm.Exponential("lambda_1", alpha)
lambda_2 = pm.Exponential("lambda_2", alpha)
lambda_3 = pm.Exponential("lambda_3", alpha)
tau_1 = pm.DiscreteUniform("tau_1", lower=0, upper=n_count_data)
tau_2 = pm.DiscreteUniform("tau_2", lower=tau_1, upper=n_count_data)
and
with model:
idx = np.arange(n_count_data) # Index
lambda_ = pm.math.switch(tau_2 >= idx, pm.math.switch(tau_1 >= idx, lambda_1, lambda_2), lambda_3)
Which i don't really find very neat. But it seems to work.

Hi. I'm study bayseian theory... Can i see the plot code?
Hi @friedhelmvictor can you please share the code you used to plot the text message graph above? It looks pretty OK to me and it is similar to a problem I am trying to solve. Thanks, in advance. Woodquest
How to plot the result???
Yes please. How to plot the result, have you any idea? Thanks Victor