Implementation:Google deepmind Dm control Variation Math
| Knowledge Sources | |
|---|---|
| Domains | Reinforcement_Learning, Domain_Randomization |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Variation classes that apply mathematical operations (logarithm, maximum, minimum, norm) to the outputs of other variations, enabling mathematical post-processing within the Variation framework.
Description
The math module provides the MathOp abstract base class and four concrete subclasses that wrap standard NumPy mathematical functions as Variation objects. MathOp stores constructor arguments and keyword arguments, evaluates them recursively via variation_values.evaluate (allowing nested variations as parameters), and then passes the evaluated results to the _callable property implemented by each subclass.
The four concrete classes are: Log (wrapping np.log), Max (wrapping np.max), Min (wrapping np.min), and Norm (wrapping np.linalg.norm). Because MathOp accepts arbitrary positional and keyword arguments, these classes can be used with the full parameter sets of their underlying NumPy functions (e.g., specifying an axis argument for Max or Min).
This design allows users to compose complex randomization pipelines entirely within the Variation abstraction. For example, you can clamp a random value by applying Min and Max, normalize a random vector using Norm, or apply a log transform to a distribution sample.
Usage
Use these classes when you need to apply mathematical transformations to variation outputs as part of a domain randomization pipeline. Pass the variation to be transformed (or a constant) as the first argument to the MathOp subclass constructor.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/composer/variation/math.py
- Lines: 1-99
Signature
class MathOp(base.Variation):
def __init__(self, *args, **kwargs):
...
@property
@abc.abstractmethod
def _callable(self):
...
class Log(MathOp):
# _callable returns np.log
class Max(MathOp):
# _callable returns np.max
class Min(MathOp):
# _callable returns np.min
class Norm(MathOp):
# _callable returns np.linalg.norm
Import
from dm_control.composer.variation import math as variation_math
from dm_control.composer.variation.math import Log, Max, Min, Norm
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| *args | Variation or numeric | Yes | Positional arguments passed to the underlying NumPy function |
| **kwargs | Variation or numeric | No | Keyword arguments passed to the underlying NumPy function (e.g., axis)
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | scalar or numpy.ndarray |
Result of applying the math operation to the evaluated arguments |
Provided Operations
| Class | NumPy Function | Description |
|---|---|---|
Log |
np.log |
Natural logarithm of the variation output |
Max |
np.max |
Maximum value of the variation output |
Min |
np.min |
Minimum value of the variation output |
Norm |
np.linalg.norm |
Vector or matrix norm of the variation output |
Usage Examples
from dm_control.composer.variation import math as variation_math
from dm_control.composer.variation import distributions
import numpy as np
rng = np.random.RandomState(42)
# Compute the norm of a random 3D vector
random_vec = distributions.Uniform(low=-1.0, high=1.0)
vec_norm = variation_math.Norm(random_vec)
# Compute the log of a log-normal sample
log_sample = variation_math.Log(distributions.LogNormal(mean=1.0, sigma=0.5))
value = log_sample(random_state=rng)
# Find the max element of a random array
initial_array = np.array([1.0, 2.0, 3.0])
max_val = variation_math.Max(distributions.Uniform(low=0.0, high=10.0))
result = max_val(initial_value=initial_array, random_state=rng)