clipppy.stochastic.sampler

Module Contents

class clipppy.stochastic.sampler.AbstractSampler

The base class for “samplers”: objects that dynamically (or not) generate values in a Stochastic context.

abstract __call__(self)

An AbstractSampler is called when Stochastic encounters one as a “specification”, and it is this method that has to be overridden in subclasses to supply the desired value.

class clipppy.stochastic.sampler.ConcreteSampler

A base class for “true” samplers, i.e. that provide a value from Pyro.

Namely, Param and Sampler.

init :torch.Tensor
support :torch.distributions.constraints.Constraint
class clipppy.stochastic.sampler.Context(context: ContextManager, func_or_val: _ps_func_t, call: _ps_call_t = PseudoSampler.call)

The base class for “samplers”: objects that dynamically (or not) generate values in a Stochastic context.

__call__(self, *args, **kwargs)

An AbstractSampler is called when Stochastic encounters one as a “specification”, and it is this method that has to be overridden in subclasses to supply the desired value.

class clipppy.stochastic.sampler.Deterministic

A PseudoSampler that records the value via pyro.deterministic.

_func
event_dim :int

The event_dim parameter to pyro.deterministic.

__call__(self)

An AbstractSampler is called when Stochastic encounters one as a “specification”, and it is this method that has to be overridden in subclasses to supply the desired value.

class clipppy.stochastic.sampler.Effect(effect: Callable[[clipppy.utils._Tin], clipppy.utils._Tout], func_or_val: _ps_func_t, call: _ps_call_t = PseudoSampler.call)

The base class for “samplers”: objects that dynamically (or not) generate values in a Stochastic context.

__call__(self) clipppy.utils._Tout

An AbstractSampler is called when Stochastic encounters one as a “specification”, and it is this method that has to be overridden in subclasses to supply the desired value.

class clipppy.stochastic.sampler.Factor

A PseudoSampler that records the value as a pyro.factor.

_func
class clipppy.stochastic.sampler.NamedPseudoSampler

A PseudoSampler with a name.

Processes the value returned by PseudoSampler.__call__ through a function _func that is given the name as first argument and the value as second.

_func :ClassVar[Callable[[str, _ps_return_t], _ps_return_t]]

A function to process the value before returning.

It is called as self._func(self.name, val, **kwargs). Subclasses can override this to e.g. pyro.deterministic and pyro.factor.

__call__(self, **kwargs)

An AbstractSampler is called when Stochastic encounters one as a “specification”, and it is this method that has to be overridden in subclasses to supply the desired value.

class clipppy.stochastic.sampler.NamedSampler

A base class for samplers with a name.

These include Sampler, Param, Deterministic, and Factor that correspond to the respective pyro.primitives.

_subclasses :ClassVar[set[Type[NamedSampler]]]
name :str

The name of the sampler, used e.g. in pyro.sample and pyro.param.

classmethod __init_subclass__(cls, **kwargs)
set_name(self: T, name: Optional[str]) T

Set self.name and return self.

Parameters

name (str or None) – Set self.name to this, but only if it (the passed in argument) is not None.

Returns

self

Return type

NamedSampler

class clipppy.stochastic.sampler.Param

Represents a pyro.param statement.

event_dim :int

The event_dim argument to pyro.param.

__call__(self)

Call pyro.param with suitable arguments.

Passes in
Returns

The result of the param statement.

Return type

torch.Tensor

class clipppy.stochastic.sampler.PseudoSampler

The base class for “samplers”: objects that dynamically (or not) generate values in a Stochastic context.

call :_ps_call_t
func_or_val :_ps_func_t
__call__(self) _ps_return_t

An AbstractSampler is called when Stochastic encounters one as a “specification”, and it is this method that has to be overridden in subclasses to supply the desired value.

__repr__(self)

Return repr(self).

class clipppy.stochastic.sampler.Sampler(d: _Sampler_dT, name: str = _Sampler.name, init: torch.Tensor = _Sampler.init, support: torch.distributions.constraints.Constraint = _Sampler.support, expand_by: Union[torch.Size, Iterable[int]] = _Sampler.expand_by, to_event: int = _Sampler.to_event, indep: Union[torch.Size, Iterable[int]] = _Sampler.indep, mask: torch.Tensor = _Sampler.mask, **kwargs)

Represents a pyro.sample statement.

d :_Sampler_dT

A( callable that returns a)* distribution to be passed to pyro.sample.

infer :Mapping[str, Any]
__call__(self)

An AbstractSampler is called when Stochastic encounters one as a “specification”, and it is this method that has to be overridden in subclasses to supply the desired value.

property distribution(self) pyro.distributions.torch_distribution.TorchDistributionMixin

The distribution from which to sample.

This is the result of repeatedly calling self.Sampler.d (zero or more times) until a distribution pops out.

property infer_dict(self) dict[str, Any]

A dict to be used as a sample site’s config attribute.

It is constructed from self.infer by filtering out Sentinel.skip values.

class clipppy.stochastic.sampler.UnbindEffect(func_or_val: _ps_func_t, call: _ps_call_t = PseudoSampler.call, dim=- 1)

The base class for “samplers”: objects that dynamically (or not) generate values in a Stochastic context.