📄 test_discretepdf.cpp
字号:
// $Id: test_discretepdf.cpp,v 1.14 2004/11/05 15:21:06 wmeeusse Exp $// KG october 2002: test program for the discrete distribution#include <pdf/discretepdf.h>#include <matrix_wrapper.h>#include <vector_wrapper.h>#include <iostream>using namespace std;using namespace BFL;using namespace MatrixWrapper;#define NUMBER_OF_CFS 5// Mapping between discrete class and simple numbers#define CF1 0#define CF2 1#define CF3 2#define CF4 3#define CF5 4#define SUCCES 0;#define NUM_SAMPLES 10000int main (){ cerr << "==================================================\n" << "Test of the Discrete PDF class applied to CF\n" << "estimation\n" << "==================================================" << endl; DiscretePdf CF_estimate(NUMBER_OF_CFS); ColumnVector uniform_vector(NUMBER_OF_CFS); uniform_vector = CF_estimate.ProbabilitiesGet(); cout << "A priori probabilities (5 Contact formations):\n" << uniform_vector << endl; CF_estimate.ProbabilitySet(CF3,100); uniform_vector = CF_estimate.ProbabilitiesGet(); cout << "After setting the probability of CF3 to 100:\n" << uniform_vector << endl; cerr << "Sampling " << NUM_SAMPLES << " samples from PDF" << endl; list<Sample<int> > samples(NUM_SAMPLES); list<Sample<int> >::iterator it; samples = CF_estimate.SampleFrom(NUM_SAMPLES,DEFAULT,NULL); // Calculating the mean of the samples cerr << "Calculating mean and covariance of samples" << endl; double mean; double sum; mean = 0.0 ; sum = 0.0; for (it = samples.begin(); it != samples.end(); it++) { // cerr << "sample:\n" << it->ValueGet() << endl; sum += it->ValueGet(); } mean = sum * (1.0 / NUM_SAMPLES); // Calculating the covariance matrix double diff; // Temporary storage double diffsum; diffsum = 0.0; for (it = samples.begin(); it != samples.end(); it++) { diff = it->ValueGet() - mean; diffsum += diff * diff; } double Covariance; Covariance = (( 1.0 / (NUM_SAMPLES-1) ) * diffsum); cout << "mean of the samples = \n" << mean << endl; cout << "Covariance Matrix of samples =\n" << Covariance << endl; return SUCCES;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -