4.3. Distributions

4.3.1. Distribution Base Class

class rlgraph.components.distributions.distribution.Distribution(scope='distribution', **kwargs)[source]

Bases: rlgraph.components.component.Component

A distribution wrapper class that can incorporate a backend-specific distribution object that gets its parameters from an external source (e.g. a NN).

API:

get_distribution(parameters): The backend-specific distribution object. sample_stochastic(parameters): Returns a stochastic sample from the distribution. sample_deterministic(parameters): Returns the max-likelihood value (deterministic) from the distribution.

draw(parameters, max_likelihood): Draws a sample from the distribution (if max_likelihood is True,
this is will be a deterministic draw, otherwise a stochastic sample).

entropy(parameters): The entropy value of the distribution. log_prob(parameters): The log probabilities for given values.

kl_divergence(parameters, other_parameters): The Kullback-Leibler Divergence between a Distribution and
another one.
check_input_spaces(input_spaces, action_space=None)[source]

Should check on the nature of all in-Sockets Spaces of this Component. This method is called automatically by the Model when all these Spaces are know during the Model’s build time.

Args:
input_spaces (Dict[str,Space]): A dict with Space/shape information.
keys=in-Socket name (str); values=the associated Space
action_space (Optional[Space]): The action Space of the Agent/GraphBuilder. Can be used to construct and
connect more Components (which rely on this information). This eliminates the need to pass the action Space information into many Components’ constructors.
draw(parameters, max_likelihood=True)[source]
entropy(parameters)[source]
kl_divergence(*args, **kwargs)
log_prob(*args, **kwargs)
sample_deterministic(parameters)[source]
sample_stochastic(parameters)[source]

4.3.2. Normal Distribution

class rlgraph.components.distributions.normal.Normal(scope='normal', **kwargs)[source]

Bases: rlgraph.components.distributions.distribution.Distribution

A Gaussian Normal distribution object defined by a tuple: mean, variance, which is the same as “loc_and_scale”.

check_input_spaces(input_spaces, action_space=None)[source]

Should check on the nature of all in-Sockets Spaces of this Component. This method is called automatically by the Model when all these Spaces are know during the Model’s build time.

Args:
input_spaces (Dict[str,Space]): A dict with Space/shape information.
keys=in-Socket name (str); values=the associated Space
action_space (Optional[Space]): The action Space of the Agent/GraphBuilder. Can be used to construct and
connect more Components (which rely on this information). This eliminates the need to pass the action Space information into many Components’ constructors.

4.3.3. Bernoulli Distribution

class rlgraph.components.distributions.bernoulli.Bernoulli(scope='bernoulli', **kwargs)[source]

Bases: rlgraph.components.distributions.distribution.Distribution

A Bernoulli distribution object defined by a single value p, the probability for True (rather than False).

4.3.4. Categorical Distribution

class rlgraph.components.distributions.categorical.Categorical(scope='categorical', **kwargs)[source]

Bases: rlgraph.components.distributions.distribution.Distribution

A categorical distribution object defined by a n values {p0, p1, …} that add up to 1, the probabilities for picking one of the n categories.

4.3.5. Beta Distribution

class rlgraph.components.distributions.beta.Beta(scope='beta', **kwargs)[source]

Bases: rlgraph.components.distributions.distribution.Distribution

A Beta distribution is defined on the interval [0, 1] and parameterized by shape parameters alpha and beta (also called concentration parameters).

check_input_spaces(input_spaces, action_space=None)[source]

Should check on the nature of all in-Sockets Spaces of this Component. This method is called automatically by the Model when all these Spaces are know during the Model’s build time.

Args:
input_spaces (Dict[str,Space]): A dict with Space/shape information.
keys=in-Socket name (str); values=the associated Space
action_space (Optional[Space]): The action Space of the Agent/GraphBuilder. Can be used to construct and
connect more Components (which rely on this information). This eliminates the need to pass the action Space information into many Components’ constructors.