1
$\begingroup$

In pymc3 documentation, it specifies that the .dist() member for distribution allows the distribution to be used without a model for sampling and use of the logp functions e.g.

d_dist = pm.HalfCauchy.dist(beta=2.5, shape=3)

however, an example I copied, used .dist() functions for model elements, but when I remove the .dist() and use the model version of the distribution, it fails.

so:

data = [tuple(x) for x in self.pointdata[['x','y', 'z']].values]
print("Data {}".format(data))
with pm.Model() as model:
   mu1 = pm.Normal('mu_wall1' ,mu=0.0, sd=10.0, shape=3)
   sd_dist = pm.HalfCauchy.dist(beta=2.5, shape=3)
   chol_packed = pm.LKJCholeskyCov('chol_packed', n=3, eta=2, sd_dist=sd_dist )
   chol= pm.expand_packed_triangular(3, chol_packed)
   wall1 = pm.MvNormal('wall1', mu=mu1, chol=chol, observed=data)
   trace = pm.sample(5000, tune=1000)

will work, generating samples and providing a solution. but:

data = [tuple(x) for x in self.pointdata[['x','y', 'z']].values]
print("Data {}".format(data))
with pm.Model() as model:
   mu1 = pm.Normal('mu_wall1' ,mu=0.0, sd=10.0, shape=3)
   sd_dist = pm.HalfCauchy('sd1', beta=2.5, shape=3)
   chol_packed = pm.LKJCholeskyCov('chol_packed', n=3, eta=2, sd_dist=sd_dist )
   chol= pm.expand_packed_triangular(3, chol_packed)
   wall1 = pm.MvNormal('wall1', mu=mu1, chol=chol, observed=data)
   trace = pm.sample(5000, tune=1000)

will throw

  line 29, in _alignPointsToMajorAxes
    chol_packed = pm.LKJCholeskyCov('chol_packed', n=3, eta=2, sd_dist=sd_dist )
  File "build/bdist.linux-x86_64/egg/pymc3/distributions/distribution.py", line 42, in __new__
  File "build/bdist.linux-x86_64/egg/pymc3/model.py", line 816, in Var
  File "build/bdist.linux-x86_64/egg/pymc3/model.py", line 1492, in __init__
  File "build/bdist.linux-x86_64/egg/pymc3/distributions/transforms.py", line 95, in apply
  File "build/bdist.linux-x86_64/egg/pymc3/distributions/distribution.py", line 52, in dist
  File "build/bdist.linux-x86_64/egg/pymc3/distributions/transforms.py", line 125, in __init__
  File "build/bdist.linux-x86_64/egg/pymc3/model.py", line 1209, in __init__
  File "build/bdist.linux-x86_64/egg/pymc3/distributions/multivariate.py", line 1041, in logp
AttributeError: 'TransformedRV' object has no attribute 'logp'

I would like to understand why using dist() helps and why utilizing the model version of the distribution causes errors.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.