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.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.
-
inline Eigen::VectorXd generateWiener(size_t m, double h)
Returns only the Wiener increments for one step.
This allocation-bearing convenience method is intended for bindings and non-hot-path callers. Native integrators use
generateWienerInto.
-
inline virtual void generateInto(Eigen::VectorXd &dW, Eigen::VectorXd &dZ, size_t m, double h)
Writes one Gaussian sample into caller-owned, pre-sized storage.
The compatibility implementation calls
generate()and may allocate. Generators used on allocation-sensitive paths should override this method to write directly into the supplied buffers.- Parameters:
dW – Pre-sized Wiener-increment output.
dZ – Pre-sized second-increment output.
m – Number of independent noise sources.
h – Integration time step.
-
inline virtual void generateWithAuxiliaryInto(Eigen::VectorXd &dW, Eigen::VectorXd &dZ, size_t m, size_t auxiliaryCount, double h)
Writes Wiener increments and a requested prefix of auxiliary increments.
The compatibility implementation forwards to
generateIntoand may generate more auxiliary values than requested. Built-in generators override this method so methods that need fewer thanmauxiliary values do not pay for unused random draws.
-
inline virtual void generateWienerInto(Eigen::VectorXd &dW, size_t m, double h)
Writes only Wiener increments into caller-owned, pre-sized storage.
The default preserves source compatibility with custom generators by forwarding through
generateInto. Built-in generators override this method to avoid generating an unused auxiliary increment.
Protected Static Functions
-
static inline void requireOutputSize(const Eigen::VectorXd &dW, const Eigen::VectorXd &dZ, size_t m)
Validates caller-owned generator output dimensions.
-
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 generateInto(Eigen::VectorXd &dW, Eigen::VectorXd &dZ, size_t m, double h) override
Writes one Gaussian sample into caller-owned, pre-sized storage.
The compatibility implementation calls
generate()and may allocate. Generators used on allocation-sensitive paths should override this method to write directly into the supplied buffers.- Parameters:
dW – Pre-sized Wiener-increment output.
dZ – Pre-sized second-increment output.
m – Number of independent noise sources.
h – Integration time step.
-
inline virtual void generateWithAuxiliaryInto(Eigen::VectorXd &dW, Eigen::VectorXd &dZ, size_t m, size_t auxiliaryCount, double h) override
Writes Wiener increments and a requested prefix of auxiliary increments.
The compatibility implementation forwards to
generateIntoand may generate more auxiliary values than requested. Built-in generators override this method so methods that need fewer thanmauxiliary values do not pay for unused random draws.
-
inline virtual void generateWienerInto(Eigen::VectorXd &dW, size_t m, double h) override
Writes only Wiener increments into caller-owned, pre-sized storage.
The default preserves source compatibility with custom generators by forwarding through
generateInto. Built-in generators override this method to avoid generating an unused auxiliary increment.
-
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
generateadvances to 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 void discardConsumed()
Discards consumed samples while preserving pending FIFO order.
-
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.
-
inline virtual void generateInto(Eigen::VectorXd &dW, Eigen::VectorXd &dZ, size_t m, double) override
Writes one Gaussian sample into caller-owned, pre-sized storage.
The compatibility implementation calls
generate()and may allocate. Generators used on allocation-sensitive paths should override this method to write directly into the supplied buffers.- Parameters:
dW – Pre-sized Wiener-increment output.
dZ – Pre-sized second-increment output.
m – Number of independent noise sources.
h – Integration time step.
-
inline virtual void generateWithAuxiliaryInto(Eigen::VectorXd &dW, Eigen::VectorXd &dZ, size_t m, size_t auxiliaryCount, double) override
Writes Wiener increments and a requested prefix of auxiliary increments.
The compatibility implementation forwards to
generateIntoand may generate more auxiliary values than requested. Built-in generators override this method so methods that need fewer thanmauxiliary values do not pay for unused random draws.
-
inline virtual void generateWienerInto(Eigen::VectorXd &dW, size_t m, double) override
Writes only Wiener increments into caller-owned, pre-sized storage.
The default preserves source compatibility with custom generators by forwarding through
generateInto. Built-in generators override this method to avoid generating an unused auxiliary increment.
Protected Functions
-
inline const GaussianNoiseSample &nextAndValidate(size_t m, size_t auxiliaryCount)
Advances to and validates the next queued sample.
Protected Attributes
-
std::vector<GaussianNoiseSample> samples
Prescribed increments retained for the lifetime of the replay sequence.
-
size_t cursor = 0
Index of the next prescribed sample to consume.
-
inline virtual void setSeed(size_t) override