Mu arg in pm.Normal cannot be a vector?

When I try to define the first model, I get the following error:

TypeError: For compute_test_value, one input test value does not have the requested type.

The error when converting the test value to that variable type:
Wrong number of dimensions: expected 0, got 1 with shape (10,).

import pymc3 as pm
with pm.Model() as model:
    mu = pm.Normal(mu=0,sigma=1,name='mu',shape=10)
    sigma = pm.HalfCauchy(beta=5.,name='sigma')
    coeff = pm.Normal(mu=mu,sigma=sigma,name='coeff')

I can define this second model, however, just fine. Why?

import pymc3 as pm
with pm.Model() as model:
    mu = pm.Normal(mu=0,sigma=1,name='mu')
    sigma = pm.HalfCauchy(beta=5.,shape=10,name='sigma')
    coeff = pm.Normal(mu=mu,sigma=sigma,name='coeff')

coeff needs to have shape=10.

import pymc3 as pm
with pm.Model() as model:
    mu = pm.Normal('mu', mu=0, sigma=1, shape=10)
    sigma = pm.HalfCauchy('sigma', beta=5.)
    coeff = pm.Normal('coeff', mu=mu, sigma=sigma, shape=10)

@aseyboldt thanks! this works. I’m still curious why the shape is passed implicitly via the sigma arg but not via the mu arg. Any ideas?

Have you tried that:

with pm.Model() as model:
    mu = pm.Normal("mu", mu=0, sigma=1)
    sigma = pm.HalfCauchy("sigma", beta=5.0)
    coeff = pm.Normal("coeff", mu=mu, sigma=sigma, shape=10)

This should work

@AlexAndorra thanks, yea this works, but it pools the coeff parameters, which I don’t want.

You’re welcome!
If you’re talking about pooling from a statistical sense, it’s because you’re using hyper-priors. If you want unpooled estimates, just do:

coeff = pm.Normal("coeff", mu=0., sigma=5., shape=10)

@AlexAndorra thanks, this works much better!

1 Like