Example #1
0
void Sampler::discreteCumulativeDistribution( const VectorXd &pdf, VectorXd &cdf )
{
	unsigned int m=pdf.size();
	//cdf.setZero(m);
	
	cdf(0)=pdf(0);
	for (unsigned int i=1; i<m; i++)
		cdf.coeffRef(i)=cdf.coeffRef(i-1)+pdf(i);
}
Example #2
0
double Sampler::inverseCumulativeSampling( const VectorXd &cdf, double delta )
{
	int i=0;
	int m=cdf.size();
	double u = unifRand(0.0,1.0);
	while ( i<m && cdf.coeffRef(i)<u  ) ++i;
		
	double value = ( static_cast<double>(i) - static_cast<double>(m)*0.5 ) *delta;
	return value;
}