@@ -90,28 +90,6 @@ void write_to_file(std::string filename, std::vector<PointType> const& randPoint
90
90
std::cout.rdbuf (coutbuf);
91
91
}
92
92
93
- bool is_correlation_matrix (const MT& matrix, const double tol = 1e-8 ){
94
- // check if all the diagonal elements are ones
95
- for (int i=0 ; i<matrix.rows () ; i++)
96
- {
97
- if (std::abs (matrix (i, i)-1.0 ) > tol)
98
- {
99
- return false ;
100
- }
101
- }
102
-
103
- // check if the matrix is positive semidefinite
104
- using NT = double ;
105
- using MatrixType = Eigen::Matrix<NT, Eigen::Dynamic, Eigen::Dynamic>;
106
- EigenvaluesProblems<NT, MatrixType, Eigen::Matrix<NT, Eigen::Dynamic, 1 >> solver;
107
-
108
- if (solver.isPositiveSemidefinite (matrix))
109
- {
110
- return true ;
111
- }
112
- return false ;
113
- }
114
-
115
93
template <typename WalkType>
116
94
void correlation_matrix_uniform_sampling (const unsigned int n, const unsigned int num_points, std::string walkname){
117
95
@@ -138,26 +116,34 @@ void correlation_matrix_uniform_sampling_MT(const unsigned int n, const unsigned
138
116
std::cout << walkname << " samples uniformly " << num_points << " correlation matrices of size " << n << " with matrix PointType" << std::endl;
139
117
std::chrono::steady_clock::time_point start, end;
140
118
double time ;
141
- std::vector<PointMT> randPoints ;
119
+ std::list<MT> randCorMatrices ;
142
120
unsigned int walkL = 1 ;
143
121
144
122
start = std::chrono::steady_clock::now ();
145
123
146
- uniform_correlation_sampling_MT<WalkType, PointMT, RNGType>(n, randPoints , walkL, num_points, 0 );
124
+ uniform_correlation_sampling_MT<WalkType, PointMT, RNGType>(n, randCorMatrices , walkL, num_points, 0 );
147
125
148
126
end = std::chrono::steady_clock::now ();
149
127
time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count ();
150
128
std::cout << " Elapsed time : " << time << " (ms)" << std::endl;
151
129
152
130
int valid_points = 0 ;
153
131
EigenvaluesProblems<NT, MT, Eigen::Matrix<NT, Eigen::Dynamic, 1 >> solver;
154
- for (const auto & points : randPoints ){
155
- if (solver.is_correlation_matrix (points. mat )){
132
+ for (const auto & matrix : randCorMatrices ){
133
+ if (solver.is_correlation_matrix (matrix )){
156
134
valid_points++;
157
- }
135
+ }
158
136
}
137
+
159
138
std::cout << " Number of valid points = " << valid_points << std::endl;
160
139
140
+ std::vector<PointMT> randPoints;
141
+ for (const auto &mat : randCorMatrices){
142
+ PointMT p;
143
+ p.mat = mat;
144
+ randPoints.push_back (p);
145
+ }
146
+
161
147
write_to_file<PointMT>(walkname + " _matrices_MT" + std::to_string (n) + " .txt" , randPoints);
162
148
}
163
149
0 commit comments