Chi-Tech
chi_math::CDFSampler Class Reference

#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_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CDFSampler()

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.

Member Function Documentation

◆ Sample()

int chi_math::CDFSampler::Sample ( double  x)

Initiates the sampling process.

Definition at line 135 of file cdfsampler.cc.

Field Documentation

◆ AUTO_FINERES

const int chi_math::CDFSampler::AUTO_FINERES = -2
static

Definition at line 31 of file cdfsampler.h.

◆ AUTO_SUBDIV

const int chi_math::CDFSampler::AUTO_SUBDIV = -1
static

Definition at line 30 of file cdfsampler.h.

◆ final_res_

int chi_math::CDFSampler::final_res_
private

Definition at line 35 of file cdfsampler.h.

◆ ref_cdf_

std::vector<double>& chi_math::CDFSampler::ref_cdf_
private

Definition at line 36 of file cdfsampler.h.

◆ sub_intvls_

std::vector<SubIntvl*> chi_math::CDFSampler::sub_intvls_
private

Definition at line 37 of file cdfsampler.h.

◆ subdiv_factor_

int chi_math::CDFSampler::subdiv_factor_
private

Definition at line 34 of file cdfsampler.h.


The documentation for this class was generated from the following files: