Implementation:Google deepmind Dm control Variation Distributions
| Knowledge Sources | |
|---|---|
| Domains | Reinforcement_Learning, Domain_Randomization |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Standard statistical distribution classes conforming to the Variation API, providing the primary source of stochasticity for domain randomization in dm_control Composer environments.
Description
The distributions module implements a hierarchy of statistical distribution classes built on the Variation abstract base class. The central abstraction is the Distribution class, which provides a common framework for parametrized distributions. Subclasses implement a _callable(random_state) method that returns the appropriate NumPy random sampling function. When called, Distribution.__call__ evaluates its constructor arguments (which may themselves be Variation objects), determines the sample shape from initial_value (unless single_sample=True), and invokes the sampling function.
The module provides ten concrete distribution classes: Uniform (continuous uniform), UniformInteger (discrete uniform), UniformChoice (uniform selection from a list), Normal (Gaussian), LogNormal, Exponential, Poisson, and Bernoulli (binary coin flip via binomial). Additionally, UniformPointOnSphere samples uniformly distributed points on the unit 3D sphere by normalizing Gaussian random vectors, and BiasedRandomWalk implements a discrete-time Ornstein-Uhlenbeck process that produces temporally correlated noise with configurable standard deviation and correlation timescale.
All distribution parameters can themselves be Variation objects, enabling hierarchical randomization where distribution parameters are sampled from other distributions. The single_sample flag controls whether the distribution draws one scalar sample or an array matching the shape of the initial value.
Usage
Use these distributions to randomize MJCF model attributes, physics parameters, positions, orientations, and other properties in Composer tasks. Bind them to element attributes via MJCFVariator or PhysicsVariator, or evaluate them directly via variation.evaluate.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/composer/variation/distributions.py
- Lines: 1-259
Signature
class Distribution(base.Variation, metaclass=abc.ABCMeta):
def __init__(self, *args, **kwargs):
...
@abc.abstractmethod
def _callable(self, random_state):
...
class Uniform(Distribution):
def __init__(self, low=0.0, high=1.0, single_sample=False):
...
class UniformInteger(Distribution):
def __init__(self, low, high=None, single_sample=False):
...
class UniformChoice(Distribution):
def __init__(self, choices, single_sample=False):
...
class UniformPointOnSphere(base.Variation):
def __init__(self, single_sample=False):
...
class Normal(Distribution):
def __init__(self, loc=0.0, scale=1.0, single_sample=False):
...
class LogNormal(Distribution):
def __init__(self, mean=0.0, sigma=1.0, single_sample=False):
...
class Exponential(Distribution):
def __init__(self, scale=1.0, single_sample=False):
...
class Poisson(Distribution):
def __init__(self, lam=1.0, single_sample=False):
...
class Bernoulli(Distribution):
def __init__(self, prob=0.5, single_sample=False):
...
class BiasedRandomWalk(base.Variation):
def __init__(self, stdev=0.1, timescale=10.):
...
Import
from dm_control.composer.variation import distributions
from dm_control.composer.variation.distributions import Uniform, Normal, BiasedRandomWalk
I/O Contract
Inputs (Distribution subclasses)
| Name | Type | Required | Description |
|---|---|---|---|
| Distribution-specific params | Variation or numeric | Yes | Parameters of the distribution (e.g., low, high for Uniform)
|
| single_sample | bool | No | If True, draw one scalar sample regardless of initial_value shape (default False)
|
Inputs (BiasedRandomWalk)
| Name | Type | Required | Description |
|---|---|---|---|
| stdev | float | No | Standard deviation of the output sequence (default 0.1); must be >= 0 |
| timescale | float | No | Number of timesteps for correlation decay (default 10.0); must be >= 0 |
Outputs
| Name | Type | Description |
|---|---|---|
| return | scalar or numpy.ndarray |
Sampled value(s); shape matches initial_value unless single_sample=True
|
Distribution Summary
| Class | NumPy Function | Parameters | Description |
|---|---|---|---|
Uniform |
random_state.uniform |
low, high | Continuous uniform distribution |
UniformInteger |
random_state.randint |
low, high | Discrete uniform distribution |
UniformChoice |
random_state.choice |
choices | Uniform selection from a list |
Normal |
random_state.normal |
loc, scale | Gaussian distribution |
LogNormal |
random_state.lognormal |
mean, sigma | Log-normal distribution |
Exponential |
random_state.exponential |
scale | Exponential distribution |
Poisson |
random_state.poisson |
lam | Poisson distribution |
Bernoulli |
random_state.binomial(1, ...) |
prob | Bernoulli (coin flip) distribution |
UniformPointOnSphere |
normalized Gaussians | (none) | Uniform unit vector on the 3D sphere |
BiasedRandomWalk |
Ornstein-Uhlenbeck process | stdev, timescale | Temporally correlated noise |
Usage Examples
from dm_control.composer.variation import distributions
import numpy as np
rng = np.random.RandomState(42)
# Sample from a uniform distribution
uniform = distributions.Uniform(low=-1.0, high=1.0)
value = uniform(initial_value=None, current_value=None, random_state=rng)
# Sample matching the shape of an initial value
initial = np.array([1.0, 2.0, 3.0])
values = uniform(initial_value=initial, current_value=None, random_state=rng)
# values has shape (3,)
# Sample a single scalar regardless of initial value shape
single = distributions.Uniform(low=0.0, high=1.0, single_sample=True)
scalar = single(initial_value=initial, current_value=None, random_state=rng)
# Sample a random point on the unit sphere
sphere = distributions.UniformPointOnSphere()
point = sphere(random_state=rng) # 3D unit vector
# Create a biased random walk for correlated noise
walk = distributions.BiasedRandomWalk(stdev=0.1, timescale=10.)
noise_1 = walk(random_state=rng)
noise_2 = walk(random_state=rng) # Correlated with noise_1
# Bernoulli distribution for binary randomization
coin = distributions.Bernoulli(prob=0.3)
flip = coin(random_state=rng) # 0 or 1