scenic.core.distributions

Objects representing distributions that can be sampled from.

Summary of Module Members

Functions

dependencies

Dependencies which must be sampled before this value.

distributionFunction

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

distributionMethod

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

makeOperatorHandler

monotonicDistributionFunction

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

needsSampling

Whether this value requires sampling.

supportInterval

Lower and upper bounds on this value, if known.

toDistribution

Wrap Python data types with Distributions, if necessary.

underlyingFunction

Original function underlying a distribution wrapper.

Classes

AttributeDistribution

Distribution resulting from accessing an attribute of a distribution

CustomDistribution

Distribution with a custom sampler given by an arbitrary function

DefaultIdentityDict

Dictionary which is the identity map by default.

DiscreteRange

Distribution over a range of integers.

Distribution

Abstract class for distributions.

FunctionDistribution

Distribution resulting from passing distributions to a function

MethodDistribution

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

MultiplexerDistribution

Distribution selecting among values based on another distribution.

Normal

Normal distribution

OperatorDistribution

Distribution resulting from applying an operator to one or more distributions

Options

Distribution over a finite list of options.

Range

Uniform distribution over a range

Samplable

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

TruncatedNormal

Truncated normal distribution.

TupleDistribution

Distributions over tuples (or namedtuples, or lists).

Exceptions

RejectionException

Exception used to signal that the sample currently being generated must be rejected.

Member Details

dependencies(thing)[source]

Dependencies which must be sampled before this value.

needsSampling(thing)[source]

Whether this value requires sampling.

supportInterval(thing)[source]

Lower and upper bounds on this value, if known.

underlyingFunction(thing)[source]

Original function underlying a distribution wrapper.

exception RejectionException[source]

Bases: Exception

Exception used to signal that the sample currently being generated must be rejected.

class DefaultIdentityDict[source]

Bases: dict

Dictionary which is the identity map by default.

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 ‘self._conditioned’ 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.

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.

sample(subsamples=None)[source]

Sample this value, optionally given some values already sampled.

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.

conditionTo(value)[source]

Condition this value to another value with the same conditional distribution.

evaluateIn(context)[source]

See LazilyEvaluable.evaluateIn.

dependencyTree()[source]

Debugging method to print the dependency tree of a Samplable.

class Distribution(*dependencies, valueType=None)[source]

Bases: scenic.core.distributions.Samplable

Abstract class for distributions.

defaultValueType

alias of builtins.float

clone()[source]

Construct an independent copy of this Distribution.

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().

supportInterval()[source]

Compute lower and upper bounds on the value of this Distribution.

class CustomDistribution(sampler, *dependencies, name='CustomDistribution', evaluator=None)[source]

Bases: scenic.core.distributions.Distribution

Distribution with a custom sampler given by an arbitrary function

class TupleDistribution(*coordinates, builder=<class 'tuple'>)[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(func, args, kwargs, support=None)[source]

Bases: scenic.core.distributions.Distribution

Distribution resulting from passing distributions to a function

distributionFunction(method, support=None)[source]

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

monotonicDistributionFunction(method)[source]

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

class MethodDistribution(method, obj, 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(attribute, obj)[source]

Bases: scenic.core.distributions.Distribution

Distribution resulting from accessing an attribute of a distribution

class OperatorDistribution(operator, obj, operands)[source]

Bases: scenic.core.distributions.Distribution

Distribution resulting from applying an operator to one or more distributions

class MultiplexerDistribution(index, options)[source]

Bases: scenic.core.distributions.Distribution

Distribution selecting among values based on another distribution.

class Range(low, high)[source]

Bases: scenic.core.distributions.Distribution

Uniform distribution over a range

class Normal(mean, stddev)[source]

Bases: scenic.core.distributions.Distribution

Normal distribution

class TruncatedNormal(mean, stddev, low, high)[source]

Bases: scenic.core.distributions.Normal

Truncated normal distribution.

class DiscreteRange(low, high, weights=None)[source]

Bases: scenic.core.distributions.Distribution

Distribution over a range of integers.

class Options(opts)[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.