Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/crhmc_cooling_gaussians' into cr…
Browse files Browse the repository at this point in the history
…hmc_cooling_gaussians
  • Loading branch information
vgnecula committed Jul 18, 2024
2 parents 3b77488 + e7aedc4 commit eaca7fc
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ else ()
add_compile_definitions("EIGEN_NO_DEBUG")
endif ()

add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17")
add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler
#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl")
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm")
Expand Down
1 change: 0 additions & 1 deletion examples/crhmc_prepare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ endif ()


#add_definitions(${CMAKE_CXX_FLAGS} "-g") # enable debuger
add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard
set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING")
add_definitions(${CMAKE_CXX_FLAGS} "-O3 " ${ADDITIONAL_FLAGS}) # optimization of the compiler
#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl")
Expand Down
1 change: 0 additions & 1 deletion examples/hpolytope-volume/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ include_directories (BEFORE ../../include/nlp_oracles)
include_directories (BEFORE ../../include/misc)
include_directories (BEFORE ../../include/optimization)

add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17")
add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm")
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl")
Expand Down
1 change: 0 additions & 1 deletion examples/vpolytope-volume/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ else ()
add_compile_definitions("EIGEN_NO_DEBUG")
endif ()

add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17")
add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler
#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl")
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm")
Expand Down
4 changes: 2 additions & 2 deletions include/preprocess/estimate_L_smooth_parameter.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// VolEsti (volume computation and sampling library)

// Copyright (c) 2012-2024 Vissarion Fisikopoulos
// Copyright (c) 2018-2024 Apostolos Chalkis
// Copyright (c) 2012-2020 Vissarion Fisikopoulos
// Copyright (c) 2018-2020 Apostolos Chalkis

//Contributed and/or modified by Alexandros Manochis, as part of Google Summer of Code 2020 program.

Expand Down
37 changes: 5 additions & 32 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,13 @@ add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_
add_test(NAME volume_cb_vpoly_intersection_vpoly_random_vpoly_sphere
COMMAND volume_cb_vpoly_intersection_vpoly -tc=random_vpoly_sphere)

add_executable (rounding_test rounding_test.cpp $<TARGET_OBJECTS:test_main>)
add_executable (new_rounding_test new_rounding_test.cpp $<TARGET_OBJECTS:test_main>)
add_test(NAME test_round_min_ellipsoid
COMMAND rounding_test -tc=round_min_ellipsoid)
COMMAND new_rounding_test -tc=round_min_ellipsoid)
add_test(NAME test_round_max_ellipsoid
COMMAND rounding_test -tc=round_max_ellipsoid)
COMMAND new_rounding_test -tc=round_max_ellipsoid)
add_test(NAME test_round_svd
COMMAND rounding_test -tc=round_svd)
add_test(NAME test_round_log_barrier_test
COMMAND rounding_test -tc=round_log_barrier_test)
add_test(NAME round_max_ellipsoid_sparse
COMMAND rounding_test -tc=round_max_ellipsoid_sparse)
add_test(NAME round_volumetric_barrier_test
COMMAND rounding_test -tc=round_volumetric_barrier_test)
add_test(NAME round_vaidya_barrier_test
COMMAND rounding_test -tc=round_vaidya_barrier_test)


COMMAND new_rounding_test -tc=round_svd)

