Module: meanRevertingNoise

Executive Summary

The MeanRevertingNoise module is an abstract MuJoCo dynamics-task base class that implements a scalar mean-reverting stochastic process (Ornstein-Uhlenbeck). It provides state registration, drift/diffusion setup, and parameter accessors. Derived classes define how the scalar stochastic state is mapped into output messages.

Module Description

The internal scalar state \(x\) follows

\[dx = -\frac{1}{\tau}x\,dt + \sqrt{\frac{2}{\tau}}\sigma_{st}\,dW\]

where:

  • \(\tau\) is the time constant

  • \(\sigma_{st}\) is the stationary standard deviation

  • \(dW\) is Wiener process increment

At each update, the base class computes:

\[\dot{x} = -\frac{1}{\tau}x\]

and configures one scalar diffusion source with amplitude

\[\sigma = \sqrt{\frac{2}{\tau}}\sigma_{st}\]

The base class then calls the virtual hook:

writeOutput(CurrentSimNanos, x)

which must be implemented by subclasses.

Message Interfaces

This base class does not define concrete input or output messages.

Subclasses are responsible for defining and publishing message interfaces in their writeOutput implementation.

Detailed Behavior

At each update step, the module performs the following operations:

  1. Ensures the scalar state was registered.

  2. Reads current state value \(x\).

  3. Sets deterministic derivative \(\dot{x} = -x/\tau\).

  4. Sets scalar diffusion magnitude \(\sqrt{2/\tau}\sigma_{st}\) for one noise source.

  5. Calls subclass writeOutput(CurrentSimNanos, x).

During state registration, the module:

  • registers a 1x1 state named meanRevertingState,

  • assigns one noise source,

  • initializes the state to zero.

Module Assumptions and Limitations

  • The class is abstract and cannot be used directly without subclassing.

  • setTimeConstant(t) requires \(t > 0\).

  • setStationaryStd(s) requires \(s \ge 0\).

  • Calling state getter/setter methods before state registration raises an error.

Verification and Testing

The OU process implementation is verified in src/simulation/mujocoDynamics/meanRevertingNoise/_UnitTest/test_meanRevertingNoise.py through a subclass usage path. The test validates empirical mean, variance, and estimated time constant against expected OU statistics.


class MeanRevertingNoise : public StatefulSysModel
#include <meanRevertingNoise.h>

Base class that provides a scalar Ornstein–Uhlenbeck state x and its stochastic evolution. Derived classes implement output handling.

The state x follows

\[ dx = -\frac{1}{\tau}\,x\,dt + \sqrt{\frac{2}{\tau}}\,\sigma_{\text{st}}\,dW \]
The base class: 1) registers a 1-by-1 state with one noise source 2) computes drift and diffusion each step 3) calls the user hook writeOutput(CurrentSimNanos, x)

Subclassed by StochasticAtmDensity, StochasticDragCoeff

Public Functions

MeanRevertingNoise() = default

Default constructor. Parameters remain at defaults.

void registerStates(DynParamRegisterer registerer) override

Register the scalar OU state with one noise source.

Parameters:

registerer – Simulation state registerer.

void UpdateState(uint64_t CurrentSimNanos) override

Update the OU state drift and diffusion, then call writeOutput.

Parameters:

CurrentSimNanos – Current simulation time in nanoseconds.

inline double getStationaryStd() const

Get stationary standard deviation \(\sigma_{\text{st}}\).

void setStationaryStd(double s)

Set stationary standard deviation \(\sigma_{\text{st}}\).

Parameters:

s – Nonnegative expected.

inline double getTimeConstant() const

Get time constant \(\tau\) [s].

void setTimeConstant(double t)

Set time constant \(\tau\) [s].

Parameters:

t – Positive expected.

inline double getTheta() const

Get \(\theta = 1/\tau\) [s^{-1}].

inline double getSigma() const

Get diffusion amplitude \(\sigma = \sqrt{2/\tau}\,\sigma_{\text{st}}\).

double getStateValue() const

Get the current scalar state x.

Throws:

std::runtime_error – if called before registerStates.

void setStateValue(double val)

Set the scalar state x.

Parameters:

val – New value.

Throws:

std::runtime_error – if called before registerStates.

Public Members

BSKLogger bskLogger

Logger.

Protected Functions

virtual void writeOutput(uint64_t CurrentSimNanos, double x) = 0

Pure virtual output hook. Called every step after drift and diffusion are set. Use this to read inputs if needed and write outputs.

Parameters:
  • CurrentSimNanos – Current simulation time in nanoseconds.

  • x – Current scalar state value.

Private Members

StateData *xState = nullptr
double sigmaStationary = 0.0

Stationary std dev of x.

double timeConstant = 1.0

OU time constant in seconds.