本文整理汇总了C++中Sampler::fullIntegrate方法的典型用法代码示例。如果您正苦于以下问题:C++ Sampler::fullIntegrate方法的具体用法?C++ Sampler::fullIntegrate怎么用?C++ Sampler::fullIntegrate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sampler
的用法示例。
在下文中一共展示了Sampler::fullIntegrate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char*argv[])
{
randomizeStart();
srand(time(0));
unsigned int nDimensions=2;
double domainMin =-10;
double domainMax = 10;
double domainStep= 0.1;
vector < pair<double, double> > domain;
double dgranularity= (abs(domainMax-domainMin))/domainStep;
unsigned int granularity = floor(dgranularity+0.5);
unsigned int nGibbsBurnIn=0;
unsigned int nGibbsValid=1000;
domain.resize(nDimensions);
for (unsigned int i=0; i<nDimensions; i++)
domain[i] = pair<double,double>(domainMin,domainMax);
DMultivariateGaussian model(nDimensions);
Inferencer inferencer;
inferencer.init( &model, nDimensions,granularity, domainStep, domain );
/*
for ( unsigned i=1000; i<=5000; i+=500)
{
inferencer.init( &model, nDimensions,granularity, domainStep, domain );
cerr << i << " " << inferencer.gibbsSamplingIntegral(nGibbsBurnIn,i) << endl;
}
*/
Sampler sampler;
VectorXd cdf(2000),pdf(2000);
double x=-6;
double delta=abs(x)/1000.0;
for ( int i=0; i<2000; i++)
{
pdf(i) = exp(-(0.5*(x*x) ));
//cout << x << " " << exp(-(0.5*(x*x) )) << endl;
x+=delta;
}
pdf*=1.0/(sqrt(2*M_PI));
cout << sampler.fullIntegrate(pdf,delta) << endl;
//cerr << cdf.sum()*delta << endl;
sampler.discreteCumulativeDistribution(pdf,cdf);
for ( int i=0; i<10; i++)
sampler.inverseCumulativeSampling(cdf,delta);
/*
x=-5;
double sum=cdf.sum();
cdf/=(sum/(1000.0));
for ( int i=0; i<2000; i++)
{
cout << x << " " << cdf(i) << endl;
x+=delta;
}
for ( int i=0; i<100000; i++)
cerr << sampler.inverseCumulativeSampling(cdf,delta) << endl;
*/
return 0;
}