add_executable (logconcave_sampling_test logconcave_sampling_test.cpp $<TARGET_OBJECTS:test_main>)
add_test(NAME logconcave_sampling_test_hmc
Expand Down Expand Up @@ -358,22 +348,6 @@ add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr
add_test(NAME test_new_billiard_uniform_MT COMMAND matrix_sampling_test -tc=new_billiard_uniform_MT)
add_test(NAME test_new_accelerated_billiard_uniform_MT COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform_MT)

add_executable (test_internal_points test_internal_points.cpp $<TARGET_OBJECTS:test_main>)
add_test(NAME test_max_ball
COMMAND test_internal_points -tc=test_max_ball)
add_test(NAME test_feasibility_point
COMMAND test_internal_points -tc=test_feasibility_point)
add_test(NAME test_analytic_center
COMMAND test_internal_points -tc=test_analytic_center)
add_test(NAME test_max_ball_sparse
COMMAND test_internal_points -tc=test_max_ball_sparse)
add_test(NAME test_volumetric_center
COMMAND test_internal_points -tc=test_volumetric_center)
add_test(NAME test_vaidya_center
COMMAND test_internal_points -tc=test_vaidya_center)



set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING")

#set_target_properties(benchmarks_crhmc
Expand All @@ -396,7 +370,7 @@ TARGET_LINK_LIBRARIES(volume_cb_vpolytope lp_solve coverage_config)
TARGET_LINK_LIBRARIES(volume_cb_zonotopes lp_solve coverage_config)
TARGET_LINK_LIBRARIES(volume_cb_vpoly_intersection_vpoly lp_solve coverage_config)
TARGET_LINK_LIBRARIES(volume_cb_vpoly_intersection_vpoly lp_solve ${MKL_LINK} coverage_config)
TARGET_LINK_LIBRARIES(rounding_test lp_solve ${MKL_LINK} coverage_config)
TARGET_LINK_LIBRARIES(new_rounding_test lp_solve ${MKL_LINK} coverage_config)
TARGET_LINK_LIBRARIES(mcmc_diagnostics_test lp_solve ${MKL_LINK} coverage_config)
TARGET_LINK_LIBRARIES(sampling_test lp_solve ${MKL_LINK} coverage_config)
TARGET_LINK_LIBRARIES(mmcs_test lp_solve ${MKL_LINK} coverage_config)
Expand All @@ -414,4 +388,3 @@ TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT}
TARGET_LINK_LIBRARIES(crhmc_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config)
TARGET_LINK_LIBRARIES(order_polytope lp_solve coverage_config)
TARGET_LINK_LIBRARIES(matrix_sampling_test lp_solve ${MKL_LINK} coverage_config)
TARGET_LINK_LIBRARIES(test_internal_points lp_solve ${MKL_LINK} coverage_config)
215 changes: 215 additions & 0 deletions test/new_rounding_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// VolEsti (volume computation and sampling library)

// Copyright (c) 2012-2020 Vissarion Fisikopoulos
// Copyright (c) 2018 Apostolos Chalkis

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

#include "doctest.h"
#include <fstream>
#include <iostream>

#include <boost/random.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/uniform_real_distribution.hpp>

#include "misc/misc.h"
#include "random_walks/random_walks.hpp"

#include "volume/volume_sequence_of_balls.hpp"
#include "volume/volume_cooling_gaussians.hpp"
#include "volume/volume_cooling_balls.hpp"

#include "preprocess/min_sampling_covering_ellipsoid_rounding.hpp"
#include "preprocess/max_inscribed_ellipsoid_rounding.hpp"
#include "preprocess/svd_rounding.hpp"

#include "generators/known_polytope_generators.h"

template <typename NT>
NT factorial(NT n)
{
return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}

template <typename NT>
void test_values(NT volume, NT expected, NT exact)
{
std::cout << "Computed volume " << volume << std::endl;
std::cout << "Expected volume = " << expected << std::endl;
std::cout << "Relative error (expected) = "
<< std::abs((volume-expected)/expected) << std::endl;
std::cout << "Relative error (exact) = "
<< std::abs((volume-exact)/exact) << std::endl;
CHECK((std::abs((volume - exact)/exact) < 0.2 ||
std::abs((volume - expected)/expected) < 0.00001));
}

template <class Polytope>
void rounding_min_ellipsoid_test(Polytope &HP,
double const& expectedBall,
double const& expectedCDHR,
double const& expectedRDHR,
double const& expectedBilliard,
double const& exact)
{
typedef typename Polytope::PointType Point;
typedef typename Point::FT NT;
typedef typename Polytope::MT MT;
typedef typename Polytope::VT VT;

int d = HP.dimension();

typedef BoostRandomNumberGenerator<boost::mt19937, NT, 5> RNGType;
RNGType rng(d);

std::pair<Point, NT> InnerBall = HP.ComputeInnerBall();
std::tuple<MT, VT, NT> res = min_sampling_covering_ellipsoid_rounding<CDHRWalk, MT, VT>(HP, InnerBall,
10 + 10 * d, rng);

// Setup the parameters
int walk_len = 1;
NT e = 0.1;

// Estimate the volume
std::cout << "Number type: " << typeid(NT).name() << std::endl;


//TODO: low accuracy in high dimensions
//NT volume = res.second * volume_cooling_balls<BallWalk, RNGType>(HP, e, walk_len);
//test_values(volume, expectedBall, exact);

NT volume = std::get<2>(res) * volume_cooling_balls<CDHRWalk, RNGType>(HP, e, walk_len).second;
test_values(volume, expectedCDHR, exact);

volume = std::get<2>(res) * volume_cooling_balls<RDHRWalk, RNGType>(HP, e, 2*walk_len).second;
test_values(volume, expectedRDHR, exact);

volume = std::get<2>(res) * volume_cooling_balls<BilliardWalk, RNGType>(HP, e, walk_len).second;
test_values(volume, expectedBilliard, exact);
}


template <class Polytope>
void rounding_max_ellipsoid_test(Polytope &HP,
double const& expectedBall,
double const& expectedCDHR,
double const& expectedRDHR,
double const& expectedBilliard,
double const& exact)
{
typedef typename Polytope::PointType Point;
typedef typename Point::FT NT;
typedef typename Polytope::MT MT;
typedef typename Polytope::VT VT;

int d = HP.dimension();

typedef BoostRandomNumberGenerator<boost::mt19937, NT, 5> RNGType;
RNGType rng(d);

std::pair<Point, NT> InnerBall = HP.ComputeInnerBall();
std::tuple<MT, VT, NT> res = max_inscribed_ellipsoid_rounding<MT, VT, NT>(HP, InnerBall.first);

// Setup the parameters
int walk_len = 1;
NT e = 0.1;

// Estimate the volume
std::cout << "Number type: " << typeid(NT).name() << std::endl;

NT volume = std::get<2>(res) * volume_cooling_balls<BilliardWalk, RNGType>(HP, e, walk_len).second;
test_values(volume, expectedBilliard, exact);
}


template <class Polytope>
void rounding_svd_test(Polytope &HP,
double const& expectedBall,
double const& expectedCDHR,
double const& expectedRDHR,
double const& expectedBilliard,
double const& exact)
{
typedef typename Polytope::PointType Point;
typedef typename Point::FT NT;
typedef typename Polytope::MT MT;
typedef typename Polytope::VT VT;

int d = HP.dimension();

typedef BoostRandomNumberGenerator<boost::mt19937, NT, 5> RNGType;
RNGType rng(d);

std::pair<Point, NT> InnerBall = HP.ComputeInnerBall();
std::tuple<MT, VT, NT> res = svd_rounding<CDHRWalk, MT, VT>(HP, InnerBall, 10 + 10 * d, rng);

// Setup the parameters
int walk_len = 1;
NT e = 0.1;

// Estimate the volume
std::cout << "Number type: " << typeid(NT).name() << std::endl;

NT volume = std::get<2>(res) * volume_cooling_balls<BilliardWalk, RNGType>(HP, e, walk_len).second;
test_values(volume, expectedBilliard, exact);
}


template <typename NT>
void call_test_min_ellipsoid() {
typedef Cartesian <NT> Kernel;
typedef typename Kernel::Point Point;
typedef HPolytope <Point> Hpolytope;
Hpolytope P;

std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl;
P = generate_skinny_cube<Hpolytope>(5);
rounding_min_ellipsoid_test(P, 0, 3070.64, 3188.25, 3140.6, 3200.0);

std::cout << "\n--- Testing rounding of H-skinny_cube10" << std::endl;

P = generate_skinny_cube<Hpolytope>(10);
rounding_min_ellipsoid_test(P, 0, 122550, 108426, 105003.0, 102400.0);
}


template <typename NT>
void call_test_max_ellipsoid() {
typedef Cartesian <NT> Kernel;
typedef typename Kernel::Point Point;
typedef HPolytope <Point> Hpolytope;
Hpolytope P;

std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl;
P = generate_skinny_cube<Hpolytope>(5);
rounding_max_ellipsoid_test(P, 0, 3070.64, 3188.25, 3140.6, 3200.0);
}


template <typename NT>
void call_test_svd() {
typedef Cartesian <NT> Kernel;
typedef typename Kernel::Point Point;
typedef HPolytope <Point> Hpolytope;
Hpolytope P;

std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl;
P = generate_skinny_cube<Hpolytope>(5);
rounding_svd_test(P, 0, 3070.64, 3188.25, 3140.6, 3200.0);
}


TEST_CASE("round_min_ellipsoid") {
call_test_min_ellipsoid<double>();
}

TEST_CASE("round_max_ellipsoid") {
call_test_max_ellipsoid<double>();
}

TEST_CASE("round_svd") {
call_test_svd<double>();
}

0 comments on commit eaca7fc

Please sign in to comment.