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

HMC random walks #38

Closed
wants to merge 419 commits into from
Closed

HMC random walks #38

wants to merge 419 commits into from

Conversation

TolisChal
Copy link
Member

This PR contains:

  • Implementations of HMC random walk when the hamiltonian is the logbarrier function of the polytope. We have 4 different implementation of the same random walk.

  • Implementation of the HMC random walk with reflections when the hamiltonian is the spherical Gaussian distribution. We use this walk to CG volume computation method yielding a faster method for H-polytopes

TolisChal added 30 commits July 31, 2018 14:22
…o compute the first point of the CDHR and not to test in every step if this is the first point. We initialize min_plus to max double value and max_min to min double value to avoid checking in every iteration if they are seted for the first time. We add comments in Polytope class and we remove useles comments from samplers.h header file.
… type in volume.h header file and in vol.cpp file. We have to use template number type in nikolic implementation in order to use different number type than double. Pass all the test locally.
… irrespective of the number type we use for the implementaion. We can use float or long double. We made adjustments in tests cpp files in order to use the template number type. We pass all the tests for both double and float.
… declared in volume.h. Now we can use float or long double in Rcpp interface as well.
Use eigen matrix for the H-polytope representation. Able to use float or long double.
… in order to sample the first point for the coordinate directions HnR. Make adjustments in get_annealing_schedule() and in volume_gaussian_annealing() for the first point coordinate case.
…he ratios in gaussian_annealing_volume. Use const bool for the computation of the first coord point.
…e class point_on_Dsphere. We move functions point_in_Dsphere, point_on_Dsphere from gaussian_samplers.h to samplers.h and implement function get_direction() to avoid duplicated code. We use these functions for RDHR and Gausian Ball Walk and first random point in convex polytope.
…r max nuber of iterations and tolerance in gaussian_samplers.h and gaussian_annealing.h header files.
…an(), we have moved the output arguments at the end of the argument list. We change all not returning functions to void in gaussian_annealing.h and in gaussian_samplers.h. We add comments for the variable k in get_next_gaussian and iterators for the fn vector. We have renamed its to iterators. We change rand_exp_range_coord() to return a double.
… Add to Rcpp interface the choice to run CV algo.
…for the CV algo. The new pdf is in doc folder.
…for CV algo in volumeCV_test.cpp. We have passed succesfully the test locally
…t_coord_point() to compute first gaussian point, overriding is not needed.
… set error=0.2 and number of experiments=20 in the CV volume test. We passed the test succesfully locally.
…ith eigen matrix in Vpolytope class. Use template number type in VPolytope class.
…tope by a point c. Create function linear_transformIt() for both H and V polytopes, to apply a linear transformation to the polytope. We use these functions to the main rounding functionin order to use the latter for Vpolytopes as well. We replace all the shiftings in CV algorithm with the function shift().
…turns the distances between the chebychev center and the facets. In Vpolytope it computes an upper bound for the number of facets (number of d-1-faces of the cyclic polytope) and for each facet returns the radius of the chebychev ball as lower bound for the distance, so we can compute an upper bound for the a_0 of the first gaussian. CV algo can now be used for the volume approximation of v polytopes.We add boolean deltaset to var_g to be able to set the radius of the ball walk when the a_i changes (that was a bug that is fixed).
…olytope returns false and V polytope returns its vertices if num_of_vertices<20*dimension. We modified rotating() function to use linear_transformIt() polytope's function, now we can rotate a V polytope as well.
…lytope classes. We remove Init(int d) and constructor with argument int d in V polytope. We create upper_bound_of_hyperplanes in V polytope class. We change input and output number type to NT in factorial function, because of overflow.
…g double. In main file we have to incluse the disearable header file. Fix some bugs for the template number types in vol.cpp and in struct var_g in volume.h. We define const boolean using_float because we use it in get_first_gaussian() function, to guarantee convergence: If float is used we set tol=1e-06 otherwise we set it 1e-07.
…end of solve_LP() function that computes the chebychev center of a H-polytope. We add some comments in samplers.h and use NT number type where it is not able to use a tamplate.
…ve to give the path to the ext file and a flag Vpoly=TRUE.
…rtices of a V-polytope as an input. Remove variable telescopic product from volesti and set initial volume equl to the volume of the chebychev ball to avoid overflow in some cases (in each iteration we multiply vol with the current ratio).
@vissarion vissarion self-requested a review September 11, 2019 13:51
Copy link
Member

