Skip to content

Commit

Permalink
Enhanced examples sequence and Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vgnecula committed Jul 2, 2024
1 parent 4ab4922 commit b23efbc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 77 deletions.
32 changes: 24 additions & 8 deletions examples/crhmc_cooling_gaussians/volume_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,41 @@
typedef double NT;
typedef Cartesian<NT> Kernel;
typedef typename Kernel::Point Point;
typedef BoostRandomNumberGenerator<boost::mt19937, NT, 3> RNGType;
typedef BoostRandomNumberGenerator<boost::mt11213b, double> RandomNumberGenerator;
typedef HPolytope<Point> HPOLYTOPE;

template <int simdLen>
void calculateAndVerifyVolume(HPOLYTOPE& polytope) {
int walk_len = 100;
NT e = 0.1;

NT volume = volume_cooling_gaussians<CRHMCWalk, RNGType, HPOLYTOPE, 4>(polytope, e, walk_len);
RandomNumberGenerator rng(polytope.dimension());

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

std::cout << "Volume " << volume << std::endl;
}

int main() {

HPOLYTOPE HP = generate_simplex<HPOLYTOPE>(2,false);
std::cout << "HPoly: " << std::endl;
HP.print();
calculateAndVerifyVolume<4>(HP);

HPOLYTOPE simplex = generate_simplex<HPOLYTOPE>(2, false);
std::cout << std::endl << "Simplex: " << std::endl;
simplex.print();
calculateAndVerifyVolume(simplex);

HPOLYTOPE cube = generate_cube<HPOLYTOPE>(3, false);
std::cout << std::endl << "Cube: " << std::endl;
cube.print();
calculateAndVerifyVolume(cube);

HPOLYTOPE cross = generate_cross<HPOLYTOPE>(3, false);
std::cout << std::endl << "Cross: " << std::endl;
cross.print();
calculateAndVerifyVolume(cross);

HPOLYTOPE birkhoff = generate_birkhoff<HPOLYTOPE>(3);
std::cout << std::endl << "Birkhoff: " << std::endl;
birkhoff.print();
calculateAndVerifyVolume(birkhoff);

return 0;
}
72 changes: 3 additions & 69 deletions include/volume/volume_cooling_gaussians_crhmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "random_walks/gaussian_cdhr_walk.hpp"
#include "sampling/random_point_generators.hpp"
#include "volume/math_helpers.hpp"
#include "random_walks/random_walks.hpp"

//new include for crhmc
#include "Eigen/Eigen"
Expand Down Expand Up @@ -53,28 +54,6 @@ using RNG = BoostRandomNumberGenerator<boost::mt19937, NT>;
using Input = crhmc_input<MT, Point, Func, Grad, Hess>;
using CrhmcProblem = crhmc_problem<Point, Input>;


/////////////////// Helpers for random walks

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);
}
};


////////////////////////////// Algorithms

// Gaussian Anealling
Expand Down Expand Up @@ -298,11 +277,6 @@ void compute_annealing_schedule(Polytope& P,
//create the walk object for this problem
WalkType walk = WalkType(problem, p, input.df, input.f, params);

//TODO: test update delta here?
update_delta<WalkType>
::apply(walk, 4.0 * chebychev_radius
/ std::sqrt(std::max(NT(1.0), a_vals[it]) * NT(n)));

// Compute the next gaussian
NT next_a = get_next_gaussian<WalkType, walk_params, RandomPointGenerator, simdLen>
(P, p, a_vals[it], N, ratio, C, walk_length, rng, g, f, params, problem, walk);
Expand Down Expand Up @@ -369,10 +343,10 @@ struct gaussian_annealing_parameters

template
<
typename WalkTypePolicy,
typename Polytope,
typename RandomNumberGenerator,
int simdLen
typename WalkTypePolicy = CRHMCWalk,
int simdLen = 8
>
double volume_cooling_gaussians(Polytope& Pin,
RandomNumberGenerator& rng,
Expand Down Expand Up @@ -515,11 +489,6 @@ double volume_cooling_gaussians(Polytope& Pin,

WalkType walk = WalkType(problem, p, input.df, input.f, params);


update_delta<WalkType>
::apply(walk, 4.0 * radius
/ std::sqrt(std::max(NT(1.0), *avalsIt) * NT(n)));

while (!done || (*itsIt)<min_steps)
{
walk.template apply(rng, walk_length);
Expand Down Expand Up @@ -578,39 +547,4 @@ double volume_cooling_gaussians(Polytope& Pin,
return vol;
}


template
<
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);
}

#endif // VOLUME_COOLING_GAUSSIANS_HPP

0 comments on commit b23efbc

Please sign in to comment.