Skip to content

Commit

Permalink
Added copyright headers and fixed template passing
Browse files Browse the repository at this point in the history
  • Loading branch information
vgnecula committed Jul 18, 2024
1 parent 013c5b5 commit dd3cc03
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 38 deletions.
11 changes: 8 additions & 3 deletions examples/crhmc_cooling_gaussians/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 )
Expand Down
15 changes: 13 additions & 2 deletions examples/crhmc_cooling_gaussians/volume_example.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -18,7 +29,7 @@ void calculateAndVerifyVolume(HPOLYTOPE& polytope) {

RandomNumberGenerator rng(polytope.dimension());

NT volume = volume_cooling_gaussians_crhmc<HPOLYTOPE, RandomNumberGenerator>(polytope, rng, e, walk_len);
NT volume = volume_cooling_gaussians<HPOLYTOPE, RandomNumberGenerator>(polytope, rng, e, walk_len);

std::cout << "Volume " << volume << std::endl;
}
Expand Down Expand Up @@ -46,4 +57,4 @@ int main() {
calculateAndVerifyVolume(birkhoff);

return 0;
}
}
70 changes: 37 additions & 33 deletions include/volume/volume_cooling_gaussians_crhmc.hpp
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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<WalkType, walk_params, RandomPointGenerator, simdLen, Grad, Func, CrhmcProblem>
NT next_a = get_next_gaussian<CRHMCWalkType, crhmc_walk_params, CRHMCRandomPointGenerator, simdLen, Grad, Func, CrhmcProblem>
(P, p, a_vals[it], N, ratio, C, walk_length, rng, g, f, params, problem, walk);

#ifdef VOLESTI_DEBUG
Expand Down Expand Up @@ -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)
Expand All @@ -249,23 +263,21 @@ double volume_cooling_gaussians_crhmc(Polytope& Pin,

typedef ImplicitMidpointODESolver<Point, NT, CrhmcProblem, Grad, simdLen> Solver;

typedef typename WalkTypePolicy::template Walk
typedef typename CRHMCWalk::template Walk
<
Point,
CrhmcProblem,
RandomNumberGenerator,
Grad,
Func,
Solver
> WalkType;
> CRHMCWalkType;

typedef typename WalkTypePolicy::template parameters
typedef typename CRHMCWalk::template parameters
<
NT,
Grad
> walk_params;

typedef CrhmcRandomPointGenerator<WalkType> RandomPointGenerator;
> crhmc_walk_params;

//const NT maxNT = std::numeric_limits<NT>::max();//1.79769e+308;
//const NT minNT = std::numeric_limits<NT>::min();//-1.79769e+308;
Expand Down Expand Up @@ -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<CRHMCWalkType>,
simdLen, Grad, Func, Hess, func_params, Input
>(P, ratio, C, parameters.frac, N, walk_length, radius, error, a_vals, rng);

#ifdef VOLESTI_DEBUG
Expand Down Expand Up @@ -371,21 +376,20 @@ double volume_cooling_gaussians_crhmc(Polytope& Pin,
//create the crhmc problem
Input input = convert2crhmc_input<Input, Polytope, Func, Grad, Hess>(P, f, g, h);

typedef crhmc_problem<Point, Input> CrhmcProblem;
CrhmcProblem problem = CrhmcProblem(input);

Point p = Point(problem.center);

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)<min_steps)
{
Expand Down Expand Up @@ -445,4 +449,4 @@ double volume_cooling_gaussians_crhmc(Polytope& Pin,
return vol;
}

#endif // VOLUME_COOLING_GAUSSIANS_CRHMC_HPP
#endif // VOLUME_COOLING_GAUSSIANS_CRHMC_HPP

0 comments on commit dd3cc03

Please sign in to comment.