@vissarion vissarion left a comment

Choose a reason for hiding this comment

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

Thanks for this PR, it seems that (at least some versions of) the new random walks are very promising. However, the code needs more work, so looking forward to your feedback. Please explain for which walks you add an R interface and why. Also you say the new volume algorithm is faster, please include here few simple runs for illustration. Finally, tests and docs and comments on the code regarding references of the implemented algorithms.

@@ -10,6 +10,7 @@
#include <Rcpp.h>
#include <RcppEigen.h>
#include <chrono>
#define VOLESTI_DEBUG
Copy link
Member

Choose a reason for hiding this comment

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

Should this be removed?

@@ -101,7 +104,8 @@ Rcpp::NumericMatrix sample_points(Rcpp::Nullable<Rcpp::Reference> P = R_NilValue

int type, dim, numpoints;
NT radius = 1.0, delta = -1.0;
bool set_mean_point = false, cdhr = true, rdhr = false, ball_walk = false, gaussian = false;
bool set_mean_point = false, cdhr = false, rdhr = false, ball_walk = false, gaussian = false, gibbs = false,
Copy link
Member

Choose a reason for hiding this comment

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

Similar to other PR's please change this to use enums instead of many bool vars.

Copy link
Member

Choose a reason for hiding this comment

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

see e.g. #39

rdhr = true;
ball_walk = false;
} else if (Rcpp::as<std::string>(WalkType).compare(std::string("HMC"))==0) {
if (type != 1) throw Rcpp::exception("HMC can be applies only to H-polytopes!");
Copy link
Member

Choose a reason for hiding this comment

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

"can be applied ..."

@@ -239,6 +248,7 @@ Rcpp::NumericMatrix sample_points(Rcpp::Nullable<Rcpp::Reference> P = R_NilValue
InnerBall = HP.ComputeInnerBall();
if (!set_mean_point) MeanPoint = InnerBall.first;
}
//if (hmc_barrier && !gaussian) a = 1.0/NT(Rcpp::as<MT>(Rcpp::as<Rcpp::Reference>(P).field("A")).rows());
Copy link
Member

Choose a reason for hiding this comment

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

is this needed?

@@ -419,6 +419,7 @@ class HPolytope{
bool get_points_for_rounding (T &randPoints) {
return false;
}

Copy link
Member

Choose a reason for hiding this comment

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

are those new lines needed or made by mistake by some IDE?

@@ -327,4 +346,47 @@ void gaussian_ball_walk(Point &p,
}
}

/*
Copy link
Member

Choose a reason for hiding this comment

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

is this needed?

@@ -0,0 +1,112 @@
// VolEsti (volume computation and sampling library)
Copy link
Member

Choose a reason for hiding this comment

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

I propose to use a less cryptic name for the file i.e. sampler instead of sam, what is heur stands for?

@@ -0,0 +1,164 @@
// VolEsti (volume computation and sampling library)
Copy link
Member

Choose a reason for hiding this comment

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

filename, hmc_reflections.h ?


// Licensed under GNU LGPL.3, see LICENCE file

#ifndef HMC_REFL_H
Copy link
Member

Choose a reason for hiding this comment

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

also please update those wrt the filename

@@ -0,0 +1,167 @@
// VolEsti (volume computation and sampling library)
Copy link
Member

Choose a reason for hiding this comment

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

filename. rk4 ?!

@vissarion
Copy link
Member

Parts of this PR appear in #142 and #144

@vissarion vissarion closed this Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants