Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GaussianNoiseModel: avoid calling DblNormal with invalid standard deviation #396

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/GaussianNoiseModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ void GaussianNoiseModel::Load(const sdf::Noise &_sdf)
double biasStdDev = 0;
biasMean = _sdf.BiasMean();
biasStdDev = _sdf.BiasStdDev();
this->dataPtr->bias = math::Rand::DblNormal(biasMean, biasStdDev);
if (biasStdDev > 0.0)
this->dataPtr->bias = math::Rand::DblNormal(biasMean, biasStdDev);
else
this->dataPtr->bias = biasMean;

// With equal probability, we pick a negative bias (by convention,
// rateBiasMean should be positive, though it would work fine if
Expand All @@ -108,8 +111,9 @@ void GaussianNoiseModel::Load(const sdf::Noise &_sdf)
double GaussianNoiseModel::ApplyImpl(double _in, double _dt)
{
// Generate independent (uncorrelated) Gaussian noise to each input value.
double whiteNoise = math::Rand::DblNormal(
this->dataPtr->mean, this->dataPtr->stdDev);
double whiteNoise = this->dataPtr->stdDev > 0.0 ?
math::Rand::DblNormal(this->dataPtr->mean, this->dataPtr->stdDev) :
this->dataPtr->mean;

// Generate varying (correlated) bias to each input value.
// This implementation is based on the one available in Rotors:
Expand Down