Skip to content

Commit

Permalink
normal dists default max 1, like other dists
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Jan 17, 2024
1 parent eda706e commit 2081b89
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/random_number_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::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<VALUE_WARNING>("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_; }
Expand Down Expand Up @@ -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<int>::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<VALUE_WARNING>("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_; }
Expand Down

0 comments on commit 2081b89

Please sign in to comment.