-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/symmetric correlation matrix #321
Merged
TolisChal
merged 5 commits into
GeomScale:develop
from
atrayees:feature/symmetric-correlation-matrix
Jul 22, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,21 @@ MT rebuildMatrix(const VT &xvector, const unsigned int n){ | |
return mat; | ||
} | ||
|
||
template<typename NT, typename MT> | ||
Eigen::Matrix<NT, Eigen::Dynamic, 1> getCoefficientsFromMatrix(const MT& mat) { | ||
int n = mat.rows(); | ||
int d = n * (n - 1) / 2; | ||
Eigen::Matrix<NT, Eigen::Dynamic, 1> coeffs(d); | ||
int k = 0; | ||
for (int i = 0; i < n; ++i) { | ||
for (int j = 0; j < i; ++j) { | ||
coeffs(k) = mat(i, j); | ||
++k; | ||
} | ||
} | ||
return coeffs; | ||
} | ||
|
||
template<typename NT, typename VT, typename MT, typename PointList> | ||
void check_output(PointList &randPoints, int num_points, int n){ | ||
int d = n*(n-1)/2, count = 0; | ||
|
@@ -64,6 +79,33 @@ void check_output(PointList &randPoints, int num_points, int n){ | |
CHECK(score.maxCoeff() < 1.1); | ||
} | ||
|
||
template<typename NT, typename VT, typename MT> | ||
void check_output_MT(std::list<MT> &randCorMatrices, int num_points, int n){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz fix indentation in this function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. really sorry for overlooking this. i fixed it |
||
int d = n*(n-1)/2, count = 0; | ||
MT A; | ||
Eigen::LDLT<MT> mat_ldlt; | ||
for(auto& mat : randCorMatrices){ | ||
mat_ldlt = Eigen::LDLT<MT>(mat); | ||
if(mat_ldlt.info() == Eigen::NumericalIssue || !mat_ldlt.isPositive()){ | ||
++count; | ||
} | ||
} | ||
std::cout << "Fails " << count << " / " << num_points << " samples\n"; | ||
CHECK(count == 0); | ||
|
||
MT samples(d, num_points); | ||
unsigned int jj = 0; | ||
for(const auto& mat : randCorMatrices){ | ||
samples.col(jj) = getCoefficientsFromMatrix<NT, MT>(mat); | ||
jj++; | ||
} | ||
|
||
VT score = univariate_psrf<NT, VT>(samples); | ||
std::cout << "psrf = " << score.maxCoeff() << std::endl; | ||
|
||
CHECK(score.maxCoeff() < 1.1); | ||
} | ||
|
||
template <typename NT> | ||
void test_corre_spectra_classes(unsigned int const n){ | ||
typedef Cartesian<NT> Kernel; | ||
|
@@ -136,18 +178,18 @@ void test_new_uniform_MT(const unsigned int n, const unsigned int num_points = 1 | |
std::cout << "Test new sampling 2 : "<< num_points << " uniform correlation matrices of size " << n << std::endl; | ||
std::chrono::steady_clock::time_point start, end; | ||
double time; | ||
std::vector<Point> randPoints; | ||
std::list<MT> randCorMatrices; | ||
unsigned int walkL = 1; | ||
|
||
start = std::chrono::steady_clock::now(); | ||
|
||
uniform_correlation_sampling_MT<WalkType, Point, RNGType>(n, randPoints, walkL, num_points, 0); | ||
uniform_correlation_sampling_MT<WalkType, Point, RNGType>(n, randCorMatrices, walkL, num_points, 0); | ||
|
||
end = std::chrono::steady_clock::now(); | ||
time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); | ||
std::cout << "Elapsed time : " << time << " (ms)" << std::endl; | ||
|
||
check_output<NT, VT, MT>(randPoints, num_points, n); | ||
check_output_MT<NT, VT, MT>(randCorMatrices, num_points, n); | ||
} | ||
|
||
int n = 3; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need this function? Notice that the class
CorreMatrix
includes this representation. Look at the member functiongetCoefficients()
.However, it's not clear why this function is needed. Can you comment on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here in the uniform_correlation_sampling_MT() function
p.mat, etc. return type MT, so I'm actually storing MT and not CorreMatrix in
std::list<MT> randCorMatrices
.but getCoefficients() is a member function of the CorreMatrix class, so in the testing function in the loop
since every member of randCorMatrices is MT, I couldn't call the getCoefficients() function which is why I wrote the separate function to get the coefficients
I thought we need this loop for populating the samples variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ic, then let's keep it in the test folder