initialize Discrete distribution with sequence of integers

This commit is contained in:
Paul P.H. Wilson 2023-03-16 14:37:05 -05:00
parent e24aa7b8f7
commit 2d20cd31f2
2 changed files with 14 additions and 0 deletions

View file

@ -39,6 +39,7 @@ class Discrete : public Distribution {
public:
explicit Discrete(pugi::xml_node node);
Discrete(const double* x, const double* p, int n);
Discrete(const double* p, int n);
//! Sample a value from the distribution
//! \param seed Pseudorandom number seed pointer

View file

@ -41,6 +41,19 @@ Discrete::Discrete(const double* x, const double* p, int n)
this->init_alias(x_vec, p_vec);
}
Discrete::Discrete(const double* p, int n)
{
std::vector<double> p_vec(p, p + n);
std::vector<double> x_vec(n);
for (int i=0; i<n; i++)
{
x_vec[i] = i;
}
this->init_alias(x_vec, p_vec);
}
void Discrete::init_alias(vector<double>& x, vector<double>& p)
{
x_ = x;