From dd3cc0327319e56b5af06a073116855c0dd7870d Mon Sep 17 00:00:00 2001 From: vgnecula Date: Thu, 4 Jul 2024 13:49:04 -0400 Subject: [PATCH] Added copyright headers and fixed template passing --- .../crhmc_cooling_gaussians/CMakeLists.txt | 11 ++- .../volume_example.cpp | 15 +++- .../volume/volume_cooling_gaussians_crhmc.hpp | 70 ++++++++++--------- 3 files changed, 58 insertions(+), 38 deletions(-) diff --git a/examples/crhmc_cooling_gaussians/CMakeLists.txt b/examples/crhmc_cooling_gaussians/CMakeLists.txt index e580fbb3e..bcbb5a937 100644 --- a/examples/crhmc_cooling_gaussians/CMakeLists.txt +++ b/examples/crhmc_cooling_gaussians/CMakeLists.txt @@ -1,7 +1,12 @@ # VolEsti (volume computation and sampling library) -# Copyright (c) 2012-2021 Vissarion Fisikopoulos -# Copyright (c) 2018-2021 Apostolos Chalkis -# Contributed and/or modified by Ioannis Iakovidis + +# Copyright (c) 2012-2024 Vissarion Fisikopoulos +# Copyright (c) 2018-2024 Apostolos Chalkis +# Copyright (c) 2024-2024 Vladimir Necula + +# Contributed and/or modified by Vladimir Necula, as part of Google Summer of +# Code 2024 program. + # Licensed under GNU LGPL.3, see LICENCE file project( VolEsti ) diff --git a/examples/crhmc_cooling_gaussians/volume_example.cpp b/examples/crhmc_cooling_gaussians/volume_example.cpp index e02a42136..c9c2f225e 100644 --- a/examples/crhmc_cooling_gaussians/volume_example.cpp +++ b/examples/crhmc_cooling_gaussians/volume_example.cpp @@ -1,3 +1,14 @@ +// VolEsti (volume computation and sampling library) + +// Copyright (c) 2012-2024 Vissarion Fisikopoulos +// Copyright (c) 2018-2024 Apostolos Chalkis +// Copyright (c) 2024-2024 Vladimir Necula + +// Contributed and/or modified by Vladimir Necula, as part of Google Summer of +// Code 2024 program. + +// Licensed under GNU LGPL.3, see LICENCE file + #include "generators/known_polytope_generators.h" #include "random_walks/random_walks.hpp" #include "volume/volume_cooling_gaussians_crhmc.hpp" @@ -18,7 +29,7 @@ void calculateAndVerifyVolume(HPOLYTOPE& polytope) { RandomNumberGenerator rng(polytope.dimension()); - NT volume = volume_cooling_gaussians_crhmc(polytope, rng, e, walk_len); + NT volume = volume_cooling_gaussians(polytope, rng, e, walk_len); std::cout << "Volume " << volume << std::endl; } @@ -46,4 +57,4 @@ int main() { calculateAndVerifyVolume(birkhoff); return 0; -} \ No newline at end of file +} diff --git a/include/volume/volume_cooling_gaussians_crhmc.hpp b/include/volume/volume_cooling_gaussians_crhmc.hpp index 77d282ca5..0f52ae220 100644 --- a/include/volume/volume_cooling_gaussians_crhmc.hpp +++ b/include/volume/volume_cooling_gaussians_crhmc.hpp @@ -1,3 +1,18 @@ +// VolEsti (volume computation and sampling library) + +// Copyright (c) 2012-2024 Vissarion Fisikopoulos +// Copyright (c) 2018-2024 Apostolos Chalkis +// Copyright (c) 2024-2024 Vladimir Necula + +// Contributed and/or modified by Vladimir Necula, as part of Google Summer of +// Code 2024 program. + +// Licensed under GNU LGPL.3, see LICENCE file + +// References +// Yunbum Kook, Yin Tat Lee, Ruoqi Shen, Santosh S. Vempala. "Sampling with +// Riemannian Hamiltonian +// Monte Carlo in a Constrained Space" #ifndef VOLUME_COOLING_GAUSSIANS_CRHMC_HPP #define VOLUME_COOLING_GAUSSIANS_CRHMC_HPP @@ -17,9 +32,9 @@ // Compute a_{i+1} when a_i is given template < - typename WalkType, - typename walk_params, - typename RandomPointGenerator, + typename CRHMCWalkType, + typename crhmc_walk_params, + typename CRHMCRandomPointGenerator, int simdLen, typename Grad, typename Func, @@ -39,9 +54,9 @@ NT get_next_gaussian(Polytope& P, RandomNumberGenerator& rng, Grad& g, Func& f, - walk_params& parameters, + crhmc_walk_params& parameters, CrhmcProblem& problem, - WalkType& crhmc_walk) + CRHMCWalkType& crhmc_walk) { NT last_a = a; @@ -58,7 +73,7 @@ NT get_next_gaussian(Polytope& P, PushBackWalkPolicy push_back_policy; bool raw_output = false; - RandomPointGenerator::apply(problem, p, N, walk_length, randPoints, + CRHMCRandomPointGenerator::apply(problem, p, N, walk_length, randPoints, push_back_policy, rng, g, f, parameters, crhmc_walk, simdLen, raw_output); while (!done) @@ -91,9 +106,9 @@ NT get_next_gaussian(Polytope& P, // Compute the sequence of spherical gaussians template < - typename WalkType, - typename walk_params, - typename RandomPointGenerator, + typename CRHMCWalkType, + typename crhmc_walk_params, + typename CRHMCRandomPointGenerator, int simdLen, typename Grad, typename Func, @@ -165,7 +180,7 @@ void compute_annealing_schedule(Polytope& P, if(problem.terminate){return;} problem.options.simdLen = simdLen; - walk_params params(input.df, p.dimension(), problem.options); + crhmc_walk_params params(input.df, p.dimension(), problem.options); if (input.df.params.eta > 0) { params.eta = input.df.params.eta; @@ -175,10 +190,10 @@ void compute_annealing_schedule(Polytope& P, dim = p.dimension(); //create the walk object for this problem - WalkType walk = WalkType(problem, p, input.df, input.f, params); + CRHMCWalkType walk = CRHMCWalkType(problem, p, input.df, input.f, params); // Compute the next gaussian - NT next_a = get_next_gaussian + NT next_a = get_next_gaussian (P, p, a_vals[it], N, ratio, C, walk_length, rng, g, f, params, problem, walk); #ifdef VOLESTI_DEBUG @@ -227,10 +242,9 @@ template < typename Polytope, typename RandomNumberGenerator, - typename WalkTypePolicy = CRHMCWalk, int simdLen = 8 > -double volume_cooling_gaussians_crhmc(Polytope& Pin, +double volume_cooling_gaussians(Polytope& Pin, RandomNumberGenerator& rng, double const& error = 0.1, unsigned int const& walk_length = 1) @@ -249,7 +263,7 @@ double volume_cooling_gaussians_crhmc(Polytope& Pin, typedef ImplicitMidpointODESolver Solver; - typedef typename WalkTypePolicy::template Walk + typedef typename CRHMCWalk::template Walk < Point, CrhmcProblem, @@ -257,15 +271,13 @@ double volume_cooling_gaussians_crhmc(Polytope& Pin, Grad, Func, Solver - > WalkType; + > CRHMCWalkType; - typedef typename WalkTypePolicy::template parameters + typedef typename CRHMCWalk::template parameters < NT, Grad - > walk_params; - - typedef CrhmcRandomPointGenerator RandomPointGenerator; + > crhmc_walk_params; //const NT maxNT = std::numeric_limits::max();//1.79769e+308; //const NT minNT = std::numeric_limits::min();//-1.79769e+308; @@ -300,15 +312,8 @@ double volume_cooling_gaussians_crhmc(Polytope& Pin, compute_annealing_schedule < - WalkType, - walk_params, - RandomPointGenerator, - simdLen, - Grad, - Func, - Hess, - func_params, - Input + CRHMCWalkType, crhmc_walk_params,CrhmcRandomPointGenerator, + simdLen, Grad, Func, Hess, func_params, Input >(P, ratio, C, parameters.frac, N, walk_length, radius, error, a_vals, rng); #ifdef VOLESTI_DEBUG @@ -371,7 +376,6 @@ double volume_cooling_gaussians_crhmc(Polytope& Pin, //create the crhmc problem Input input = convert2crhmc_input(P, f, g, h); - typedef crhmc_problem CrhmcProblem; CrhmcProblem problem = CrhmcProblem(input); Point p = Point(problem.center); @@ -379,13 +383,13 @@ double volume_cooling_gaussians_crhmc(Polytope& Pin, if(problem.terminate){return 0;} problem.options.simdLen=simdLen; - walk_params params(input.df, p.dimension(), problem.options); + crhmc_walk_params params(input.df, p.dimension(), problem.options); if (input.df.params.eta > 0) { params.eta = input.df.params.eta; } - WalkType walk = WalkType(problem, p, input.df, input.f, params); + CRHMCWalkType walk = CRHMCWalkType(problem, p, input.df, input.f, params); while (!done || (*itsIt)