From 2081b89c1020f85d555322ba1e432894d249f59c Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 17 Jan 2024 08:16:06 -0700 Subject: [PATCH] normal dists default max 1, like other dists --- src/random_number_generator.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/random_number_generator.h b/src/random_number_generator.h index 6b6ae7d277..419ef9f204 100644 --- a/src/random_number_generator.h +++ b/src/random_number_generator.h @@ -116,10 +116,13 @@ class NormalDoubleDist : public DoubleDistribution { double min_; double max_; public: - NormalDoubleDist(double mean, double std_dev, double min=0, double max=std::numeric_limits::max()) : dist(mean, std_dev), min_(min), max_(max) { + NormalDoubleDist(double mean, double std_dev, double min=0, double max=1) : dist(mean, std_dev), min_(min), max_(max) { if (min_ == max_) { throw ValueError("Min and max cannot be equal for a normal distribution. Either use FixedDoubleDist or change the min/max."); } + if (max_ < (mean - 3*std_dev) || min_ > (mean + 3*std_dev)) { + Warn("Dist is sampling from a truncated normal more than 3 standard deviations from the mean. Drawing sampling may be inefficient"); + } }; virtual double sample(); virtual double max() { return max_; } @@ -153,10 +156,13 @@ class NormalIntDist : public IntDistribution { int min_; int max_; public: - NormalIntDist(double mean, double std_dev, int min=0, int max=std::numeric_limits::max()) : dist(mean, std_dev), min_(min), max_(max) { + NormalIntDist(double mean, double std_dev, int min=0, int max=1) : dist(mean, std_dev), min_(min), max_(max) { if (min_ == max_) { throw ValueError("Min and max cannot be equal for a normal distribution. Either use FixedIntDist or change the min/max."); } + if (max_ < (mean - 3*std_dev) || min_ > (mean + 3*std_dev)) { + Warn("Dist is sampling from a truncated normal more than 3 standard deviations from the mean. Drawing sampling may be inefficient"); + } }; virtual int sample(); virtual int max() { return max_; }