Skip to content

Manuscript Error: Get NotImplementedError: Sorry, pickling not yet supported. when trying to run Listing 5.5 #160

Open
@paw-lu

Description

@paw-lu

Description

When trying to run Listing 5.5:

with pm.Model() as splines:
    τ = pm.HalfCauchy("τ", 1) 
    β = pm.Normal("β", mu=0, sd=τ, shape=B.shape[1])
    μ = pm.Deterministic("μ", pm.math.dot(B, β))
    σ = pm.HalfNormal("σ", 1)
    c = pm.Normal("c", μ, σ, observed=data["count_normalized"].values)
    idata_s = pm.sample(1000, return_inferencedata=True)

I get

NotImplementedError: Sorry, pickling not yet supported. See https://github.com/pydata/patsy/issues/26 if you want to help.

As seen by the traceback, this seems to be due to using Patsy's design matrix in a model (variable B in the snippet above). You can reduce the above example to just:

with pm.Model() as model:
    β = pm.Normal("β", mu=0, sd=3, shape=b.shape[1])
    μ = pm.Deterministic("μ", var=pm.math.dot(B, β))
    idata_s = pm.sample(1000, return_inferencedata=True)

And still get the same exception thrown.

Reference

https://bayesiancomputationbook.com/markdown/chp_05.html#id18

Possible solution

We can just convert the DesignMatrix into an ndarray to avoid the patsy issues.

-     μ = pm.Deterministic("μ", var=pm.math.dot(B, β))
+     μ = pm.Deterministic("μ", var=pm.math.dot(np.asarray(B), β)) 

As always, happy to provide PR here if it helps!

Author Section

Do not close until

  • Added to Errata
  • Fixed in Open Access
  • Fixed in latex source

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions