1#ifndef PROBABILITY_DIST_H
2#define PROBABILITY_DIST_H
12#include <unsupported/Eigen/CXX11/Tensor>
14namespace ProbabilityDistHelpers {
15 int findIndexOfNextSmallestValue(
double x,
const Eigen::VectorXd &vector);
18namespace ProbabilityDist {
32 Uniform(
double min,
double max) : dist_(min, max) {}
40 return dist_(generator_);
50 dist_ = std::uniform_real_distribution<double>(min, max);
53 mutable std::uniform_real_distribution<double> dist_;
54 static thread_local std::mt19937 generator_;
68 explicit DiscreteInversion(
const Eigen::Matrix<double, Eigen::Dynamic, 2> &probabilities_matrix);
84 Eigen::Matrix<double, Eigen::Dynamic, 2> probabilities_matrix_;
85 Eigen::Matrix<double, Eigen::Dynamic, 2> cdf_matrix_;
86 std::string sampling_algorithm_;
93 static Eigen::VectorXd cumsum(
const Eigen::VectorXd &vector);
96 Eigen::Matrix<double, Eigen::Dynamic, 2> generateCDF()
const;
125 explicit ContinuousInversion(std::function<
double(
double,
double)> &PDF, Eigen::VectorXd &energies,
double x_min,
double x_max,
double err_thresh = 1E-4);
136 std::function<double(
double,
double)> PDF_;
137 std::function<double(
double,
double)> normalized_PDF_;
138 std::vector<Eigen::Array<double, Eigen::Dynamic, 2>> CDF_;
139 Eigen::VectorXd energies_;
140 std::vector<Eigen::Array<double, Eigen::Dynamic, 2>> interp_parameters_;
146 void normalizePDF(
double E);
148 double getXFromY(
int energy_index,
double y)
const;
150 void initializeCDFAndInterpolationParameters();
152 Eigen::Array<double, Eigen::Dynamic, 2> calculateInterpolationParametersPerEnergy(
153 double E, Eigen::Array<double, Eigen::Dynamic, 2> CDF_RITA_PER_ENERGY);
155 Eigen::Array<double, Eigen::Dynamic, 2> getMinimizedErrorCDFPerEnergy(
double E,
double err_thresh);
157 Eigen::Array<double, Eigen::Dynamic, 2> generateCDFPerEnergy(
double E, Eigen::VectorXd x_grid);
159 double getInterpErrorOverInterval(
double E,
IntervalData id)
const;
161 double getPDFFromCDFOverInterval(
double E,
double x,
IntervalData id)
const;
Class which uses PENELOPE's RITA inversion sampling algorithm to sample from a continuous distributio...
double sample(double E) const
Returns a sample from the continuous distribution.
ContinuousInversion(std::function< double(double, double)> &PDF, Eigen::VectorXd &energies, double x_min, double x_max, double err_thresh=1E-4)
Constructor for the ContinuousInversion class.
Class which uses inversion sampling to sample from a discrete distribution.
double getExpectationValue() const
Returns the expectation value of the discrete distribution.
double sample() const
Returns a sample from the discrete distribution.
DiscreteInversion(const Eigen::Matrix< double, Eigen::Dynamic, 2 > &probabilities_matrix)
Constructor for the DiscreteInversion class.