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).dWis the Wiener increment for each noise source;dZis 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 ignoredZ.With time step
h, each entry ofdWanddZis distributed as \(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
mnoise sources and time steph. Both returned vectors have lengthm.
-
virtual ~GaussianNoiseGenerator() = default
-
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
dWanddZis drawn as \(\sqrt{h}\,N(0,1)\). ThedWentries are drawn first (indices 0..m-1), then thedZentries.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
mnoise sources and time steph. Both returned vectors have lengthm.
-
inline virtual void setSeed(size_t seed) override
-
class PrescribedGaussianNoiseGenerator : public GaussianNoiseGenerator
- #include <stochasticNoiseGenerator.h>
Replays a pre-computed sequence of Gaussian increments.
Each call to
generatepops 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/dZvalues are the actual increments (already scaled to the step, i.e. distributed as \(N(0,h)\)); they are returned verbatim and thehargument togenerateis ignored for the values themselves. If a generate call is made after the queue is exhausted, astd::runtime_erroris 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
mnoise sources and time steph. Both returned vectors have lengthm.
Protected Attributes
-
std::deque<GaussianNoiseSample> queue
FIFO of prescribed increments, one entry per integration step.
-
inline virtual void setSeed(size_t) override