beanmachine.ppl.world.utils module
- class beanmachine.ppl.world.utils.BetaDimensionTransform(cache_size=0)
Bases:
torch.distributions.transforms.Transform
Volume preserving transformation to the Beta distribution support.
- bijective = True
- codomain: torch.distributions.constraints.Constraint = IndependentConstraint(Real(), 1)
- domain: torch.distributions.constraints.Constraint = Real()
- forward_shape(shape)
Infers the shape of the forward computation, given the input shape. Defaults to preserving shape.
- inverse_shape(shape)
Infers the shapes of the inverse computation, given the output shape. Defaults to preserving shape.
- log_abs_det_jacobian(x, y)
Computes the log det jacobian log |dy/dx| given input and output.
- beanmachine.ppl.world.utils.get_default_transforms(distribution: torch.distributions.distribution.Distribution) torch.distributions.transforms.Transform
Get transforms of a distribution to transform it from constrained space into unconstrained space.
- Parameters
distribution – the distribution to check
- Returns
a Transform that need to be applied to the distribution to transform it from constrained space into unconstrained space
- beanmachine.ppl.world.utils.initialize_value(distribution: torch.distributions.distribution.Distribution, initialize_from_prior: bool = False)
Initialized the Variable value
- Parameters
initialize_from_prior – if true, returns sample from prior
- Returns
the value to the set the Variable value to
- beanmachine.ppl.world.utils.is_constraint_eq(constraint: Union[torch.distributions.constraints.Constraint, Type], check_constraints: Union[torch.distributions.constraints.Constraint, Type]) bool
- beanmachine.ppl.world.utils.is_constraint_eq(constraint: Union[torch.distributions.constraints.Constraint, Type], check_constraints: Iterable[Union[torch.distributions.constraints.Constraint, Type]]) Iterable[bool]
This provides an equality check that works for different constraints specified in
torch.distributions.constraints
. If constraint is constraints.Independent, then the base_constraint is checked. If check_constraints is a single Constraint type or instance this returns a True if the given constraint matches check_constraints. Otherwise, if check_constraints is an iterable, this returns a bool list that represents an element-wise check.- Parameters
constraint – A constraint class or instance.
check_constraints – A constraint class or instance or an iterable containing constraint classes or instances to check against.
- Returns
bool (or a list of bool) values indicating if the given constraint equals the constraint in check_constraints.