I’m trying to rewrite student cheating example
in the book “Bayesian methods for hackers” under pyMC v5.0.1.
import pymc as pm
import arviz as az
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def cheat():
print(f"Running on PyMC v{pm.__version__}")
model = pm.Model()
with model:
N = 10
p = pm.Uniform("cheat_rate", lower=0.0, upper=1.0, initval=0.1)
cheat_truth = pm.Bernoulli("cheat_truth", p=p, size=N)
flip1 = pm.Bernoulli("flip1", p=0.5, size=N)
flip2 = pm.Bernoulli("flip2", p=0.5, size=N)
yes_rate = pm.Deterministic("yes_rate", (flip1 * cheat_truth + (1 - flip1) * flip2).sum() / N)
yes_count_observed = 35
yes_count = pm.Binomial("yes_count", n=N, p=yes_rate, observed=yes_count_observed)
print('sample of yes_count:', pm.draw(yes_count))
pm.model_to_graphviz(model=model)
with model:
idata = pm.sample(draws=1000, discard_tuned_samples=False)
az.plot_trace(idata, combined=True)
print(az.summary(idata, round_to=2))
However, it always blames below even I give the initval
as starting point. Another problem is that the model graph does not show in JupyterLab even graph.save('a.png')
gives empty picture. Could you help me to solve those problems? Thank you in advance.
SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'cheat_rate_interval__': array(-2.19722458), 'cheat_truth': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 'flip1': array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), 'flip2': array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])}
Initial evaluation results:
{'cheat_rate': -2.41, 'cheat_truth': -1.05, 'flip1': -6.93, 'flip2': -6.93, 'yes_count': -inf}