-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheigentest.cpp
More file actions
85 lines (73 loc) · 2 KB
/
eigentest.cpp
File metadata and controls
85 lines (73 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <Eigen/Core>
#include <Eigen/Dense>
#include "TRandom3.h"
#include <boost/program_options.hpp>
#include <iostream>
using Eigen::MatrixXd;
using Eigen::VectorXd;
using namespace std;
using namespace ROOT;
using namespace boost::program_options;
int main(int argc, char* argv[])
{
variables_map vm;
try
{
options_description desc{"Options"};
desc.add_options()
("help,h", "Help screen")
("ndim", value<int>()->default_value(100), "")
("noise", value<double>()->default_value(0.01), "")
("ntoys", value<int>()->default_value(10000), "");
store(parse_command_line(argc, argv, desc), vm);
notify(vm);
if (vm.count("help")){
std::cout << desc << '\n';
return 0;
}
}
catch (const error &ex)
{
std::cerr << ex.what() << '\n';
}
TRandom3* ran = new TRandom3();
int ndim = vm["ndim"].as<int>();
int ntoys = vm["ntoys"].as<int>();
double noise = vm["noise"].as<double>();
VectorXd u0 = VectorXd::Zero(ndim);
VectorXd u = VectorXd::Zero(ndim);
MatrixXd nunuT = MatrixXd::Zero(ndim,ndim);
MatrixXd identity = MatrixXd::Zero(ndim,ndim);
for(unsigned int i=0; i<ndim; i++){
u0(i) = ran->Gaus(0., 1.);
identity(i,i) = 1;
}
u0 /= u0.norm();
double nu2 = 0.;
double nu_mean = 0.;
for(unsigned int itoy=0; itoy < ntoys; itoy++){
for(unsigned int i=0; i<ndim; i++){
u(i) = u0(i) + ran->Gaus(0., noise);
}
u /= u.norm();
VectorXd nu = u - u0;
nu2 += nu.squaredNorm();
nu_mean += nu.norm();
nunuT += nu*nu.transpose();
}
nunuT /= ntoys;
nu2 /= ntoys;
nu_mean /= ntoys;
nunuT /= (nu2);
nunuT *= ndim-1;
cout << "nu2 = " << nu2 << endl;
cout << "nu_mean2 = " << nu_mean*nu_mean << endl;
cout << "nu*nu.T: " << endl;
cout << nunuT << endl;
cout << "(1 - nu0*nu0.T)/<nu2>*(n-1): " << endl;
cout << identity-(u0*u0.transpose()) << endl;
cout << "Difference: " << endl;
cout << nunuT - (identity-(u0*u0.transpose())) << endl;
delete ran;
return 0;
}