|
FhSim
3.1.0
Marine systems simulation
|
#include <SensorNoise.h>
Public Member Functions | |
| SensorNoise (unsigned int seed) | |
| bool | IsDeterministic () const |
| True when the generator is seeded zero and callers should add no noise. | |
| double | Uniform (double low, double high) |
| double | Gaussian (double mean, double stddev) |
| int | Poisson (double lambda) |
| double | Gamma (double shape) |
Draws the random numbers the AUV sensors need, reproducibly on any platform.
The distributions are hand-rolled on top of std::mt19937 and std::uniform_real_distribution only. This is the single most important property of this class. std::normal_distribution, std::poisson_distribution and std::gamma_distribution have implementation-defined algorithms: the same engine and the same seed produce different numbers under libstdc++, libc++ and the MSVC standard library, so a recorded regression baseline would pass on one platform and fail on another. std::mt19937 and std::uniform_real_distribution are specified exactly by the standard, and every distribution here is built from them by a published algorithm, so the sequence is fixed everywhere. Do not replace any of these with the standard distributions.
A seed of zero means deterministic operation: the sensor is noise free and the simulation is an exact regression baseline, which is also the most useful configuration when debugging a model. Callers ask IsDeterministic and skip the perturbation entirely rather than drawing zero-width noise. A generator seeded zero that is asked for a draw anyway returns the mean of the distribution, so forgetting to branch degrades the model quietly rather than reintroducing randomness.
@group block and appears in no model list.
|
explicit |
Creates a generator with the given seed.
| seed | The random seed; zero means deterministic and noise free. |
| double SensorNoise::Gamma | ( | double | shape | ) |
Draws a gamma distributed number of unit mean.
The Marsaglia-Tsang method is used with scale 1/shape, so the mean is one and the variance is 1/shape. This is the multiplicative speckle factor the acoustic sensors need.
| shape | The shape parameter; must be positive. |
| double SensorNoise::Gaussian | ( | double | mean, |
| double | stddev | ||
| ) |
Draws a normally distributed number by the Box-Muller transform.
| mean | The mean of the distribution. |
| stddev | The standard deviation of the distribution. |
| int SensorNoise::Poisson | ( | double | lambda | ) |
Draws a Poisson distributed count.
Knuth's product method is used below kPoissonNormalLimit, where its expected number of uniform draws is small, and a rounded and clamped normal approximation above it, where the product method becomes slow and the approximation is good.
| lambda | The mean of the distribution; must not be negative. |
| double SensorNoise::Uniform | ( | double | low, |
| double | high | ||
| ) |
Draws a uniform number.
| low | The lower bound, inclusive. |
| high | The upper bound, exclusive. |
[low, high).