Merge pull request #1890 from ojschumann/rational_dist

Rational univariate distribution
This commit is contained in:
Paul Romano 2021-10-12 22:26:02 -05:00 committed by GitHub
commit c2fe6327e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 234 additions and 8 deletions

View file

@ -80,6 +80,32 @@ private:
double b_; //!< Upper bound of distribution
};
//==============================================================================
//! PowerLaw distribution over the interval [a,b] with exponent n : p(x)=c x^n
//==============================================================================
class PowerLaw : public Distribution {
public:
explicit PowerLaw(pugi::xml_node node);
PowerLaw(double a, double b, double n)
: offset_ {std::pow(a, n + 1)}, span_ {std::pow(b, n + 1) - offset_},
ninv_ {1 / (n + 1)} {};
//! Sample a value from the distribution
//! \param seed Pseudorandom number seed pointer
//! \return Sampled value
double sample(uint64_t* seed) const;
double a() const { return std::pow(offset_, ninv_); }
double b() const { return std::pow(offset_ + span_, ninv_); }
double n() const { return 1 / ninv_ - 1; }
private:
//! Store processed values in object to allow for faster sampling
double offset_; //!< a^(n+1)
double span_; //!< b^(n+1) - a^(n+1)
double ninv_; //!< 1/(n+1)
};
//==============================================================================
//! Maxwellian distribution of form c*sqrt(E)*exp(-E/theta)
//==============================================================================