Google summer of code'24, Week 8.

A tuning function.

Posted by Atrayee Samanta on July 26, 2024

In my last week, I focused on tuning one of the parameters: the walk length.

My Code

Here is my function:


template<typename WalkTypePolicy, typename PointType, typename RNGType, typename MT>
void tune_walkL(const std::vector<unsigned int>& walkL_values, const std::vector<unsigned int>& dimensions, const unsigned int num_points,
            	const unsigned int nburns, const unsigned int num_matrices){
    for (unsigned int n : dimensions) {
        std::list<MT> 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<WalkTypePolicy, PointType, 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) for dimension: " << n << std::endl;

            int d = n*(n-1)/2;
            MT samples(d, num_points);
            unsigned int jj = 0;
            for(auto& mat : randCorMatrices){
                samples.col(jj) = getCoefficientsFromMatrix<NT, MT>(mat);
            	jj++;
            }

            //calculate psrf
            VT psrf = univariate_psrf<NT, VT, MT>(samples);
            double max_psrf = psrf.maxCoeff();
       	    std::cout << "PSRF = " << max_psrf << std::endl;

    	    //calculate ess
            unsigned int min_ess = 0;
            VT ess_vector = effective_sample_size<NT, VT, MT>(samples, min_ess);
	    std::cout << "Effective Sample Size = " << min_ess << std::endl;
            std::cout << "Average Effective Sample Size = " << min_ess/num_matrices << std::endl;

            // Clear the matrices for the next iteration
            randCorMatrices.clear();
    	}
    }
}

This function has the following input parameters-

  1. walkl_values- a vector of different walk length values to tune
  2. dimensions- a vector of different dimensions for the correlation matrices
  3. num_points- number of points to generate during the sampling process
  4. nburns- number of burn-in samples
  5. num_matrices- number of matrices to be sampled

This function is used to tune the walk length values, for identifying an optimal value for the walk length for the sampling of correlation matrices. 3 metrics are used to measure the efficiency of a particular walk length-

  • Run time
  • The value of the univariate PSRF
  • The value of the effective sampling size.

This function iterates over all the dimensions as specified in the input parameter, and prints the values of our required metrics.