Skip to content

Shape error in random method for HalfNormal #3147

Closed
@junpenglao

Description

@junpenglao
with pm.Model() as m:
    a = pm.HalfNormal('a', np.ones((3, 1)), shape=(3, 10))

a.random(point=m.test_point)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-35-a1da77da6c66> in <module>()
----> 1 a.random(point=m.test_point)

~/Documents/pymc3/pymc3/model.py in __call__(self, *args, **kwargs)
     40 
     41     def __call__(self, *args, **kwargs):
---> 42         return getattr(self.obj, self.method_name)(*args, **kwargs)
     43 
     44 

~/Documents/pymc3/pymc3/distributions/continuous.py in random(self, point, size)
    749         return generate_samples(stats.halfnorm.rvs, loc=0., scale=sd,
    750                                 dist_shape=self.shape,
--> 751                                 size=size)
    752 
    753     def logp(self, value):

~/Documents/pymc3/pymc3/distributions/distribution.py in generate_samples(generator, *args, **kwargs)
    522             dist_shape: {dist_shape}
    523             broadcast_shape: {broadcast_shape}
--> 524         '''.format(size=size, dist_shape=dist_shape, broadcast_shape=broadcast_shape))
    525 
    526     # reshape samples here

TypeError: Attempted to generate values with incompatible shapes:
            size: 1
            dist_shape: (3, 10)
            broadcast_shape: (3, 1)

I have a vague feeling this is something to do with broadcasting sigma parameter in Normal/HalfNormal, I think I have seen it before...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions