beanmachine.ppl.distributions.unit module

class beanmachine.ppl.distributions.unit.Unit(log_factor, validate_args=None)

Bases: torch.distributions.distribution.Distribution

Trivial nonnormalized distribution representing the unit type.

The unit type has a single value with no data, i.e. value.numel() == 0.

This is used for pyro.factor() statements.

arg_constraints = {'log_factor': Real()}
expand(batch_shape, _instance=None)

Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to batch_shape. This method calls expand on the distribution’s parameters. As such, this does not allocate new memory for the expanded distribution instance. Additionally, this does not repeat any args checking or parameter broadcasting in, when an instance is first created.

  • batch_shape (torch.Size) – the desired expanded size.

  • _instance – new instance provided by subclasses that need to override .expand.


New distribution instance with batch dimensions expanded to batch_size.


Returns the log of the probability density/mass function evaluated at value.


value (Tensor) –


Generates a sample_shape shaped sample or sample_shape shaped batch of samples if the distribution parameters are batched.

support = Real()
beanmachine.ppl.distributions.unit.broadcast_shape(*shapes, **kwargs)

Similar to np.broadcast() but for shapes. Equivalent to np.broadcast(*map(np.empty, shapes)).shape. :param tuple shapes: shapes of tensors. :param bool strict: whether to use extend-but-not-resize broadcasting. :returns: broadcasted shape :rtype: tuple :raises: ValueError