Chi-Tech
|
#include <cdfsampler.h>
Data Structures | |
struct | SubIntvl |
Public Member Functions | |
CDFSampler (std::vector< double > &in_cdf, int subdiv_factor=AUTO_SUBDIV, int final_res=AUTO_FINERES) | |
int | Sample (double x) |
Static Public Attributes | |
static const int | AUTO_SUBDIV = -1 |
static const int | AUTO_FINERES = -2 |
Private Attributes | |
int | subdiv_factor_ |
int | final_res_ |
std::vector< double > & | ref_cdf_ |
std::vector< SubIntvl * > | sub_intvls_ |
Object for implementing an efficient cdf sampler.
Normal linear sampling of bins of a Cumulative Distribution Function is O(N) for each sample which can lead to very expensive sampling of distributions with many samples. To this end this sampler is designed to subdivide the bins recursively until a suitable linear search can be performed.
The speed-up for cdfs of >1000 bins is more than a factor 100.
In order to use this sampler for repeated sampling calls make sure to initialize it outside the phases that will repeatedly sample it because it has some over-head to it that gets executed in the constructor.
Definition at line 26 of file cdfsampler.h.
chi_math::CDFSampler::CDFSampler | ( | std::vector< double > & | in_cdf, |
int | subdiv_factor = AUTO_SUBDIV , |
||
int | final_res = AUTO_FINERES |
||
) |
Default constructor.
Definition at line 69 of file cdfsampler.cc.
int chi_math::CDFSampler::Sample | ( | double | x | ) |
Initiates the sampling process.
Definition at line 135 of file cdfsampler.cc.
|
static |
Definition at line 31 of file cdfsampler.h.
|
static |
Definition at line 30 of file cdfsampler.h.
|
private |
Definition at line 35 of file cdfsampler.h.
|
private |
Definition at line 36 of file cdfsampler.h.
|
private |
Definition at line 37 of file cdfsampler.h.
|
private |
Definition at line 34 of file cdfsampler.h.