FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
SensorNoise Class Reference

#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)
 

Detailed Description

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.

Note
This is a helper, not a SimObject, so it has no @group block and appears in no model list.

Constructor & Destructor Documentation

◆ SensorNoise()

SensorNoise::SensorNoise ( unsigned int  seed)
explicit

Creates a generator with the given seed.

Parameters
seedThe random seed; zero means deterministic and noise free.

Member Function Documentation

◆ Gamma()

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.

Parameters
shapeThe shape parameter; must be positive.
Returns
One gamma distributed sample with mean one.

◆ Gaussian()

double SensorNoise::Gaussian ( double  mean,
double  stddev 
)

Draws a normally distributed number by the Box-Muller transform.

Parameters
meanThe mean of the distribution.
stddevThe standard deviation of the distribution.
Returns
One normally distributed sample.

◆ Poisson()

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.

Parameters
lambdaThe mean of the distribution; must not be negative.
Returns
One Poisson distributed count.

◆ Uniform()

double SensorNoise::Uniform ( double  low,
double  high 
)

Draws a uniform number.

Parameters
lowThe lower bound, inclusive.
highThe upper bound, exclusive.
Returns
A number drawn uniformly from [low, high).

The documentation for this class was generated from the following file: