0

I am new to pymc3 and was trying to write a code to do a simple Bayesian inference with MCMC. But the pm. sample just keep giving me the error:

BrokenPipeError: [Errno 32] Broken pipe

count_data = np.loadtxt('txtdata.csv')
n_count_data = len(count_data)

alpha = 1/count_data.mean()

with pm.Model() as model:

    lamda_1 = pm.Exponential("lamda_1", alpha)
    lamda_2 = pm.Exponential("lamda_2", alpha)

    tau = pm.DiscreteUniform("tau",lower = 0, upper = n_count_data)

    print ("Random Output : ", tau.random(), tau.random(), tau.random())

    def lamda_(tau = tau, lamda_1 = lamda_1, lamda_2 = lamda_2):
        init_zero = tt.as_tensor_variable(np.zeros(n_count_data))
        out = pm.Deterministic("out", init_zero)
        out = tt.set_subtensor(out[:tau], lamda_1)
        out = tt.set_subtensor(out[tau:], lamda_1)
        return out

    lamda_val = lamda_(tau, lamda_1, lamda_2)

    observation = pm.Poisson("obs", lamda_val, observed = count_data)

    model = pm.Model([observation, lamda_1, lamda_2, tau])

    trace = pm.sample(40000)

Can anyone help to take a look at what is causing the issue? Thank you.

merv
  • 67,214
  • 13
  • 180
  • 245
  • What are you trying to accomplish with `model = pm.Model([observation, lamda_1, lamda_2, tau])`? The `with` context already defines `model` and attaches all the variables in context. – merv Aug 05 '19 at 18:17
  • @merv Thanks. I now do realize `model = pm.Model([observation, lamda_1, lamda_2, tau])` is unnecessary. The reason I had this code was that the code was originally from pymc and I was trying to convert it into pymc3. However, even after my removing the line you mentioned, I still got the same error. Any suggestions? – kungfu penguin Aug 06 '19 at 03:32
  • Okay. Without an example dataset, I can't directly troubleshoot your code - just point out things that seem odd to me as a PyMC3 user. I've never encountered the error. The `print` statement also doesn't make much sense... most of what happens in a PyMC3 context is "wiring" together of the Theano computation graph in the abstract; nothing actually has values until sampling is done, so those objects usually don't have any tangible values attached until `pm.sample` is called. But that is, again, just guesswork on my part. – merv Aug 08 '19 at 05:33

0 Answers0