From e2275aa92751b70158e1e1c48dc9d760f54eb0bd Mon Sep 17 00:00:00 2001 From: atrayees <121290945+atrayees@users.noreply.github.com> Date: Fri, 26 Jul 2024 16:49:08 +0530 Subject: [PATCH] function to tune walkL --- examples/correlation_matrices/sampler.cpp | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/examples/correlation_matrices/sampler.cpp b/examples/correlation_matrices/sampler.cpp index 0655767ea..5ed72c47e 100644 --- a/examples/correlation_matrices/sampler.cpp +++ b/examples/correlation_matrices/sampler.cpp @@ -18,6 +18,8 @@ #include "random_walks/random_walks.hpp" #include "sampling/sample_correlation_matrices.hpp" #include "matrix_operations/EigenvaluesProblems.h" +#include "diagnostics/effective_sample_size.hpp" +#include "diagnostics/univariate_psrf.hpp" typedef double NT; typedef Eigen::Matrix MT; @@ -161,6 +163,46 @@ void correlation_matrix_uniform_sampling_MT(const unsigned int n, const unsigned write_to_file(walkname + "_matrices_MT" + std::to_string(n) + ".txt", randPoints); } +template +void tune_walkL(const std::vector& walkL_values, const std::vector& dimensions, const unsigned int num_points, + const unsigned int nburns, const unsigned int num_matrices){ + for (unsigned int n : dimensions) { + std::list randCorMatrices; + + for (unsigned int walkL : walkL_values) { + std::chrono::steady_clock::time_point start, end; + double time; + start = std::chrono::steady_clock::now(); + + uniform_correlation_sampling_MT(n, randCorMatrices, walkL, num_points, 0); + + end = std::chrono::steady_clock::now(); + time = std::chrono::duration_cast(end - start).count(); + std::cout << "Elapsed time : " << time << " (ms)" << std::endl; + + VT samples(n, randCorMatrices.size()); + int idx = 0; + for (const auto& matrix : randCorMatrices) { + samples.col(idx++) = matrix; + } + + //calculate psrf + VT psrf = univariate_psrf(samples); + double max_psrf = psrf.maxCoeff(); + std::cout << "Maximum psrf = " << max_psrf << std::endl; + + //calculate ess + unsigned int min_ess = 0; + VT ess_vector = effective_sample_size(samples, min_ess); + std::cout << "Minimum Ess = " << min_ess << std::endl; + + // Clear the matrices for the next iteration + randCorMatrices.clear(); + } + } +} + + int main(int argc, char const *argv[]){ // To enable Intel MKL, change option USE_MKL to ON in CMakeLists.txt