stochasticNoiseGenerator

struct GaussianNoiseSample
#include <stochasticNoiseGenerator.h>

One draw of the Gaussian random variables needed to advance a stochastic integrator by a single time step.

Both members have length m (the number of independent noise sources). dW is the Wiener increment for each noise source; dZ is a second, independent Wiener increment required by the higher-order Roessler methods (SRI/SRA) to build the mixed iterated integrals. Methods that only need the Wiener increment (e.g. Euler-Maruyama, Euler-Heun, RKMil) simply ignore dZ.

With time step h, each entry of dW and dZ is distributed as \(N(0, h)\).

Public Members

Eigen::VectorXd dW

Wiener increment per noise source, ~ N(0, h).

Eigen::VectorXd dZ

Second independent Wiener increment per noise source, ~ N(0, h).

class GaussianNoiseGenerator
#include <stochasticNoiseGenerator.h>

Interface for the random-variable source used by the native stochastic integrators.

Separating the noise generation from the integrator lets a test install a generator that replays a known sequence of increments (see PrescribedGaussianNoiseGenerator), which is how the Basilisk integrators are checked for numerical equivalence against a reference implementation.

Warning

Stochastic integration is in beta.

Subclassed by PrescribedGaussianNoiseGenerator, RandomGaussianNoiseGenerator

Public Functions

virtual ~GaussianNoiseGenerator() = default
virtual void setSeed(size_t seed) = 0

Sets the seed for the underlying RNG (if any).

virtual GaussianNoiseSample generate(size_t m, double h) = 0

Returns the Gaussian increments for one step with m noise sources and time step h. Both returned vectors have length m.

class RandomGaussianNoiseGenerator : public GaussianNoiseGenerator
#include <stochasticNoiseGenerator.h>

Draws the Gaussian increments from a Mersenne-Twister RNG.

This is the default generator used in production. Each entry of dW and dZ is drawn as \(\sqrt{h}\,N(0,1)\). The dW entries are drawn first (indices 0..m-1), then the dZ entries.

Public Functions

inline virtual void setSeed(size_t seed) override

Sets the seed for the underlying RNG (if any).

inline virtual GaussianNoiseSample generate(size_t m, double h) override

Returns the Gaussian increments for one step with m noise sources and time step h. Both returned vectors have length m.

Protected Attributes

std::mt19937 rng = {std::random_device{}()}

Random Number Generator

std::normal_distribution<double> normal_rv = {0., 1.}

Standard normally distributed random variable

class PrescribedGaussianNoiseGenerator : public GaussianNoiseGenerator
#include <stochasticNoiseGenerator.h>

Replays a pre-computed sequence of Gaussian increments.

Each call to generate pops the next queued sample. This is used by the unit tests to feed a native integrator exactly the same Wiener increments that a reference implementation used, so that the two can be compared to within floating-point tolerance.

The queued dW/dZ values are the actual increments (already scaled to the step, i.e. distributed as \(N(0,h)\)); they are returned verbatim and the h argument to generate is ignored for the values themselves. If a generate call is made after the queue is exhausted, a std::runtime_error is thrown.

Public Functions

inline virtual void setSeed(size_t) override

Seeding has no effect on a prescribed generator.

inline void pushStep(const std::vector<double> &dW, const std::vector<double> &dZ = {})

Appends one step’s worth of increments to the replay queue.

Parameters:
  • dW – Wiener increments for each noise source for this step.

  • dZ – Second Wiener increments for each noise source for this step. May be empty for methods that do not use it, in which case a zero vector of matching length is returned.

inline void clear()

Removes all queued samples.

inline size_t remaining() const

Number of steps still queued.

inline virtual GaussianNoiseSample generate(size_t m, double) override

Returns the Gaussian increments for one step with m noise sources and time step h. Both returned vectors have length m.

Protected Attributes

std::deque<GaussianNoiseSample> queue

FIFO of prescribed increments, one entry per integration step.