scenic.core.distributions¶
Objects representing distributions that can be sampled from.
Summary of Module Members¶
Functions
Uniform distribution over a finite list of options. 

Whether the function supports iterable unpacking of distributions. 

Dependencies which must be sampled before this value. 

Decorator for wrapping a function so that it can take distributions as arguments. 

Decorator for wrapping a method so that it can take distributions as arguments. 



Like distributionFunction, but additionally specifies that the function is monotonic. 

Whether this value requires sampling. 

Lower and upper bounds on this value, if known. 

Wrap Python data types with Distributions, if necessary. 

Original function underlying a distribution wrapper. 

Decorator indicating the function supports iterable unpacking of distributions. 
Classes
Distribution resulting from accessing an attribute of a distribution 

A samplable which always evaluates to a constant value. 

Distribution with a custom sampler given by an arbitrary function 

Distribution over a range of integers. 

Abstract class for distributions. 

Distribution resulting from passing distributions to a function 

Distribution resulting from passing distributions to a method of a fixed object 

Distribution selecting among values based on another distribution. 

Normal distribution 

Distribution resulting from applying an operator to one or more distributions 

Distribution over a finite list of options. 

Uniform distribution over a range 

Abstract class for values which can be sampled, possibly depending on other values. 

A placeholder for the iterable unpacking operator * applied to a distribution. 

Truncated normal distribution. 

Distributions over tuples (or namedtuples, or lists). 

Uniform distribution over a variable number of options. 
Exceptions
Exception used to signal that the sample currently being generated must be rejected. 
Member Details¶
 canUnpackDistributions(func)[source]¶
Whether the function supports iterable unpacking of distributions.
 unpacksDistributions(func)[source]¶
Decorator indicating the function supports iterable unpacking of distributions.
 exception RejectionException[source]¶
Bases:
Exception
Exception used to signal that the sample currently being generated must be rejected.
 class Samplable(dependencies)[source]¶
Bases:
scenic.core.lazy_eval.LazilyEvaluable
Abstract class for values which can be sampled, possibly depending on other values.
Samplables may specify a proxy object which must have the same distribution as the original after conditioning on the scenario’s requirements. This allows transparent conditioning without modifying Samplable fields of immutable objects.
 Parameters
dependencies – sequence of values that this value may depend on (formally, objects for which sampled values must be provided to
sampleGiven
). It is legal to include values which are not instances ofSamplable
, e.g. integers. Attributes
_conditioned – proxy object as described above; set using
conditionTo
._dependencies – tuple of other samplables which must be sampled before this one; set by the initializer and subsequently immutable.
 static sampleAll(quantities)[source]¶
Sample all the given Samplables, which may have dependencies in common.
Reproducibility note: the order in which the quantities are given can affect the order in which calls to random are made, affecting the final result.
 sampleGiven(value)[source]¶
Sample this value, given values for all its dependencies.
The default implementation simply returns a dictionary of dependency values. Subclasses must override this method to specify how actual sampling is done.
 Parameters
value (DefaultIdentityDict) – dictionary mapping objects to their sampled values. Guaranteed to provide values for all objects given in the set of dependencies when this
Samplable
was created.
 conditionTo(value)[source]¶
Condition this value to another value with the same conditional distribution.
 class ConstantSamplable(value)[source]¶
Bases:
scenic.core.distributions.Samplable
A samplable which always evaluates to a constant value.
Only for internal use.
 class Distribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Samplable
Abstract class for distributions.
Note
When called during dynamic simulations (vs. scenario compilation), constructors for distributions return actual sampled values, not
Distribution
objects. Parameters
 Attributes
_valueType – type of the values sampled from this distribution, or
object
if the type is not known.
 property isPrimitive¶
Whether this is a primitive Distribution.
 bucket(buckets=None)[source]¶
Construct a bucketed approximation of this Distribution.
This function factors a given Distribution into a discrete distribution over buckets together with a distribution for each bucket. The argument buckets controls how many buckets the domain of the original Distribution is split into. Since the result is an independent distribution, the original must support
clone
.
 class CustomDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Distribution with a custom sampler given by an arbitrary function
 class TupleDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
,collections.abc.Sequence
Distributions over tuples (or namedtuples, or lists).
 toDistribution(val)[source]¶
Wrap Python data types with Distributions, if necessary.
For example, tuples containing Samplables need to be converted into TupleDistributions in order to keep track of dependencies properly.
 class FunctionDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Distribution resulting from passing distributions to a function
 distributionFunction(wrapped=None, *, support=None, valueType=None)[source]¶
Decorator for wrapping a function so that it can take distributions as arguments.
 monotonicDistributionFunction(method, valueType=None)[source]¶
Like distributionFunction, but additionally specifies that the function is monotonic.
 class StarredDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
A placeholder for the iterable unpacking operator * applied to a distribution.
 class MethodDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Distribution resulting from passing distributions to a method of a fixed object
 distributionMethod(method)[source]¶
Decorator for wrapping a method so that it can take distributions as arguments.
 class AttributeDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Distribution resulting from accessing an attribute of a distribution
 class OperatorDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Distribution resulting from applying an operator to one or more distributions
 class MultiplexerDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Distribution selecting among values based on another distribution.
 class Range(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Uniform distribution over a range
 class Normal(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Normal distribution
 class TruncatedNormal(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Normal
Truncated normal distribution.
 class DiscreteRange(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Distribution over a range of integers.
 class Options(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.MultiplexerDistribution
Distribution over a finite list of options.
Specified by a dict giving probabilities; otherwise uniform over a given iterable.
 Uniform(*opts)[source]¶
Uniform distribution over a finite list of options.
Implemented as an instance of
Options
when the set of options is known statically, and an instance ofUniformDistribution
otherwise.
 class UniformDistribution(*args, **kwargs)[source]¶
Bases:
scenic.core.distributions.Distribution
Uniform distribution over a variable number of options.
See
Options
for the more common uniform distribution over a fixed number of options. This class is for the special case where iterable unpacking is applied to a distribution, so that the number of options is unknown at compile time.