Example2 for random number generator
- Author
- MIP
#include <cmath>
#include <cstring>
#include <Base/Math/Random.hh>
using namespace BIAS;
using namespace std;
#define COUNT 1000
int main()
{
double num1, num2;
double mean1 = 10.0, mean2 = -30.0;
double sigma1 = 0.5, sigma2 = 10.0;
double angle = 0.16;
double dist[COUNT][2];
double covm[2][2];
double mean[2], var[2];
for (int i=0; i<2; i++){
mean[i] = var[i] = 0.0;
for (int j=0; j<2; j++)
covm[i][j]=0.0;
}
for (register unsigned int i=0; i<COUNT; i++){
dist[i][0]=num1 * cos(angle) - num2 * sin(angle);
dist[i][1]=num1 * sin(angle) + num2 * cos(angle);
mean[0]+=dist[i][0];
mean[1]+=dist[i][1];
cout << dist[i][0] << "\t" << dist[i][1] << endl;
}
mean[0]/=COUNT;
mean[1]/=COUNT;
cerr << "mean:" << endl;
cerr << mean[0] << "\t" << mean[1] << endl;
for (register unsigned int i=0; i<COUNT; i++){
covm[0][0]+=(dist[i][0]-mean[0])*(dist[i][0]-mean[0]);
covm[1][1]+=(dist[i][1]-mean[1])*(dist[i][1]-mean[1]);
covm[0][1]+=(dist[i][1]-mean[1])*(dist[i][0]-mean[0]);
}
covm[0][0]/=COUNT-1;
covm[1][1]/=COUNT-1;
covm[0][1]/=COUNT-1;
covm[1][0]=covm[0][1];
cerr << "covariance matrix:" << endl;
for (int i=0; i<2; i++){
for (int j=0; j<2; j++){
cerr << covm[i][j] << "\t";
}
cerr << endl;
}
return 0;
}