-
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
CRHMC Integration within Volume Cooling Gaussians #314
CRHMC Integration within Volume Cooling Gaussians #314
Conversation
template <typename WalkType> | ||
struct update_delta | ||
{ | ||
template <typename NT> | ||
static void apply(WalkType& walk, NT delta) {} | ||
}; | ||
|
||
template <typename Polytope, typename RandomNumberGenerator> | ||
struct update_delta<GaussianBallWalk::Walk<Polytope, RandomNumberGenerator>> | ||
{ | ||
template <typename NT> | ||
static void apply(GaussianBallWalk::Walk<Polytope, RandomNumberGenerator> walk, | ||
NT delta) | ||
{ | ||
walk.update_delta(delta); | ||
} | ||
}; |
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.
Are they already defined in the volume_cooling_gaussians.hpp
?
update_delta<WalkType> | ||
::apply(walk, 4.0 * chebychev_radius | ||
/ std::sqrt(std::max(NT(1.0), a_vals[it]) * NT(n))); |
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.
Do we need this here? Does this affect the crhmc parameterization?
update_delta<WalkType> | ||
::apply(walk, 4.0 * radius | ||
/ std::sqrt(std::max(NT(1.0), *avalsIt) * NT(n))); |
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.
Do we need this?
< | ||
typename WalkTypePolicy = GaussianCDHRWalk, | ||
typename RandomNumberGenerator = BoostRandomNumberGenerator<boost::mt11213b, double>, | ||
typename Polytope, | ||
int simdLen | ||
> | ||
double volume_cooling_gaussians(Polytope &Pin, | ||
double const& error = 0.1, | ||
unsigned int const& walk_length = 1) | ||
{ | ||
RandomNumberGenerator rng(Pin.dimension()); | ||
return volume_cooling_gaussians<WalkTypePolicy, Polytope, RandomNumberGenerator, simdLen>(Pin, rng, error, walk_length); | ||
} | ||
|
||
|
||
template | ||
< | ||
typename WalkTypePolicy = GaussianCDHRWalk, | ||
typename RandomNumberGenerator = BoostRandomNumberGenerator<boost::mt11213b, double>, | ||
typename Polytope, | ||
int simdLen | ||
> | ||
double volume_cooling_gaussians(Polytope &Pin, | ||
Cartesian<double>::Point const& interior_point, | ||
unsigned int const& walk_length = 1, | ||
double const& error = 0.1) | ||
{ | ||
RandomNumberGenerator rng(Pin.dimension()); | ||
Pin.set_interior_point(interior_point); | ||
|
||
return volume_cooling_gaussians<WalkTypePolicy, Polytope, RandomNumberGenerator, simdLen>(Pin, rng, error, walk_length); | ||
} |
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.
What these calls are useful for? This implementation shouldn't be related to any other random walk.
|
||
// Compute the first variance a_0 for the starting gaussian | ||
template <typename Polytope, typename NT> | ||
void get_first_gaussian(Polytope& P, |
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.
Has this function differences from the get_first_gaussian
in volume/volume_cooling_gaussian.hpp
?
@@ -0,0 +1,550 @@ | |||
#ifndef VOLUME_COOLING_GAUSSIANS_HPP |
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.
Plz change this to VOLUME_COOLING_GAUSSIANS_CRHMC_HPP
using NT = double; | ||
using Kernel = Cartesian<NT>; | ||
using Point = typename Kernel::Point; | ||
using Func = GaussianFunctor::FunctionFunctor<Point>; | ||
using Grad = GaussianFunctor::GradientFunctor<Point>; | ||
using Hess = GaussianFunctor::HessianFunctor<Point>; | ||
|
||
using NegativeLogprobFunctor = GaussianFunctor::FunctionFunctor<Point>; //Func | ||
using NegativeGradientFunctor = GaussianFunctor::GradientFunctor<Point>; //Grad | ||
using HessianFunctor = GaussianFunctor::HessianFunctor<Point>; //Hess | ||
|
||
using PolytopeType = HPolytope<Point>; | ||
using MT = PolytopeType::MT; | ||
using VT = Eigen::Matrix<NT, Eigen::Dynamic, 1>; | ||
using func_params = GaussianFunctor::parameters<NT, Point>; | ||
using RNG = BoostRandomNumberGenerator<boost::mt19937, NT>; | ||
|
||
//Param building -> see sampling_functions.cpp | ||
using Input = crhmc_input<MT, Point, Func, Grad, Hess>; | ||
using CrhmcProblem = crhmc_problem<Point, Input>; |
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.
We shouldn't define them here since this header file can be included in other files and cause redefinition errors. Plz use typedef ...
for only what you need inside each function.
Also, you should use template parameters like NT, MT, VT, Polytope through the templated parameters in each function. For example, in volume_cooling_gaussians, you could define at the beggining,
typedef Polytope::NT NT;
typedef Polytope::MT MT;
....
You can check other templated volume functions and follow the same style.
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.
Thanks! I have a few minor comments.
# 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 |
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.
please update those data
@@ -0,0 +1,49 @@ | |||
#include "generators/known_polytope_generators.h" |
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.
add copyright headers here please
typedef HPolytope<Point> HPOLYTOPE; | ||
|
||
void calculateAndVerifyVolume(HPOLYTOPE& polytope) { | ||
int walk_len = 100; |
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.
does crhmc need such a large value for walk_length?
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.
I found better results with a higher value. Of course, it is not a necessity, but compared to something like 10, it is surely performing better (at least based on my observations and the other current parameters). I think we can later do a better analysis on how this is performing. @TolisChal was also suggesting some modifications for N and W within the gaussian annealing.
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.
In previous volume approximation methods best performance was obtained with walk_length=1.
However, we can check this 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.
Regarding N and W they should be much smaller than their default values, e.g., N=1200 and W=300
calculateAndVerifyVolume(birkhoff); | ||
|
||
return 0; | ||
} |
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.
please add one empty line at the end of every file.
@@ -0,0 +1,448 @@ | |||
#ifndef VOLUME_COOLING_GAUSSIANS_CRHMC_HPP |
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.
please add copyright headers here
auto steps = totalSteps; | ||
|
||
|
||
//create the crhmc problem for this variance |
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.
there is a potential of optimization here, i.e. to create the problem (and the preprocessing) only once and update each time with the new variance. Is the variance needed for the preprocessing or only for sampling?
Could we add a related TODO comment here?
|
||
////////////////////////////// Algorithms | ||
|
||
// Gaussian Anealling |
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.
we can remove this, we have it in the original case but you are creating those new functions especially for the second step, i.e. to sample from non-spherical gaussians.
typename WalkTypePolicy = CRHMCWalk, | ||
int simdLen = 8 | ||
> | ||
double volume_cooling_gaussians_crhmc(Polytope& Pin, |
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.
could we keep the same name? It can be overloaded right?
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.
Another question, what are the changes between this and the original volume_cooling_gaussians? If the changes are only the calls to get_first_gaussian and get_annealing_schedule and the type of the walk, is it possible to use the same function to avoid duplication of the code?
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.
Actually not really. There are slight changes especially to the walk call, which is done within this function as well. For example walk instantiation, apply and after we apply the walk, in the current crhmc implementation the point is not automatically updated, so we need to use p = walk.getPoint();
|
||
compute_annealing_schedule | ||
< | ||
WalkType, |
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.
maybe this it too much, could we just use 2 lines for the templates?
< | ||
typename Polytope, | ||
typename RandomNumberGenerator, | ||
typename WalkTypePolicy = CRHMCWalk, |
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.
CRHMCWalk is the only case right, so this template could be removed.
906e119
to
f1abc36
Compare
typedef CrhmcRandomPointGenerator<CRHMCWalkType> CRHMCRandomPointGenerator; | ||
|
||
CRHMCRandomPointGenerator::apply(problem, p, N, walk_length, randPoints, | ||
push_back_policy, rng, g, f, parameters, crhmc_walk, simdLen, raw_output); |
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.
plz fix indentation here
//const NT maxNT = std::numeric_limits<NT>::max();//1.79769e+308; | ||
//const NT minNT = std::numeric_limits<NT>::min();//-1.79769e+308; |
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.
Shall we delete those two lines?
unsigned int n = P.dimension(); | ||
unsigned int m = P.num_of_hyperplanes(); | ||
gaussian_annealing_parameters<NT> parameters(P.dimension()); | ||
//RandomNumberGenerator rng(n); |
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.
Shall we delete those this line?
{ | ||
|
||
typedef typename Polytope::PointType Point; | ||
|
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.
plz delete this blank line
k = k / 2; | ||
} | ||
done = true; | ||
} else { |
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.
} else
{ ...
eaca7fc
to
7a0be2d
Compare
typedef CrhmcRandomPointGenerator<CRHMCWalkType> CRHMCRandomPointGenerator; | ||
|
||
CRHMCRandomPointGenerator::apply(problem, p, N, walk_length, randPoints, | ||
push_back_policy, rng, g, f, parameters, crhmc_walk, simdLen, raw_output); |
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.
plz fix indentation here
Integrated the CRHMC within the Volume Cooling Gaussians Algorithm.
Also, added an example file.