Skip to content
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

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

vgnecula
Copy link
Contributor

@vgnecula vgnecula commented Jul 1, 2024

Integrated the CRHMC within the Volume Cooling Gaussians Algorithm.

Also, added an example file.

@vgnecula vgnecula marked this pull request as ready for review July 1, 2024 02:39
@vgnecula vgnecula changed the title CRHMC Integratiojn within Volume Cooling Gaussians CRHMC Integration within Volume Cooling Gaussians Jul 1, 2024
Comment on lines 59 to 75
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);
}
};
Copy link
Member

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?

Comment on lines 302 to 304
update_delta<WalkType>
::apply(walk, 4.0 * chebychev_radius
/ std::sqrt(std::max(NT(1.0), a_vals[it]) * NT(n)));
Copy link
Member

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?

Comment on lines 519 to 521
update_delta<WalkType>
::apply(walk, 4.0 * radius
/ std::sqrt(std::max(NT(1.0), *avalsIt) * NT(n)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Comment on lines 583 to 614
<
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);
}
Copy link
Member

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,
Copy link
Member

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
Copy link
Member

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

Comment on lines 36 to 55
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>;
Copy link
Member

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.

Copy link
Contributor

@vfisikop vfisikop left a 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
Copy link
Contributor

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"
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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;
}
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

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,
Copy link
Contributor

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.

@TolisChal TolisChal force-pushed the develop branch 4 times, most recently from 906e119 to f1abc36 Compare July 7, 2024 02:25
typedef CrhmcRandomPointGenerator<CRHMCWalkType> CRHMCRandomPointGenerator;

CRHMCRandomPointGenerator::apply(problem, p, N, walk_length, randPoints,
push_back_policy, rng, g, f, parameters, crhmc_walk, simdLen, raw_output);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz fix indentation here

Comment on lines 297 to 298
//const NT maxNT = std::numeric_limits<NT>::max();//1.79769e+308;
//const NT minNT = std::numeric_limits<NT>::min();//-1.79769e+308;
Copy link
Member

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);
Copy link
Member

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;

Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else
{ ...

@vgnecula vgnecula reopened this Jul 18, 2024
typedef CrhmcRandomPointGenerator<CRHMCWalkType> CRHMCRandomPointGenerator;

CRHMCRandomPointGenerator::apply(problem, p, N, walk_length, randPoints,
push_back_policy, rng, g, f, parameters, crhmc_walk, simdLen, raw_output);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz fix indentation here

@TolisChal TolisChal merged commit 3325d6a into GeomScale:develop Jul 19, 2024
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants