diff --git a/examples/count-linear-extensions-using-hpolytope/CMakeLists.txt b/examples/count-linear-extensions-using-hpolytope/CMakeLists.txt index 49f295303..f3e66b634 100644 --- a/examples/count-linear-extensions-using-hpolytope/CMakeLists.txt +++ b/examples/count-linear-extensions-using-hpolytope/CMakeLists.txt @@ -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") diff --git a/examples/crhmc_prepare/CMakeLists.txt b/examples/crhmc_prepare/CMakeLists.txt index 9d99477c2..3575c4a46 100644 --- a/examples/crhmc_prepare/CMakeLists.txt +++ b/examples/crhmc_prepare/CMakeLists.txt @@ -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") diff --git a/examples/hpolytope-volume/CMakeLists.txt b/examples/hpolytope-volume/CMakeLists.txt index ad9bb7e39..eff88889a 100644 --- a/examples/hpolytope-volume/CMakeLists.txt +++ b/examples/hpolytope-volume/CMakeLists.txt @@ -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") diff --git a/examples/vpolytope-volume/CMakeLists.txt b/examples/vpolytope-volume/CMakeLists.txt index 2f7020fb1..e1a0c2576 100644 --- a/examples/vpolytope-volume/CMakeLists.txt +++ b/examples/vpolytope-volume/CMakeLists.txt @@ -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") diff --git a/include/preprocess/estimate_L_smooth_parameter.hpp b/include/preprocess/estimate_L_smooth_parameter.hpp index 180f20947..8f5a1e89c 100644 --- a/include/preprocess/estimate_L_smooth_parameter.hpp +++ b/include/preprocess/estimate_L_smooth_parameter.hpp @@ -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. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 615791148..a3f8f03d1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 $) +add_executable (new_rounding_test new_rounding_test.cpp $) 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 $) add_test(NAME logconcave_sampling_test_hmc @@ -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 $) -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 @@ -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) @@ -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) diff --git a/test/new_rounding_test.cpp b/test/new_rounding_test.cpp new file mode 100644 index 000000000..87c63a32a --- /dev/null +++ b/test/new_rounding_test.cpp @@ -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 +#include + +#include +#include +#include +#include + +#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 +NT factorial(NT n) +{ + return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; +} + +template +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 +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 RNGType; + RNGType rng(d); + + std::pair InnerBall = HP.ComputeInnerBall(); + std::tuple res = min_sampling_covering_ellipsoid_rounding(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(HP, e, walk_len); + //test_values(volume, expectedBall, exact); + + NT volume = std::get<2>(res) * volume_cooling_balls(HP, e, walk_len).second; + test_values(volume, expectedCDHR, exact); + + volume = std::get<2>(res) * volume_cooling_balls(HP, e, 2*walk_len).second; + test_values(volume, expectedRDHR, exact); + + volume = std::get<2>(res) * volume_cooling_balls(HP, e, walk_len).second; + test_values(volume, expectedBilliard, exact); +} + + +template +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 RNGType; + RNGType rng(d); + + std::pair InnerBall = HP.ComputeInnerBall(); + std::tuple res = max_inscribed_ellipsoid_rounding(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(HP, e, walk_len).second; + test_values(volume, expectedBilliard, exact); +} + + +template +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 RNGType; + RNGType rng(d); + + std::pair InnerBall = HP.ComputeInnerBall(); + std::tuple res = svd_rounding(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(HP, e, walk_len).second; + test_values(volume, expectedBilliard, exact); +} + + +template +void call_test_min_ellipsoid() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + Hpolytope P; + + std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl; + P = generate_skinny_cube(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(10); + rounding_min_ellipsoid_test(P, 0, 122550, 108426, 105003.0, 102400.0); +} + + +template +void call_test_max_ellipsoid() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + Hpolytope P; + + std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl; + P = generate_skinny_cube(5); + rounding_max_ellipsoid_test(P, 0, 3070.64, 3188.25, 3140.6, 3200.0); +} + + +template +void call_test_svd() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + Hpolytope P; + + std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl; + P = generate_skinny_cube(5); + rounding_svd_test(P, 0, 3070.64, 3188.25, 3140.6, 3200.0); +} + + +TEST_CASE("round_min_ellipsoid") { + call_test_min_ellipsoid(); +} + +TEST_CASE("round_max_ellipsoid") { + call_test_max_ellipsoid(); +} + +TEST_CASE("round_svd") { + call_test_svd(); +} +