From 911e0304d249bd3171f3304c7341488d37cfef69 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Fri, 21 Jun 2024 16:06:05 -0600 Subject: [PATCH 01/20] generalize rounding loop --- .../sampler.cpp | 19 ++-- .../preprocess/analytic_center_linear_ineq.h | 45 ++++----- include/preprocess/feasible_point.hpp | 32 +++++++ .../preprocess/max_inscribed_ellipsoid.hpp | 8 +- .../max_inscribed_ellipsoid_rounding.hpp | 91 ++++++++++++++++--- test/CMakeLists.txt | 2 + test/new_rounding_test.cpp | 54 ++++++++++- test/test_internal_points.cpp | 2 +- 8 files changed, 199 insertions(+), 54 deletions(-) create mode 100644 include/preprocess/feasible_point.hpp diff --git a/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp b/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp index 22dd6d9e5..6b4c74105 100644 --- a/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp +++ b/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp @@ -73,16 +73,19 @@ void sample_using_gaussian_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned i unsigned int max_iter = 150; NT tol = std::pow(10, -6.0), reg = std::pow(10, -4.0); VT x0 = q.getCoefficients(); - std::pair, bool> inscribed_ellipsoid_res = max_inscribed_ellipsoid(HP.get_mat(), - HP.get_vec(), - x0, - max_iter, - tol, - reg); - if (!inscribed_ellipsoid_res.second) // not converged + MT E; + VT center; + bool converged; + std::tie(E, center, converged) = max_inscribed_ellipsoid(HP.get_mat(), + HP.get_vec(), + x0, + max_iter, + tol, + reg); + if (!converged) // not converged throw std::runtime_error("max_inscribed_ellipsoid not converged"); - MT A_ell = inscribed_ellipsoid_res.first.first.inverse(); + MT A_ell = E; EllipsoidType inscribed_ellipsoid(A_ell); // -------------------------------------------------------------------- diff --git a/include/preprocess/analytic_center_linear_ineq.h b/include/preprocess/analytic_center_linear_ineq.h index c7918635a..a1a032597 100644 --- a/include/preprocess/analytic_center_linear_ineq.h +++ b/include/preprocess/analytic_center_linear_ineq.h @@ -13,6 +13,7 @@ #include #include "max_inscribed_ball.hpp" +#include "feasible_point.hpp" template NT get_max_step(VT const& Ad, VT const& b_Ax) @@ -33,17 +34,8 @@ template void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, VT const& x, VT const& Ax, MT &H, VT &grad, VT &b_Ax) { - const int m = A.rows(); - VT s(m); - b_Ax.noalias() = b - Ax; - NT *s_data = s.data(); - for (int i = 0; i < m; i++) - { - *s_data = NT(1) / b_Ax.coeff(i); - s_data++; - } - + VT s = b_Ax.cwiseInverse(); VT s_sq = s.cwiseProduct(s); // Gradient of the log-barrier function grad.noalias() = A_trans * s; @@ -70,27 +62,20 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, (ii) A boolean variable that declares convergence */ template -std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) +std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, VT const& x0, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) { - VT x; - bool feasibility_only = true, converged; - // Compute a feasible point - std::tie(x, std::ignore, converged) = max_inscribed_ball(A, b, max_iters, 1e-08, feasibility_only); - VT Ax = A * x; - if (!converged || (Ax.array() > b.array()).any()) - { - std::runtime_error("The computation of the analytic center failed."); - } // Initialization + VT x = x0; + VT Ax = A * x; const int n = A.cols(), m = A.rows(); MT H(n, n), A_trans = A.transpose(); VT grad(n), d(n), Ad(m), b_Ax(m), step_d(n), x_prev; NT grad_err, rel_pos_err, rel_pos_err_temp, step; unsigned int iter = 0; - converged = false; + bool converged = false; const NT tol_bnd = NT(0.01); get_hessian_grad_logbarrier(A, A_trans, b, x, Ax, H, grad, b_Ax); @@ -128,7 +113,17 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, } } while (true); - return std::make_tuple(x, converged); + return std::make_tuple(H, x, converged); +} + +template +std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) +{ + VT x0 = compute_feasible_point(A, b); + return analytic_center_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); } #endif diff --git a/include/preprocess/feasible_point.hpp b/include/preprocess/feasible_point.hpp new file mode 100644 index 000000000..82839fe26 --- /dev/null +++ b/include/preprocess/feasible_point.hpp @@ -0,0 +1,32 @@ +// VolEsti (volume computation and sampling library) + +// Copyright (c) 2012-2024 Vissarion Fisikopoulos +// Copyright (c) 2018-2024 Apostolos Chalkis + +// Licensed under GNU LGPL.3, see LICENCE file + + +#ifndef FEASIBLE_POINT_HPP +#define FEASIBLE_POINT_HPP + +#include + +#include "max_inscribed_ball.hpp" + +template +VT compute_feasible_point(MT const& A, VT const& b) +{ + VT x; + bool feasibility_only = true, converged; + unsigned max_iters = 10000; + // Compute a feasible point + std::tie(x, std::ignore, converged) = max_inscribed_ball(A, b, max_iters, 1e-08, feasibility_only); + if (!converged || ((A * x).array() > b.array()).any()) + { + std::runtime_error("The computation of a feasible point failed."); + } + return x; +} + + +#endif diff --git a/include/preprocess/max_inscribed_ellipsoid.hpp b/include/preprocess/max_inscribed_ellipsoid.hpp index 7a0c19a6f..2a824e10f 100644 --- a/include/preprocess/max_inscribed_ellipsoid.hpp +++ b/include/preprocess/max_inscribed_ellipsoid.hpp @@ -40,9 +40,9 @@ // using Custom_MT as to deal with both dense and sparse matrices, MT will be the type of result matrix // TODO: Change the return data structure to std::tuple template -std::pair, bool> max_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0, - unsigned int const& maxiter, - NT const& tol, NT const& reg) +std::tuple max_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0, + unsigned int const& maxiter, + NT const& tol, NT const& reg) { typedef Eigen::DiagonalMatrix Diagonal_MT; @@ -256,7 +256,7 @@ std::pair, bool> max_inscribed_ellipsoid(Custom_MT A, VT b, VT x += x0; } - return std::pair, bool>(std::pair(E2, x), converged); + return std::make_tuple(E2, x, converged); } diff --git a/include/preprocess/max_inscribed_ellipsoid_rounding.hpp b/include/preprocess/max_inscribed_ellipsoid_rounding.hpp index da00a8867..cddbdb3af 100644 --- a/include/preprocess/max_inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/max_inscribed_ellipsoid_rounding.hpp @@ -12,6 +12,54 @@ #define MAX_ELLIPSOID_ROUNDING_HPP #include "max_inscribed_ellipsoid.hpp" +#include "analytic_center_linear_ineq.h" +#include "feasible_point.hpp" + +enum EllipsoidType +{ + MAX_ELLIPSOID = 1, + LOG_BARRIER = 2 +}; + +template +struct inscribed_ellispoid +{ + template + inline static std::tuple + compute(Custom_MT A, VT b, VT const& x0, + unsigned int const& maxiter, + NT const& tol, NT const& reg) + { + std::runtime_error("no roudning method is defined"); + return std::tuple(); + } +}; + +template <> +struct inscribed_ellispoid +{ + template + inline static std::tuple + compute(Custom_MT A, VT b, VT const& x0, + unsigned int const& maxiter, + NT const& tol, NT const& reg) + { + return max_inscribed_ellipsoid(A, b, x0, maxiter, tol, reg); + } +}; + +template <> +struct inscribed_ellispoid +{ + template + inline static std::tuple + compute(Custom_MT const& A, VT const& b, VT const& x0, + unsigned int const& maxiter, + NT const& tol, NT&) + { + return analytic_center_linear_ineq(MT(A), b, x0); + } +}; template < @@ -19,18 +67,34 @@ template typename VT, typename NT, typename Polytope, - typename Point + int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID > std::tuple max_inscribed_ellipsoid_rounding(Polytope &P, - Point const& InnerPoint, unsigned int const max_iterations = 5, NT const max_eig_ratio = NT(6)) { - std::pair, bool> iter_res; - iter_res.second = false; + typedef typename Polytope::PointType Point; + VT x = compute_feasible_point(P.get_mat(), P.get_vec()); + return max_inscribed_ellipsoid_rounding(P, Point(x), max_iterations, max_eig_ratio); +} - VT x0 = InnerPoint.getCoefficients(); +template +< + typename MT, + typename VT, + typename NT, + typename Polytope, + typename Point, + int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID +> +std::tuple max_inscribed_ellipsoid_rounding(Polytope &P, + Point const& InnerPoint, + unsigned int const max_iterations = 5, + NT const max_eig_ratio = NT(6)) +{ + VT x0 = InnerPoint.getCoefficients(), center; MT E, L; + bool converged; unsigned int maxiter = 500, iter = 1, d = P.dimension(); NT R = 100.0, r = 1.0, tol = std::pow(10, -6.0), reg = std::pow(10, -4.0), round_val = 1.0; @@ -41,10 +105,12 @@ std::tuple max_inscribed_ellipsoid_rounding(Polytope &P, while (true) { // compute the largest inscribed ellipsoid in P centered at x0 - iter_res = max_inscribed_ellipsoid(P.get_mat(), P.get_vec(), x0, maxiter, tol, reg); - E = iter_res.first.first; + //std::tie(E, center, converged) = max_inscribed_ellipsoid(P.get_mat(), P.get_vec(), x0, maxiter, tol, reg); + std::tie(E, center, converged) = + inscribed_ellispoid::template compute(P.get_mat(), P.get_vec(), + x0, maxiter, tol, reg); E = (E + E.transpose()) / 2.0; - E = E + MT::Identity(d, d)*std::pow(10, -8.0); //normalize E + E += MT::Identity(d, d)*std::pow(10, -8.0); //normalize E Eigen::LLT lltOfA(E.llt().solve(MT::Identity(E.cols(), E.cols()))); // compute the Cholesky decomposition of E^{-1} L = lltOfA.matrixL(); @@ -69,9 +135,9 @@ std::tuple max_inscribed_ellipsoid_rounding(Polytope &P, } } // shift polytope and apply the linear transformation on P - P.shift(iter_res.first.second); - shift += T * iter_res.first.second; - T = T * L; + P.shift(center); + shift.noalias() += T * center; + T.applyOnTheRight(L); // T = T * L; round_val *= L.transpose().determinant(); P.linear_transformIt(L); @@ -80,7 +146,8 @@ std::tuple max_inscribed_ellipsoid_rounding(Polytope &P, x0 = VT::Zero(d); // check the roundness of the polytope - if(((std::abs(R / r) <= max_eig_ratio && iter_res.second) || iter >= max_iterations)){ + std::cout<<"std::abs(R / r): "<= max_iterations)){ break; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e17848fc6..984c4d312 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -296,6 +296,8 @@ add_test(NAME test_round_max_ellipsoid COMMAND new_rounding_test -tc=round_max_ellipsoid) add_test(NAME test_round_svd COMMAND new_rounding_test -tc=round_svd) +add_test(NAME test_round_log_barrier_test + COMMAND new_rounding_test -tc=round_log_barrier_test) diff --git a/test/new_rounding_test.cpp b/test/new_rounding_test.cpp index ab17ed939..4933d5bb8 100644 --- a/test/new_rounding_test.cpp +++ b/test/new_rounding_test.cpp @@ -111,7 +111,37 @@ void rounding_max_ellipsoid_test(Polytope &HP, 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_log_barrier_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); + max_inscribed_ellipsoid_rounding(HP); // Setup the parameters int walk_len = 1; NT e = 0.1; @@ -164,11 +194,11 @@ void call_test_min_ellipsoid() { typedef HPolytope Hpolytope; Hpolytope P; - std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl; + std::cout << "\n--- Testing min ellipsoid 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; + std::cout << "\n--- Testing min ellipsoid rounding of H-skinny_cube10" << std::endl; P = generate_skinny_cube(10); rounding_min_ellipsoid_test(P, 0, 122550, 108426, 105003.0, 102400.0); @@ -182,11 +212,23 @@ void call_test_max_ellipsoid() { typedef HPolytope Hpolytope; Hpolytope P; - std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl; + std::cout << "\n--- Testing max ellipsoid rounding of H-skinny_cube5" << std::endl; P = generate_skinny_cube(5); rounding_max_ellipsoid_test(P, 0, 3070.64, 3188.25, 3262.61, 3200.0); } +template +void call_test_log_barrier() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + Hpolytope P; + + std::cout << "\n--- Testing log-barrier rounding of H-skinny_cube5" << std::endl; + P = generate_skinny_cube(5); + rounding_log_barrier_test(P, 0, 3070.64, 3188.25, 3262.77, 3200.0); +} + template void call_test_svd() { @@ -195,7 +237,7 @@ void call_test_svd() { typedef HPolytope Hpolytope; Hpolytope P; - std::cout << "\n--- Testing rounding of H-skinny_cube5" << std::endl; + std::cout << "\n--- Testing SVD 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); } @@ -209,6 +251,10 @@ TEST_CASE("round_max_ellipsoid") { call_test_max_ellipsoid(); } +TEST_CASE("round_log_barrier_test") { + call_test_log_barrier(); +} + TEST_CASE("round_svd") { call_test_svd(); } diff --git a/test/test_internal_points.cpp b/test/test_internal_points.cpp index fa44e9baf..067c95c77 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -85,7 +85,7 @@ void call_test_analytic_center() { P = skinny_random_hpoly(3, 15, pre_rounding, max_min_eig_ratio, 127); P.normalize(); - auto [analytic_center, converged] = analytic_center_linear_ineq(P.get_mat(), P.get_vec()); + auto [Hessian, analytic_center, converged] = analytic_center_linear_ineq(P.get_mat(), P.get_vec()); CHECK(P.is_in(Point(analytic_center)) == -1); CHECK(converged); From 85b1faf288d864ad2cfa36fc009aee861dbee210 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Fri, 21 Jun 2024 17:45:28 -0600 Subject: [PATCH 02/20] support sparse cholesky operator --- .../preprocess/analytic_center_linear_ineq.h | 76 +++++++++++++++---- .../max_inscribed_ellipsoid_rounding.hpp | 2 +- test/new_rounding_test.cpp | 1 - test/test_internal_points.cpp | 14 +++- 4 files changed, 75 insertions(+), 18 deletions(-) diff --git a/include/preprocess/analytic_center_linear_ineq.h b/include/preprocess/analytic_center_linear_ineq.h index a1a032597..0a1c73dcc 100644 --- a/include/preprocess/analytic_center_linear_ineq.h +++ b/include/preprocess/analytic_center_linear_ineq.h @@ -40,9 +40,53 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, // Gradient of the log-barrier function grad.noalias() = A_trans * s; // Hessian of the log-barrier function - H.noalias() = A_trans * s_sq.asDiagonal() * A; + H = A_trans * s_sq.asDiagonal() * A; } +template +struct cholesky_operator +{ + inline static std::unique_ptr> + initialize(MT const&) + { + return std::unique_ptr>(new Eigen::LLT()); + } + + template + inline static VT solve(std::unique_ptr> const& lltmat, MT const& H, VT const& b) + { + lltmat->compute(H); + return lltmat->solve(b); + } + + /* + TODO: update_hessian_Atrans_D_A() + */ +}; + +template +struct cholesky_operator> +{ + inline static std::unique_ptr>> + initialize(Eigen::SparseMatrix const& mat) + { + std::unique_ptr>> lltmat = std::unique_ptr>>(new Eigen::SimplicialLLT>()); + lltmat->analyzePattern(mat); + return lltmat; + } + + template + inline static VT solve(std::unique_ptr>> const& lltmat, Eigen::SparseMatrix const& H, VT const& b) + { + lltmat->factorize(H); + return lltmat->solve(b); + } + + /* + TODO: update_hessian_Atrans_D_A() + */ +}; + /* This implementation computes the analytic center of a polytope given as a set of linear inequalities P = {x | Ax <= b}. The analytic center @@ -61,11 +105,11 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, Output: (i) The analytic center of the polytope (ii) A boolean variable that declares convergence */ -template -std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, VT const& x0, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) +template +std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, VT const& x0, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) { // Initialization VT x = x0; @@ -78,12 +122,14 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, bool converged = false; const NT tol_bnd = NT(0.01); + auto lltmat = cholesky_operator::initialize(A_trans*A); + get_hessian_grad_logbarrier(A, A_trans, b, x, Ax, H, grad, b_Ax); do { iter++; // Compute the direction - d.noalias() = - H.llt().solve(grad); + d.noalias() = - cholesky_operator::solve(lltmat, H, grad); Ad.noalias() = A * d; // Compute the step length step = std::min((NT(1) - tol_bnd) * get_max_step(Ad, b_Ax), NT(1)); @@ -113,17 +159,17 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, } } while (true); - return std::make_tuple(H, x, converged); + return std::make_tuple(MT_dense(H), x, converged); } -template -std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) +template +std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) { - VT x0 = compute_feasible_point(A, b); - return analytic_center_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); + VT x0 = compute_feasible_point(MT_dense(A), b); + return analytic_center_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); } #endif diff --git a/include/preprocess/max_inscribed_ellipsoid_rounding.hpp b/include/preprocess/max_inscribed_ellipsoid_rounding.hpp index cddbdb3af..e2a43f988 100644 --- a/include/preprocess/max_inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/max_inscribed_ellipsoid_rounding.hpp @@ -57,7 +57,7 @@ struct inscribed_ellispoid unsigned int const& maxiter, NT const& tol, NT&) { - return analytic_center_linear_ineq(MT(A), b, x0); + return analytic_center_linear_ineq(A, b, x0); } }; diff --git a/test/new_rounding_test.cpp b/test/new_rounding_test.cpp index 4933d5bb8..01e2010ed 100644 --- a/test/new_rounding_test.cpp +++ b/test/new_rounding_test.cpp @@ -141,7 +141,6 @@ void rounding_log_barrier_test(Polytope &HP, RNGType rng(d); std::pair InnerBall = HP.ComputeInnerBall(); std::tuple res = max_inscribed_ellipsoid_rounding(HP, InnerBall.first); - max_inscribed_ellipsoid_rounding(HP); // Setup the parameters int walk_len = 1; NT e = 0.1; diff --git a/test/test_internal_points.cpp b/test/test_internal_points.cpp index 067c95c77..ec1fe2e49 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -77,6 +77,7 @@ void call_test_analytic_center() { typedef typename Hpolytope::MT MT; typedef typename Hpolytope::VT VT; typedef boost::mt19937 PolyRNGType; + typedef Eigen::SparseMatrix SpMT; Hpolytope P; std::cout << "\n--- Testing analytic center for skinny H-polytope" << std::endl; @@ -85,13 +86,24 @@ void call_test_analytic_center() { P = skinny_random_hpoly(3, 15, pre_rounding, max_min_eig_ratio, 127); P.normalize(); - auto [Hessian, analytic_center, converged] = analytic_center_linear_ineq(P.get_mat(), P.get_vec()); + auto [Hessian, analytic_center, converged] = analytic_center_linear_ineq(P.get_mat(), P.get_vec()); + SpMT Asp = P.get_mat().sparseView(); + auto [Hessian_sp, analytic_center2, converged2] = analytic_center_linear_ineq(Asp, P.get_vec()); + CHECK(P.is_in(Point(analytic_center)) == -1); CHECK(converged); CHECK(std::abs(analytic_center(0) + 4.75912) < 1e-04); CHECK(std::abs(analytic_center(1) + 4.28762) < 1e-04); CHECK(std::abs(analytic_center(2) - 7.54156) < 1e-04); + + CHECK(P.is_in(Point(analytic_center2)) == -1); + CHECK(converged2); + CHECK(std::abs(analytic_center(0) - analytic_center2(0)) < 1e-12); + CHECK(std::abs(analytic_center(1) - analytic_center2(1)) < 1e-12); + CHECK(std::abs(analytic_center(2) - analytic_center2(2)) < 1e-12); + + CHECK((Hessian - Hessian_sp).norm() < 1e-12); } TEST_CASE("test_max_ball") { From b3f75ba9a8e22460225e612dcaba1e713034ee3c Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Sun, 23 Jun 2024 22:26:32 -0600 Subject: [PATCH 03/20] complete sparse support in max_inscribed_ball --- .../preprocess/analytic_center_linear_ineq.h | 53 +-- include/preprocess/cholesky_opoerator.h | 161 +++++++ include/preprocess/max_inscribed_ball.hpp | 43 +- test/CMakeLists.txt | 218 +--------- test/CMakeLists_2.txt | 403 ++++++++++++++++++ test/test_internal_points.cpp | 57 ++- 6 files changed, 672 insertions(+), 263 deletions(-) create mode 100644 include/preprocess/cholesky_opoerator.h create mode 100644 test/CMakeLists_2.txt diff --git a/include/preprocess/analytic_center_linear_ineq.h b/include/preprocess/analytic_center_linear_ineq.h index 0a1c73dcc..657d054cd 100644 --- a/include/preprocess/analytic_center_linear_ineq.h +++ b/include/preprocess/analytic_center_linear_ineq.h @@ -14,6 +14,7 @@ #include "max_inscribed_ball.hpp" #include "feasible_point.hpp" +#include "cholesky_opoerator.h" template NT get_max_step(VT const& Ad, VT const& b_Ax) @@ -40,53 +41,9 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, // Gradient of the log-barrier function grad.noalias() = A_trans * s; // Hessian of the log-barrier function - H = A_trans * s_sq.asDiagonal() * A; + cholesky_operator::update_hessian_Atrans_D_A(H, A_trans, A, s_sq.asDiagonal()); } -template -struct cholesky_operator -{ - inline static std::unique_ptr> - initialize(MT const&) - { - return std::unique_ptr>(new Eigen::LLT()); - } - - template - inline static VT solve(std::unique_ptr> const& lltmat, MT const& H, VT const& b) - { - lltmat->compute(H); - return lltmat->solve(b); - } - - /* - TODO: update_hessian_Atrans_D_A() - */ -}; - -template -struct cholesky_operator> -{ - inline static std::unique_ptr>> - initialize(Eigen::SparseMatrix const& mat) - { - std::unique_ptr>> lltmat = std::unique_ptr>>(new Eigen::SimplicialLLT>()); - lltmat->analyzePattern(mat); - return lltmat; - } - - template - inline static VT solve(std::unique_ptr>> const& lltmat, Eigen::SparseMatrix const& H, VT const& b) - { - lltmat->factorize(H); - return lltmat->solve(b); - } - - /* - TODO: update_hessian_Atrans_D_A() - */ -}; - /* This implementation computes the analytic center of a polytope given as a set of linear inequalities P = {x | Ax <= b}. The analytic center @@ -122,14 +79,14 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT cons bool converged = false; const NT tol_bnd = NT(0.01); - auto lltmat = cholesky_operator::initialize(A_trans*A); + auto llt = cholesky_operator::initialize(A_trans*A); get_hessian_grad_logbarrier(A, A_trans, b, x, Ax, H, grad, b_Ax); do { iter++; // Compute the direction - d.noalias() = - cholesky_operator::solve(lltmat, H, grad); + d.noalias() = - cholesky_operator::solve(llt, H, grad); Ad.noalias() = A * d; // Compute the step length step = std::min((NT(1) - tol_bnd) * get_max_step(Ad, b_Ax), NT(1)); @@ -168,7 +125,7 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT cons NT const grad_err_tol = 1e-08, NT const rel_pos_err_tol = 1e-12) { - VT x0 = compute_feasible_point(MT_dense(A), b); + VT x0 = compute_feasible_point(A, b); return analytic_center_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); } diff --git a/include/preprocess/cholesky_opoerator.h b/include/preprocess/cholesky_opoerator.h new file mode 100644 index 000000000..b64f4b42e --- /dev/null +++ b/include/preprocess/cholesky_opoerator.h @@ -0,0 +1,161 @@ +// VolEsti (volume computation and sampling library) + +// Copyright (c) 2024 Vissarion Fisikopoulos +// Copyright (c) 2024 Apostolos Chalkis +// Copyright (c) 2024 Elias Tsigaridas + +// Licensed under GNU LGPL.3, see LICENCE file + + +#ifndef CHOLESKY_OPERATOR_H +#define CHOLESKY_OPERATOR_H + +#include + +template +struct cholesky_operator +{ + inline static std::unique_ptr> + initialize(MT const&) + { + return std::unique_ptr>(new Eigen::LLT()); + } + + template + inline static VT solve(std::unique_ptr> const& llt, MT const& H, VT const& b) + { + llt->compute(H); + return llt->solve(b); + } + + template + inline static void update_hessian_Atrans_D_A(MT &H, MT const& A_trans, MT const& A, diag_MT const& D) + { + H.noalias() = A_trans * D * A; + } + + inline static void init_Bmat(MT &B, int const n, MT const& , MT const& ) + { + B.resize(n+1, n+1); + } + + template + inline static void update_Bmat(MT &B, VT const& AtDe, VT const& d, MT const& AtD, MT const& A) + { + const int n = A.cols(); + B.block(0, 0, n, n).noalias() = AtD * A; + B.block(0, n, n, 1).noalias() = AtDe; + B.block(n, 0, 1, n).noalias() = AtDe.transpose(); + B(n, n) = d.sum(); + B.noalias() += 1e-14 * MT::Identity(n + 1, n + 1); + } +}; + +template +struct cholesky_operator> +{ + inline static std::unique_ptr>> + initialize(Eigen::SparseMatrix const& mat) + { + std::unique_ptr>> llt = std::unique_ptr>>(new Eigen::SimplicialLLT>()); + llt->analyzePattern(mat); + return llt; + } + + template + inline static VT solve(std::unique_ptr>> const& llt, Eigen::SparseMatrix const& H, VT const& b) + { + llt->factorize(H); + return llt->solve(b); + } + + template + inline static void update_hessian_Atrans_D_A(Eigen::SparseMatrix &H, Eigen::SparseMatrix const& A_trans, Eigen::SparseMatrix const& A, diag_MT const& D) + { + H = A_trans * D * A; + } + + inline static void init_Bmat(Eigen::SparseMatrix &B, int const n, Eigen::SparseMatrix const& A_trans, Eigen::SparseMatrix const& A) + { + // Initialize the structure of matrix B + typedef Eigen::Triplet triplet; + std::vector trp; + for (int i = 0; i < n; i++) + { + trp.push_back(triplet(i, i, NT(1))); + trp.push_back(triplet(i, n, NT(1))); + trp.push_back(triplet(n, i, NT(1))); + } + trp.push_back(triplet(n, n, NT(1))); + Eigen::SparseMatrix ATA = A_trans * A; + for (int k=0; k::InnerIterator it(ATA,k); it; ++it) + { + if (it.row() == it.col()) continue; + trp.push_back(triplet(it.row(), it.col(), NT(1))); + } + } + B.resize(n+1, n+1); + B.setFromTriplets(trp.begin(), trp.end()); + } + + template + inline static void update_Bmat(Eigen::SparseMatrix &B, VT const& AtDe, VT const& d, Eigen::SparseMatrix const& AtD, Eigen::SparseMatrix const& A) + { + const int n = A.cols(); + Eigen::SparseMatrix AtD_A = AtD * A; + //std::cout<<"B indeces: "<::InnerIterator it1(B,k); + typename Eigen::SparseMatrix::InnerIterator it2(AtD_A,k <= n-1 ? k : k-1); + for (typename Eigen::SparseMatrix::InnerIterator it1(B,k); it1; ++it1) + { + //std::cout<<"row1: "< -void calcstep(MT const& A, MT const& A_trans, Eigen::LLT const& lltOfB, VT &s, - VT &y, VT &r1, VT const& r2, NT const& r3, VT &r4, - VT &dx, VT &ds, NT &dt, VT &dy, VT &tmp, VT &rhs) +template +void calcstep(MT const& A, MT const& A_trans, MT const& B, + llt_type const& llt, VT &s, VT &y, VT &r1, + VT const& r2, NT const& r3, VT &r4, VT &dx, + VT &ds, NT &dt, VT &dy, VT &tmp, VT &rhs) { int m = A.rows(), n = A.cols(); NT *vec_iter1 = tmp.data(), *vec_iter2 = y.data(), *vec_iter3 = s.data(), @@ -42,7 +45,7 @@ void calcstep(MT const& A, MT const& A_trans, Eigen::LLT const& lltOfB, VT & rhs.block(0,0,n,1).noalias() = r2 + A_trans * tmp; rhs(n) = r3 + tmp.sum(); - VT dxdt = lltOfB.solve(rhs); + VT dxdt = cholesky_operator::solve(llt, B, rhs); dx = dxdt.block(0,0,n,1); dt = dxdt(n); @@ -84,9 +87,11 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, NT const tau0 = 0.995, power_num = 5.0 * std::pow(10.0, 15.0); NT *vec_iter1, *vec_iter2, *vec_iter3, *vec_iter4; - MT B(n + 1, n + 1), AtD(n, m), - eEye = std::pow(10.0, -14.0) * MT::Identity(n + 1, n + 1), - A_trans = A.transpose(); + MT B, AtD(n, m), A_trans = A.transpose(); + //MT_dense eEye = std::pow(10.0, -14.0) * MT_dense::Identity(n + 1, n + 1); + + cholesky_operator::init_Bmat(B, n, A_trans, A); + auto llt = cholesky_operator::initialize(B); for (unsigned int i = 0; i < maxiter; ++i) { @@ -135,20 +140,24 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, vec_iter3++; vec_iter2++; } - AtD.noalias() = A_trans*d.asDiagonal(); + AtD = A_trans*d.asDiagonal(); //todo: optimize it in cholesky_operator AtDe.noalias() = AtD * e_m; - B.block(0, 0, n, n).noalias() = AtD * A; - B.block(0, n, n, 1).noalias() = AtDe; - B.block(n, 0, 1, n).noalias() = AtDe.transpose(); - B(n, n) = d.sum(); - B.noalias() += eEye; + //std::cout<<"starting update Bmat..\n"<::update_Bmat(B, AtDe, d, AtD, A); + //exit(-1); + //B.block(0, 0, n, n).noalias() = AtD * A; + //B.block(0, n, n, 1).noalias() = AtDe; + //B.block(n, 0, 1, n).noalias() = AtDe.transpose(); + //B(n, n) = d.sum(); + //B.noalias() += eEye; + //std::cout<<"B:\n"< lltOfB(B); + //Eigen::LLT lltOfB(B); // predictor step & length - calcstep(A, A_trans, lltOfB, s, y, r1, r2, r3, r4, dx, ds, dt, dy, tmp, rhs); + calcstep(A, A_trans, B, llt, s, y, r1, r2, r3, r4, dx, ds, dt, dy, tmp, rhs); alphap = -1.0; alphad = -1.0; @@ -175,7 +184,7 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, // corrector and combined step & length mu_ds_dy.noalias() = e_m * mu - ds.cwiseProduct(dy); - calcstep(A, A_trans, lltOfB, s, y, o_m, o_n, 0.0, mu_ds_dy, dxc, dsc, dtc, dyc, tmp, rhs); + calcstep(A, A_trans, B, llt, s, y, o_m, o_n, 0.0, mu_ds_dy, dxc, dsc, dtc, dyc, tmp, rhs); dx += dxc; ds += dsc; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 984c4d312..babc605ee 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -185,172 +185,24 @@ add_definitions(${CMAKE_CXX_FLAGS} "-DMKL_ILP64") #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") #add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) -add_executable (new_volume_example new_volume_example.cpp) -add_executable (benchmarks_sob benchmarks_sob.cpp) -add_executable (benchmarks_cg benchmarks_cg.cpp) -add_executable (benchmarks_cb benchmarks_cb.cpp) + add_library(test_main OBJECT test_main.cpp) -add_executable (mcmc_diagnostics_test mcmc_diagnostics_test.cpp $) -add_test(NAME test_psrf COMMAND mcmc_diagnostics_test -tc=psrf) -add_test(NAME test_univariate_psrf COMMAND mcmc_diagnostics_test -tc=univariate_psrf) -add_test(NAME test_interval_psrf COMMAND mcmc_diagnostics_test -tc=interval_psrf) -add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess) -add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke) -add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery) - -add_executable (sampling_test sampling_test.cpp $) -add_test(NAME test_dikin COMMAND sampling_test -tc=dikin) -add_test(NAME test_john COMMAND sampling_test -tc=john) -add_test(NAME test_vaidya COMMAND sampling_test -tc=vaidya) -add_test(NAME test_brdhr COMMAND sampling_test -tc=brdhr) -add_test(NAME test_bcdhr COMMAND sampling_test -tc=bcdhr) -add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr) -add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw) -add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc) - -add_executable (mmcs_test mmcs_test.cpp $) -add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs) - -add_executable (ode_solvers_test ode_solvers_test.cpp $) -add_test(NAME ode_solvers_test_first_order - COMMAND ode_solvers_test -tc=first_order) -add_test(NAME ode_solvers_test_second_order - COMMAND ode_solvers_test -tc=second_order) - -add_executable (root_finders_test root_finders_test.cpp $) -add_test(NAME root_finders_test_root_finders - COMMAND root_finders_test -tc=root_finders) - -#add_executable (benchmarks_crhmc benchmarks_crhmc.cpp ) -#add_executable (benchmarks_crhmc_sampling benchmarks_crhmc_sampling.cpp ) - -add_executable (crhmc_polytope_preparation_test crhmc_polytope_preparation_test.cpp $) -add_test(NAME crhmc_polytope_test_preparation - COMMAND crhmc_polytope_preparation_test -tc=test_preparation_crhmc) -add_test(NAME crhmc_test_fixed_vars - COMMAND crhmc_polytope_preparation_test -tc=test_fixed_vars_crhmc) -add_test(NAME crhmc_test_dep_vars - COMMAND crhmc_polytope_preparation_test -tc=test_dep_vars_crhmc) -add_test(NAME crhmc_test_center_computation - COMMAND crhmc_polytope_preparation_test -tc=test_center_computation) - -add_executable (boundary_oracles_test boundary_oracles_test.cpp $) -add_test(NAME boundary_oracles_test_h_poly_oracles - COMMAND boundary_oracles_test -tc=h_poly_oracles) - -add_executable (volume_sob_hpolytope volume_sob_hpolytope.cpp $) -add_test(NAME volume_sob_hpolytope_cube COMMAND volume_sob_hpolytope -tc=cube) -add_test(NAME volume_sob_hpolytope_cross COMMAND volume_sob_hpolytope -tc=cross) -add_test(NAME volume_sob_hpolytope_birkhoff COMMAND volume_sob_hpolytope -tc=birk) -add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) -add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) -add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) -add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) -set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) - -add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) -add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) -add_test(NAME volume_sob_vpolytope_cross COMMAND volume_sob_vpolytope -tc=cross) -add_test(NAME volume_sob_vpolytope_simplex COMMAND volume_sob_vpolytope -tc=simplex) - -add_executable (volume_cg_hpolytope volume_cg_hpolytope.cpp $) -add_test(NAME volume_cg_hpolytope_cube COMMAND volume_cg_hpolytope -tc=cube) -add_test(NAME volume_cg_hpolytope_cross COMMAND volume_cg_hpolytope -tc=cross) -add_test(NAME volume_cg_hpolytope_birkhoff COMMAND volume_cg_hpolytope -tc=birk) -add_test(NAME volume_cg_hpolytope_prod_simplex COMMAND volume_cg_hpolytope -tc=prod_simplex) -add_test(NAME volume_cg_hpolytope_simplex COMMAND volume_cg_hpolytope -tc=simplex) -add_test(NAME volume_cg_hpolytope_skinny_cube COMMAND volume_cg_hpolytope -tc=skinny_cube) - -add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $) -add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube) -add_test(NAME volume_cg_vpolytope_cross COMMAND volume_cg_vpolytope -tc=cross) -add_test(NAME volume_cg_vpolytope_simplex COMMAND volume_cg_vpolytope -tc=simplex) - -add_executable (volume_cb_hpolytope volume_cb_hpolytope.cpp $) -add_test(NAME volume_cb_hpolytope_cube COMMAND volume_cb_hpolytope -tc=cube) -add_test(NAME volume_cb_hpolytope_cross COMMAND volume_cb_hpolytope -tc=cross) -add_test(NAME volume_cb_hpolytope_birkhoff COMMAND volume_cb_hpolytope -tc=birk) -add_test(NAME volume_cb_hpolytope_prod_simplex COMMAND volume_cb_hpolytope -tc=prod_simplex) -add_test(NAME volume_cb_hpolytope_simplex COMMAND volume_cb_hpolytope -tc=simplex) -add_test(NAME volume_cb_hpolytope_skinny_cube COMMAND volume_cb_hpolytope -tc=skinny_cube) - -add_executable (volume_cb_vpolytope volume_cb_vpolytope.cpp $) -add_test(NAME volume_cb_vpolytope_cube COMMAND volume_cb_vpolytope -tc=cube) -add_test(NAME volume_cb_vpolytope_cross COMMAND volume_cb_vpolytope -tc=cross) -add_test(NAME volume_cb_vpolytope_simplex COMMAND volume_cb_vpolytope -tc=simplex) - -add_executable (volume_cb_zonotopes volume_cb_zonotopes.cpp $) -add_test(NAME volume_cb_zonotopes_uniform_zonotopes - COMMAND volume_cb_zonotopes -tc=uniform_zonotopes) - -add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_vpoly.cpp $) -add_test(NAME volume_cb_vpoly_intersection_vpoly_random_vpoly_sphere - COMMAND volume_cb_vpoly_intersection_vpoly -tc=random_vpoly_sphere) - -add_executable (new_rounding_test new_rounding_test.cpp $) -add_test(NAME test_round_min_ellipsoid - COMMAND new_rounding_test -tc=round_min_ellipsoid) -add_test(NAME test_round_max_ellipsoid - COMMAND new_rounding_test -tc=round_max_ellipsoid) -add_test(NAME test_round_svd - COMMAND new_rounding_test -tc=round_svd) -add_test(NAME test_round_log_barrier_test - COMMAND new_rounding_test -tc=round_log_barrier_test) - - - -add_executable (logconcave_sampling_test logconcave_sampling_test.cpp $) -add_test(NAME logconcave_sampling_test_hmc - COMMAND logconcave_sampling_test -tc=hmc) -add_test(NAME logconcave_sampling_test_uld - COMMAND logconcave_sampling_test -tc=uld) -add_test(NAME logconcave_sampling_test_exponential_biomass_sampling - COMMAND logconcave_sampling_test -tc=exponential_biomass_sampling) -add_test(NAME logconcave_sampling_test_nuts_hmc_truncated - COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated) -add_test(NAME logconcave_sampling_test_nuts_hmc - COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc) - - - -add_executable (crhmc_sampling_test crhmc_sampling_test.cpp $) -add_test(NAME crhmc_sampling_test_crhmc - COMMAND crhmc_sampling_test -tc=crhmc) -add_test(NAME crhmc_test_polytope_sampling - COMMAND crhmc_sampling_test -tc=test_polytope_sampling_crhmc) -add_test(NAME crhmc_test_sparse_sampling - COMMAND crhmc_sampling_test -tc=test_sampling_sparse_problem) -add_executable (simple_mc_integration simple_mc_integration.cpp $) -add_test(NAME simple_mc_integration_over_limits - COMMAND simple_mc_integration -tc=rectangle) -add_test(NAME simple_mc_integration_over_cubes - COMMAND simple_mc_integration -tc=cube) -add_test(NAME simple_mc_integration_over_simplices - COMMAND simple_mc_integration -tc=simplex) -add_test(NAME simple_mc_integration_over_product_simplices - COMMAND simple_mc_integration -tc=prod_simplex) -add_test(NAME simple_mc_integration_over_cross_polytopes - COMMAND simple_mc_integration -tc=cross) -add_test(NAME simple_mc_integration_over_birkhoff_polytopes - COMMAND simple_mc_integration -tc=birkhoff) - -add_executable (order_polytope order_polytope.cpp $) -add_test(NAME order_polytope_basics COMMAND order_polytope -tc=basics) -add_test(NAME order_polytope_line_intersect COMMAND order_polytope -tc=line_intersect) -add_test(NAME order_polytope_reflection COMMAND order_polytope -tc=reflection) -add_test(NAME order_polytope_vec_mult COMMAND order_polytope -tc=vec_mult) - -add_executable (matrix_sampling_test sampling_correlation_matrices_test.cpp $) -add_test(NAME test_corre_spectra_classes COMMAND matrix_sampling_test -tc=corre_spectra) -add_test(NAME test_new_ball_uniform COMMAND matrix_sampling_test -tc=new_ball_uniform) -add_test(NAME test_new_billiard_uniform COMMAND matrix_sampling_test -tc=new_billiard_uniform) -add_test(NAME test_new_accelerated_billiard_uniform COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform) -add_test(NAME test_new_ball_uniform_MT COMMAND matrix_sampling_test -tc=new_ball_uniform_MT) -add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr_uniform_MT) -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 (new_rounding_test new_rounding_test.cpp $) +#add_test(NAME test_round_min_ellipsoid +# COMMAND new_rounding_test -tc=round_min_ellipsoid) +#add_test(NAME test_round_max_ellipsoid +# COMMAND new_rounding_test -tc=round_max_ellipsoid) +#add_test(NAME test_round_svd +# COMMAND new_rounding_test -tc=round_svd) +#add_test(NAME test_round_log_barrier_test +# COMMAND new_rounding_test -tc=round_log_barrier_test) + + + add_executable (test_internal_points test_internal_points.cpp $) add_test(NAME test_max_ball @@ -359,6 +211,9 @@ 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) + set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") @@ -366,38 +221,7 @@ set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) #set_target_properties(benchmarks_crhmc_sampling # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -set_target_properties(crhmc_polytope_preparation_test - PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -set_target_properties(crhmc_sampling_test - PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) - -TARGET_LINK_LIBRARIES(new_volume_example lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(new_volume_example lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_sob_hpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_sob_vpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cg_hpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cg_vpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cb_hpolytope lp_solve coverage_config) -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(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) -TARGET_LINK_LIBRARIES(benchmarks_sob lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(benchmarks_cg lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(benchmarks_cb lp_solve ${MKL_LINK} coverage_config) -#TARGET_LINK_LIBRARIES(benchmarks_crhmc_sampling lp_solve ${MKL_LINK} QD_LIB coverage_config) -#TARGET_LINK_LIBRARIES(benchmarks_crhmc lp_solve ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(simple_mc_integration lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(ode_solvers_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(boundary_oracles_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(root_finders_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(crhmc_polytope_preparation_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -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(new_rounding_test lp_solve ${MKL_LINK} coverage_config) TARGET_LINK_LIBRARIES(test_internal_points lp_solve ${MKL_LINK} coverage_config) diff --git a/test/CMakeLists_2.txt b/test/CMakeLists_2.txt new file mode 100644 index 000000000..984c4d312 --- /dev/null +++ b/test/CMakeLists_2.txt @@ -0,0 +1,403 @@ +# VolEsti (volume computation and sampling library) +# Copyright (c) 2012-2020 Vissarion Fisikopoulos +# Copyright (c) 2018-2020 Apostolos Chalkis +# Copyright (c) 2021 Vaibhav Thakkar + +# Contributed and/or modified by Vaibhav Thakkar +# Contributed and/or modified by Ioannis Iakovidis +# Licensed under GNU LGPL.3, see LICENCE file + +project( VolEsti ) + +enable_testing() + +CMAKE_MINIMUM_REQUIRED(VERSION 3.11) + +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + +# Locate Intel MKL root (in case it is enabled) + +if (APPLE) + set(MKLROOT /opt/intel/oneapi/mkl/latest) +elseif(UNIX) + set(MKLROOT /opt/intel/oneapi/mkl/latest) +endif() + + +option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) +option(BUILTIN_EIGEN "Use eigen from ../external" OFF) +option(BUILTIN_AUTODIFF "Use autodiff from ../external" ON) +option(USE_MKL "Use MKL library to build eigen" OFF) + +if(DISABLE_NLP_ORACLES) + add_definitions(-DDISABLE_NLP_ORACLES) +else() + find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) + find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) + find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) + find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + + if (NOT IFOPT) + + message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") + + elseif (NOT GMP) + + message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") + + elseif (NOT MPSOLVE) + + message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") + + elseif (NOT FFTW3) + + message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") + + else() + message(STATUS "Library ifopt found: ${IFOPT}") + message(STATUS "Library gmp found: ${GMP}") + message(STATUS "Library mpsolve found: ${MPSOLVE}") + message(STATUS "Library fftw3 found:" ${FFTW3}) + + endif(NOT IFOPT) + +endif(DISABLE_NLP_ORACLES) + +option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) + +if(DISABLE_NLP_ORACLES) + add_definitions(-DDISABLE_NLP_ORACLES) +else() + find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) + find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) + find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) + find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + + if (NOT IFOPT) + + message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") + + elseif (NOT GMP) + + message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") + + elseif (NOT MPSOLVE) + + message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") + + elseif (NOT FFTW3) + + message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") + + else() + message(STATUS "Library ifopt found: ${IFOPT}") + message(STATUS "Library gmp found: ${GMP}") + message(STATUS "Library mpsolve found: ${MPSOLVE}") + message(STATUS "Library fftw3 found:" ${FFTW3}) + + endif(NOT IFOPT) + +endif(DISABLE_NLP_ORACLES) + +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +include("../external/cmake-files/Autodiff.cmake") +GetAutodiff() + +include("../external/cmake-files/Eigen.cmake") +GetEigen() + +include("../external/cmake-files/Boost.cmake") +GetBoost() + +include("../external/cmake-files/LPSolve.cmake") +GetLPSolve() + +include("../external/cmake-files/QD.cmake") +GetQD() + +# Code Coverage Configuration +add_library(coverage_config INTERFACE) + +option(CODE_COVERAGE "Enable coverage reporting" OFF) +if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + # Add required flags (GCC & LLVM/Clang) + target_compile_options(coverage_config INTERFACE + -O1 # O0 (or no) optimization takes too much time and causes CircleCI test failure. + -g # generate debug info + --coverage # sets all required flags + ) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(coverage_config INTERFACE --coverage) + else() + target_link_libraries(coverage_config INTERFACE --coverage) + endif() +endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + +if (BUILTIN_AUTODIFF) + include_directories (BEFORE ../../external/_deps/Autodiff) +else () + include_directories(BEFORE /usr/local/include) +endif(BUILTIN_AUTODIFF) + +set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") + +if (USE_MKL) + find_library(BLAS NAMES libblas.so libblas.dylib PATHS /usr/local/Cellar/lapack/3.9.1_1/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu /usr/local/Cellar/openblas/0.3.15_1/lib /usr/lib) + find_library(GFORTRAN NAME libgfortran.dylib PATHS /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10) + find_library(LAPACK NAME liblapack.dylib PATHS /usr/lib) + find_library(OPENMP NAME libiomp5.dylib PATHS /opt/intel/oneapi/compiler/2021.1.1/mac/compiler/lib) + include_directories (BEFORE ${MKLROOT}/include) + set(PROJECT_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES}) + set(MKL_LINK "-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl") + add_definitions(-DEIGEN_USE_MKL_ALL) +else() + set(MKL_LINK "") +endif(USE_MKL) + +include_directories (BEFORE ../external) +include_directories (BEFORE ../include) + +#for Eigen +if (${CMAKE_VERSION} VERSION_LESS "3.12.0") + add_compile_options(-D "EIGEN_NO_DEBUG") +else () + add_compile_definitions("EIGEN_NO_DEBUG") +endif () + +add_definitions(${CMAKE_CXX_FLAGS} "-g") # enable debuger +#add_definitions(${CMAKE_CXX_FLAGS} "-Wint-in-bool-context") +#add_definitions(${CMAKE_CXX_FLAGS} "-Wall") + +add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler +add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") #enable the c++17 support needed by autodiff +#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl") +add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm") +add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl") +add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR") +add_definitions(${CMAKE_CXX_FLAGS} "-DMKL_ILP64") +#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") +#add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) + +add_executable (new_volume_example new_volume_example.cpp) +add_executable (benchmarks_sob benchmarks_sob.cpp) +add_executable (benchmarks_cg benchmarks_cg.cpp) +add_executable (benchmarks_cb benchmarks_cb.cpp) + +add_library(test_main OBJECT test_main.cpp) + +add_executable (mcmc_diagnostics_test mcmc_diagnostics_test.cpp $) +add_test(NAME test_psrf COMMAND mcmc_diagnostics_test -tc=psrf) +add_test(NAME test_univariate_psrf COMMAND mcmc_diagnostics_test -tc=univariate_psrf) +add_test(NAME test_interval_psrf COMMAND mcmc_diagnostics_test -tc=interval_psrf) +add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess) +add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke) +add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery) + +add_executable (sampling_test sampling_test.cpp $) +add_test(NAME test_dikin COMMAND sampling_test -tc=dikin) +add_test(NAME test_john COMMAND sampling_test -tc=john) +add_test(NAME test_vaidya COMMAND sampling_test -tc=vaidya) +add_test(NAME test_brdhr COMMAND sampling_test -tc=brdhr) +add_test(NAME test_bcdhr COMMAND sampling_test -tc=bcdhr) +add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr) +add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw) +add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc) + +add_executable (mmcs_test mmcs_test.cpp $) +add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs) + +add_executable (ode_solvers_test ode_solvers_test.cpp $) +add_test(NAME ode_solvers_test_first_order + COMMAND ode_solvers_test -tc=first_order) +add_test(NAME ode_solvers_test_second_order + COMMAND ode_solvers_test -tc=second_order) + +add_executable (root_finders_test root_finders_test.cpp $) +add_test(NAME root_finders_test_root_finders + COMMAND root_finders_test -tc=root_finders) + +#add_executable (benchmarks_crhmc benchmarks_crhmc.cpp ) +#add_executable (benchmarks_crhmc_sampling benchmarks_crhmc_sampling.cpp ) + +add_executable (crhmc_polytope_preparation_test crhmc_polytope_preparation_test.cpp $) +add_test(NAME crhmc_polytope_test_preparation + COMMAND crhmc_polytope_preparation_test -tc=test_preparation_crhmc) +add_test(NAME crhmc_test_fixed_vars + COMMAND crhmc_polytope_preparation_test -tc=test_fixed_vars_crhmc) +add_test(NAME crhmc_test_dep_vars + COMMAND crhmc_polytope_preparation_test -tc=test_dep_vars_crhmc) +add_test(NAME crhmc_test_center_computation + COMMAND crhmc_polytope_preparation_test -tc=test_center_computation) + +add_executable (boundary_oracles_test boundary_oracles_test.cpp $) +add_test(NAME boundary_oracles_test_h_poly_oracles + COMMAND boundary_oracles_test -tc=h_poly_oracles) + +add_executable (volume_sob_hpolytope volume_sob_hpolytope.cpp $) +add_test(NAME volume_sob_hpolytope_cube COMMAND volume_sob_hpolytope -tc=cube) +add_test(NAME volume_sob_hpolytope_cross COMMAND volume_sob_hpolytope -tc=cross) +add_test(NAME volume_sob_hpolytope_birkhoff COMMAND volume_sob_hpolytope -tc=birk) +add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) +add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) +add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) +add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) +set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) + +add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) +add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) +add_test(NAME volume_sob_vpolytope_cross COMMAND volume_sob_vpolytope -tc=cross) +add_test(NAME volume_sob_vpolytope_simplex COMMAND volume_sob_vpolytope -tc=simplex) + +add_executable (volume_cg_hpolytope volume_cg_hpolytope.cpp $) +add_test(NAME volume_cg_hpolytope_cube COMMAND volume_cg_hpolytope -tc=cube) +add_test(NAME volume_cg_hpolytope_cross COMMAND volume_cg_hpolytope -tc=cross) +add_test(NAME volume_cg_hpolytope_birkhoff COMMAND volume_cg_hpolytope -tc=birk) +add_test(NAME volume_cg_hpolytope_prod_simplex COMMAND volume_cg_hpolytope -tc=prod_simplex) +add_test(NAME volume_cg_hpolytope_simplex COMMAND volume_cg_hpolytope -tc=simplex) +add_test(NAME volume_cg_hpolytope_skinny_cube COMMAND volume_cg_hpolytope -tc=skinny_cube) + +add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $) +add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube) +add_test(NAME volume_cg_vpolytope_cross COMMAND volume_cg_vpolytope -tc=cross) +add_test(NAME volume_cg_vpolytope_simplex COMMAND volume_cg_vpolytope -tc=simplex) + +add_executable (volume_cb_hpolytope volume_cb_hpolytope.cpp $) +add_test(NAME volume_cb_hpolytope_cube COMMAND volume_cb_hpolytope -tc=cube) +add_test(NAME volume_cb_hpolytope_cross COMMAND volume_cb_hpolytope -tc=cross) +add_test(NAME volume_cb_hpolytope_birkhoff COMMAND volume_cb_hpolytope -tc=birk) +add_test(NAME volume_cb_hpolytope_prod_simplex COMMAND volume_cb_hpolytope -tc=prod_simplex) +add_test(NAME volume_cb_hpolytope_simplex COMMAND volume_cb_hpolytope -tc=simplex) +add_test(NAME volume_cb_hpolytope_skinny_cube COMMAND volume_cb_hpolytope -tc=skinny_cube) + +add_executable (volume_cb_vpolytope volume_cb_vpolytope.cpp $) +add_test(NAME volume_cb_vpolytope_cube COMMAND volume_cb_vpolytope -tc=cube) +add_test(NAME volume_cb_vpolytope_cross COMMAND volume_cb_vpolytope -tc=cross) +add_test(NAME volume_cb_vpolytope_simplex COMMAND volume_cb_vpolytope -tc=simplex) + +add_executable (volume_cb_zonotopes volume_cb_zonotopes.cpp $) +add_test(NAME volume_cb_zonotopes_uniform_zonotopes + COMMAND volume_cb_zonotopes -tc=uniform_zonotopes) + +add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_vpoly.cpp $) +add_test(NAME volume_cb_vpoly_intersection_vpoly_random_vpoly_sphere + COMMAND volume_cb_vpoly_intersection_vpoly -tc=random_vpoly_sphere) + +add_executable (new_rounding_test new_rounding_test.cpp $) +add_test(NAME test_round_min_ellipsoid + COMMAND new_rounding_test -tc=round_min_ellipsoid) +add_test(NAME test_round_max_ellipsoid + COMMAND new_rounding_test -tc=round_max_ellipsoid) +add_test(NAME test_round_svd + COMMAND new_rounding_test -tc=round_svd) +add_test(NAME test_round_log_barrier_test + COMMAND new_rounding_test -tc=round_log_barrier_test) + + + +add_executable (logconcave_sampling_test logconcave_sampling_test.cpp $) +add_test(NAME logconcave_sampling_test_hmc + COMMAND logconcave_sampling_test -tc=hmc) +add_test(NAME logconcave_sampling_test_uld + COMMAND logconcave_sampling_test -tc=uld) +add_test(NAME logconcave_sampling_test_exponential_biomass_sampling + COMMAND logconcave_sampling_test -tc=exponential_biomass_sampling) +add_test(NAME logconcave_sampling_test_nuts_hmc_truncated + COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated) +add_test(NAME logconcave_sampling_test_nuts_hmc + COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc) + + + +add_executable (crhmc_sampling_test crhmc_sampling_test.cpp $) +add_test(NAME crhmc_sampling_test_crhmc + COMMAND crhmc_sampling_test -tc=crhmc) +add_test(NAME crhmc_test_polytope_sampling + COMMAND crhmc_sampling_test -tc=test_polytope_sampling_crhmc) +add_test(NAME crhmc_test_sparse_sampling + COMMAND crhmc_sampling_test -tc=test_sampling_sparse_problem) +add_executable (simple_mc_integration simple_mc_integration.cpp $) +add_test(NAME simple_mc_integration_over_limits + COMMAND simple_mc_integration -tc=rectangle) +add_test(NAME simple_mc_integration_over_cubes + COMMAND simple_mc_integration -tc=cube) +add_test(NAME simple_mc_integration_over_simplices + COMMAND simple_mc_integration -tc=simplex) +add_test(NAME simple_mc_integration_over_product_simplices + COMMAND simple_mc_integration -tc=prod_simplex) +add_test(NAME simple_mc_integration_over_cross_polytopes + COMMAND simple_mc_integration -tc=cross) +add_test(NAME simple_mc_integration_over_birkhoff_polytopes + COMMAND simple_mc_integration -tc=birkhoff) + +add_executable (order_polytope order_polytope.cpp $) +add_test(NAME order_polytope_basics COMMAND order_polytope -tc=basics) +add_test(NAME order_polytope_line_intersect COMMAND order_polytope -tc=line_intersect) +add_test(NAME order_polytope_reflection COMMAND order_polytope -tc=reflection) +add_test(NAME order_polytope_vec_mult COMMAND order_polytope -tc=vec_mult) + +add_executable (matrix_sampling_test sampling_correlation_matrices_test.cpp $) +add_test(NAME test_corre_spectra_classes COMMAND matrix_sampling_test -tc=corre_spectra) +add_test(NAME test_new_ball_uniform COMMAND matrix_sampling_test -tc=new_ball_uniform) +add_test(NAME test_new_billiard_uniform COMMAND matrix_sampling_test -tc=new_billiard_uniform) +add_test(NAME test_new_accelerated_billiard_uniform COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform) +add_test(NAME test_new_ball_uniform_MT COMMAND matrix_sampling_test -tc=new_ball_uniform_MT) +add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr_uniform_MT) +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) + +set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") + +#set_target_properties(benchmarks_crhmc +# PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) +#set_target_properties(benchmarks_crhmc_sampling +# PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) +set_target_properties(crhmc_polytope_preparation_test + PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) +set_target_properties(crhmc_sampling_test + PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) + +TARGET_LINK_LIBRARIES(new_volume_example lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(new_volume_example lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_sob_hpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_sob_vpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cg_hpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cg_vpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cb_hpolytope lp_solve coverage_config) +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(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) +TARGET_LINK_LIBRARIES(benchmarks_sob lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(benchmarks_cg lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(benchmarks_cb lp_solve ${MKL_LINK} coverage_config) +#TARGET_LINK_LIBRARIES(benchmarks_crhmc_sampling lp_solve ${MKL_LINK} QD_LIB coverage_config) +#TARGET_LINK_LIBRARIES(benchmarks_crhmc lp_solve ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(simple_mc_integration lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(ode_solvers_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(boundary_oracles_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(root_finders_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(crhmc_polytope_preparation_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +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/test_internal_points.cpp b/test/test_internal_points.cpp index ec1fe2e49..f679bd1c3 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -22,6 +22,9 @@ #include "generators/known_polytope_generators.h" #include "generators/h_polytopes_generator.h" +#include "convex_bodies/orderpolytope.h" +#include "misc/poset.h" + template void call_test_max_ball() { typedef Cartesian Kernel; @@ -40,12 +43,60 @@ void call_test_max_ball() { NT tol = 1e-08; unsigned int maxiter = 500; auto [center, radius, converged] = max_inscribed_ball(P.get_mat(), P.get_vec(), maxiter, tol); - CHECK(P.is_in(Point(center)) == -1); CHECK(std::abs(radius - InnerBall.second) <= 1e-03); CHECK(converged); } +template +void call_test_max_ball_sparse() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + typedef boost::mt19937 PolyRNGType; + typedef typename OrderPolytope::VT VT; + typedef typename OrderPolytope::MT MT; + typedef typename Poset::RT RT; + typedef typename Poset::RV RV; + typedef Eigen::SparseMatrix SpMT; + + // Create Poset, 4 elements, a0 <= a1, a0 <= a2, a1 <= a3 + RV poset_data{{0, 1}, {0, 2}, {1, 3}}; + Poset poset(4, poset_data); + + // Initialize order polytope from the poset + OrderPolytope OP(poset); + OP.normalize(); + SpMT Asp = OP.get_mat(); + std::cout<<"Asp:\n" < InnerBall = OP.ComputeInnerBall(); + + NT tol = 1e-08; + unsigned int maxiter = 500; + auto [center, radius, converged] = max_inscribed_ball(Asp, b, maxiter, tol); + std::cout<<"sparse ended\n"< void call_test_max_ball_feasibility() { typedef Cartesian Kernel; @@ -117,3 +168,7 @@ TEST_CASE("test_feasibility_point") { TEST_CASE("test_analytic_center") { call_test_analytic_center(); } + +TEST_CASE("test_max_ball_sparse") { + call_test_max_ball_sparse(); +} \ No newline at end of file From 7e66e8c4e157c6a0bbf54e72ccc93e84474b00de Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Mon, 24 Jun 2024 12:22:07 -0600 Subject: [PATCH 04/20] complete sparse support in preprocesing --- include/convex_bodies/orderpolytope.h | 6 + .../preprocess/analytic_center_linear_ineq.h | 16 +- include/preprocess/cholesky_opoerator.h | 161 ----------- include/preprocess/feasible_point.hpp | 6 +- .../preprocess/mat_computational_operator.h | 252 ++++++++++++++++++ include/preprocess/max_inscribed_ball.hpp | 27 +- .../preprocess/max_inscribed_ellipsoid.hpp | 53 ++-- .../max_inscribed_ellipsoid_rounding.hpp | 2 +- test/CMakeLists.txt | 20 +- test/test_internal_points.cpp | 3 + 10 files changed, 320 insertions(+), 226 deletions(-) delete mode 100644 include/preprocess/cholesky_opoerator.h create mode 100644 include/preprocess/mat_computational_operator.h diff --git a/include/convex_bodies/orderpolytope.h b/include/convex_bodies/orderpolytope.h index 2df5c6619..79f41e161 100644 --- a/include/convex_bodies/orderpolytope.h +++ b/include/convex_bodies/orderpolytope.h @@ -638,6 +638,12 @@ class OrderPolytope { return false; } + // Apply linear transformation, of square matrix T^{-1}, in H-polytope P:= Ax<=b + // This is most of the times for testing reasons because it might destroy the sparsity + void linear_transformIt(MT const& T) + { + _A = _A * T; + } // shift polytope by a point c void shift(VT const& c) diff --git a/include/preprocess/analytic_center_linear_ineq.h b/include/preprocess/analytic_center_linear_ineq.h index 657d054cd..ab188c314 100644 --- a/include/preprocess/analytic_center_linear_ineq.h +++ b/include/preprocess/analytic_center_linear_ineq.h @@ -14,7 +14,7 @@ #include "max_inscribed_ball.hpp" #include "feasible_point.hpp" -#include "cholesky_opoerator.h" +#include "mat_computational_operator.h" template NT get_max_step(VT const& Ad, VT const& b_Ax) @@ -41,7 +41,7 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, // Gradient of the log-barrier function grad.noalias() = A_trans * s; // Hessian of the log-barrier function - cholesky_operator::update_hessian_Atrans_D_A(H, A_trans, A, s_sq.asDiagonal()); + matrix_computational_operator::update_Atrans_Diag_A(H, A_trans, A, s_sq.asDiagonal()); } /* @@ -59,8 +59,11 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, (iii) Tolerance parameter grad_err_tol to bound the L2-norm of the gradient (iv) Tolerance parameter rel_pos_err_tol to check the relative progress in each iteration - Output: (i) The analytic center of the polytope - (ii) A boolean variable that declares convergence + Output: (i) The Hessian computed on the analytic center + (ii) The analytic center of the polytope + (iii) A boolean variable that declares convergence + + Note: Using MT as to deal with both dense and sparse matrices, MT_dense will be the type of result matrix */ template std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, VT const& x0, @@ -68,6 +71,7 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT cons NT const grad_err_tol = 1e-08, NT const rel_pos_err_tol = 1e-12) { + typedef matrix_computational_operator mat_op; // Initialization VT x = x0; VT Ax = A * x; @@ -79,14 +83,14 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT cons bool converged = false; const NT tol_bnd = NT(0.01); - auto llt = cholesky_operator::initialize(A_trans*A); + auto llt = mat_op::initialize_chol(A_trans*A); get_hessian_grad_logbarrier(A, A_trans, b, x, Ax, H, grad, b_Ax); do { iter++; // Compute the direction - d.noalias() = - cholesky_operator::solve(llt, H, grad); + d.noalias() = - mat_op::solve_vec(llt, H, grad); Ad.noalias() = A * d; // Compute the step length step = std::min((NT(1) - tol_bnd) * get_max_step(Ad, b_Ax), NT(1)); diff --git a/include/preprocess/cholesky_opoerator.h b/include/preprocess/cholesky_opoerator.h deleted file mode 100644 index b64f4b42e..000000000 --- a/include/preprocess/cholesky_opoerator.h +++ /dev/null @@ -1,161 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2024 Vissarion Fisikopoulos -// Copyright (c) 2024 Apostolos Chalkis -// Copyright (c) 2024 Elias Tsigaridas - -// Licensed under GNU LGPL.3, see LICENCE file - - -#ifndef CHOLESKY_OPERATOR_H -#define CHOLESKY_OPERATOR_H - -#include - -template -struct cholesky_operator -{ - inline static std::unique_ptr> - initialize(MT const&) - { - return std::unique_ptr>(new Eigen::LLT()); - } - - template - inline static VT solve(std::unique_ptr> const& llt, MT const& H, VT const& b) - { - llt->compute(H); - return llt->solve(b); - } - - template - inline static void update_hessian_Atrans_D_A(MT &H, MT const& A_trans, MT const& A, diag_MT const& D) - { - H.noalias() = A_trans * D * A; - } - - inline static void init_Bmat(MT &B, int const n, MT const& , MT const& ) - { - B.resize(n+1, n+1); - } - - template - inline static void update_Bmat(MT &B, VT const& AtDe, VT const& d, MT const& AtD, MT const& A) - { - const int n = A.cols(); - B.block(0, 0, n, n).noalias() = AtD * A; - B.block(0, n, n, 1).noalias() = AtDe; - B.block(n, 0, 1, n).noalias() = AtDe.transpose(); - B(n, n) = d.sum(); - B.noalias() += 1e-14 * MT::Identity(n + 1, n + 1); - } -}; - -template -struct cholesky_operator> -{ - inline static std::unique_ptr>> - initialize(Eigen::SparseMatrix const& mat) - { - std::unique_ptr>> llt = std::unique_ptr>>(new Eigen::SimplicialLLT>()); - llt->analyzePattern(mat); - return llt; - } - - template - inline static VT solve(std::unique_ptr>> const& llt, Eigen::SparseMatrix const& H, VT const& b) - { - llt->factorize(H); - return llt->solve(b); - } - - template - inline static void update_hessian_Atrans_D_A(Eigen::SparseMatrix &H, Eigen::SparseMatrix const& A_trans, Eigen::SparseMatrix const& A, diag_MT const& D) - { - H = A_trans * D * A; - } - - inline static void init_Bmat(Eigen::SparseMatrix &B, int const n, Eigen::SparseMatrix const& A_trans, Eigen::SparseMatrix const& A) - { - // Initialize the structure of matrix B - typedef Eigen::Triplet triplet; - std::vector trp; - for (int i = 0; i < n; i++) - { - trp.push_back(triplet(i, i, NT(1))); - trp.push_back(triplet(i, n, NT(1))); - trp.push_back(triplet(n, i, NT(1))); - } - trp.push_back(triplet(n, n, NT(1))); - Eigen::SparseMatrix ATA = A_trans * A; - for (int k=0; k::InnerIterator it(ATA,k); it; ++it) - { - if (it.row() == it.col()) continue; - trp.push_back(triplet(it.row(), it.col(), NT(1))); - } - } - B.resize(n+1, n+1); - B.setFromTriplets(trp.begin(), trp.end()); - } - - template - inline static void update_Bmat(Eigen::SparseMatrix &B, VT const& AtDe, VT const& d, Eigen::SparseMatrix const& AtD, Eigen::SparseMatrix const& A) - { - const int n = A.cols(); - Eigen::SparseMatrix AtD_A = AtD * A; - //std::cout<<"B indeces: "<::InnerIterator it1(B,k); - typename Eigen::SparseMatrix::InnerIterator it2(AtD_A,k <= n-1 ? k : k-1); - for (typename Eigen::SparseMatrix::InnerIterator it1(B,k); it1; ++it1) - { - //std::cout<<"row1: "< VT compute_feasible_point(MT const& A, VT const& b) { diff --git a/include/preprocess/mat_computational_operator.h b/include/preprocess/mat_computational_operator.h new file mode 100644 index 000000000..fb4caf7b0 --- /dev/null +++ b/include/preprocess/mat_computational_operator.h @@ -0,0 +1,252 @@ +// VolEsti (volume computation and sampling library) + +// Copyright (c) 2024 Vissarion Fisikopoulos +// Copyright (c) 2024 Apostolos Chalkis +// Copyright (c) 2024 Elias Tsigaridas + +// Licensed under GNU LGPL.3, see LICENCE file + + +#ifndef MATRIX_COMPUTATIONAL_OPERATOR_H +#define MATRIX_COMPUTATIONAL_OPERATOR_H + +#include + +#include "Spectra/include/Spectra/SymEigsSolver.h" +#include "Spectra/include/Spectra/MatOp/DenseSymMatProd.h" +#include "Spectra/include/Spectra/MatOp/SparseSymMatProd.h" + + +template +struct matrix_computational_operator {}; + + +// Dense matrix operator +template +struct matrix_computational_operator> +{ + typedef Eigen::Matrix MT; + + inline static std::unique_ptr> + initialize_chol(MT const&) + { + return std::unique_ptr>(new Eigen::LLT()); + } + + template + inline static VT solve_vec(std::unique_ptr> const& llt, + MT const& H, VT const& b) + { + llt->compute(H); + return llt->solve(b); + } + + inline static MT solve_mat(std::unique_ptr> const& llt, + MT const& E, MT const& mat, NT &logdetE) + { + llt->compute(E); + logdetE = llt->matrixL().toDenseMatrix().diagonal().array().log().sum(); + return llt->solve(mat); + } + + template + inline static void update_Atrans_Diag_A(MT &H, MT const& A_trans, + MT const& A, diag_MT const& D) + { + H.noalias() = A_trans * D * A; + } + + template + inline static void update_Diag_A(MT &H, diag_MT const& D, MT const& A) + { + H.noalias() = D * A; + } + + template + inline static void update_A_Diag(MT &H, MT const& A, diag_MT const& D) + { + H.noalias() = A * D; + } + + inline static std::unique_ptr> get_mat_prod_op(MT const& E) + { + return std::unique_ptr>(new Spectra::DenseSymMatProd(E)); + } + + inline static std::unique_ptr>> get_eigs_solver(std::unique_ptr> const& op, + int const n) + { + return std::unique_ptr>>(new Spectra::SymEigsSolver>(op.get(), 2, std::min(std::max(10, n/5), n))); + } + + inline static void init_Bmat(MT &B, int const n, MT const& , MT const& ) + { + B.resize(n+1, n+1); + } + + template + inline static void update_Bmat(MT &B, VT const& AtDe, VT const& d, + MT const& AtD, MT const& A) + { + const int n = A.cols(); + B.block(0, 0, n, n).noalias() = AtD * A; + B.block(0, n, n, 1).noalias() = AtDe; + B.block(n, 0, 1, n).noalias() = AtDe.transpose(); + B(n, n) = d.sum(); + B.noalias() += 1e-14 * MT::Identity(n + 1, n + 1); + } +}; + + +// Sparse matrix operator +template +struct matrix_computational_operator> +{ + typedef Eigen::Matrix MT; + + inline static std::unique_ptr>> + initialize_chol(Eigen::SparseMatrix const& mat) + { + std::unique_ptr>> llt = + std::unique_ptr>>(new Eigen::SimplicialLLT>()); + llt->analyzePattern(mat); + return llt; + } + + template + inline static VT solve_vec(std::unique_ptr>> const& llt, + Eigen::SparseMatrix const& H, VT const& b) + { + llt->factorize(H); + return llt->solve(b); + } + + inline static MT solve_mat(std::unique_ptr>> const& llt, + Eigen::SparseMatrix const& E, Eigen::SparseMatrix const& mat, NT &logdetE) + { + llt->factorize(E); + logdetE = llt->matrixL().nestedExpression().diagonal().array().log().sum(); + return llt->solve(mat); + } + + template + inline static void update_Atrans_Diag_A(Eigen::SparseMatrix &H, + Eigen::SparseMatrix const& A_trans, + Eigen::SparseMatrix const& A, + diag_MT const& D) + { + H = A_trans * D * A; + } + + template + inline static void update_Diag_A(Eigen::SparseMatrix &H, + diag_MT const& D, + Eigen::SparseMatrix const& A) + { + H = D * A; + } + + template + inline static void update_A_Diag(Eigen::SparseMatrix &H, + Eigen::SparseMatrix const& A, + diag_MT const& D) + { + H = A * D; + } + + inline static std::unique_ptr> + get_mat_prod_op(Eigen::SparseMatrix const& E) + { + return std::unique_ptr>(new Spectra::SparseSymMatProd(E)); + } + + inline static std::unique_ptr>> get_eigs_solver(std::unique_ptr> const& op, + int const n) + { + return std::unique_ptr>>(new Spectra::SymEigsSolver>(op.get(), 2, std::min(std::max(10, n/5), n))); + } + + inline static void init_Bmat(Eigen::SparseMatrix &B, + int const n, + Eigen::SparseMatrix const& A_trans, + Eigen::SparseMatrix const& A) + { + // Initialize the structure of matrix B + typedef Eigen::Triplet triplet; + std::vector trp; + for (int i = 0; i < n; i++) + { + trp.push_back(triplet(i, i, NT(1))); + trp.push_back(triplet(i, n, NT(1))); + trp.push_back(triplet(n, i, NT(1))); + } + trp.push_back(triplet(n, n, NT(1))); + + Eigen::SparseMatrix ATA = A_trans * A; + for (int k=0; k::InnerIterator it(ATA,k); it; ++it) + { + if (it.row() == it.col()) continue; // Diagonal element already allocated + trp.push_back(triplet(it.row(), it.col(), NT(1))); + } + } + B.resize(n+1, n+1); + B.setFromTriplets(trp.begin(), trp.end()); + } + + template + inline static void update_Bmat(Eigen::SparseMatrix &B, + VT const& AtDe, + VT const& d, + Eigen::SparseMatrix const& AtD, + Eigen::SparseMatrix const& A) + { + /* + B is (n+1)x(n+1) and AtD_A is nxn. + We set B(1:n), 1:n) = AtD_A, B(n+1, :) = AtD^T, B(:, n+1) = AtD, B(n+1, n+1) = d.sum() + */ + const int n = A.cols(); + Eigen::SparseMatrix AtD_A = AtD * A; + int k = 0; + while(k < B.outerSize()) + { + typename Eigen::SparseMatrix::InnerIterator it2(AtD_A, k <= n-1 ? k : k-1); + for (typename Eigen::SparseMatrix::InnerIterator it1(B, k); it1; ++it1) + { + if (it1.row() <= n-1 && it1.col() <= n-1) + { + it1.valueRef() = it2.value(); + } + else if (it1.row() == n && it1.col() <= n-1) + { + it1.valueRef() = AtDe.coeff(it1.col()); + } + else if (it1.col() == n && it1.row() <= n-1) + { + it1.valueRef() = AtDe.coeff(it1.row()); + } + else // then, (it1.row() == n && it1.col() == n) + { + it1.valueRef() = d.sum(); + } + + if (it1.row() == it1.col()) + { + it1.valueRef() += 1e-14; + } + if (it1.row()::solve(llt, B, rhs); + VT dxdt = matrix_computational_operator::solve_vec(llt, B, rhs); dx = dxdt.block(0,0,n,1); dt = dxdt(n); @@ -59,12 +59,13 @@ void calcstep(MT const& A, MT const& A_trans, MT const& B, } } - +// Using MT as to deal with both dense and sparse matrices template std::tuple max_inscribed_ball(MT const& A, VT const& b, unsigned int maxiter, NT tol, const bool feasibility_only = false) { + typedef matrix_computational_operator mat_op; int m = A.rows(), n = A.cols(); bool converge = false; @@ -88,10 +89,9 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, NT *vec_iter1, *vec_iter2, *vec_iter3, *vec_iter4; MT B, AtD(n, m), A_trans = A.transpose(); - //MT_dense eEye = std::pow(10.0, -14.0) * MT_dense::Identity(n + 1, n + 1); - cholesky_operator::init_Bmat(B, n, A_trans, A); - auto llt = cholesky_operator::initialize(B); + mat_op::init_Bmat(B, n, A_trans, A); + auto llt = mat_op::initialize_chol(B); for (unsigned int i = 0; i < maxiter; ++i) { @@ -140,21 +140,10 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, vec_iter3++; vec_iter2++; } - AtD = A_trans*d.asDiagonal(); //todo: optimize it in cholesky_operator + mat_op::update_A_Diag(AtD, A_trans, d.asDiagonal()); // AtD = A_trans*d.asDiagonal() AtDe.noalias() = AtD * e_m; - //std::cout<<"starting update Bmat..\n"<::update_Bmat(B, AtDe, d, AtD, A); - //exit(-1); - //B.block(0, 0, n, n).noalias() = AtD * A; - //B.block(0, n, n, 1).noalias() = AtDe; - //B.block(n, 0, 1, n).noalias() = AtDe.transpose(); - //B(n, n) = d.sum(); - //B.noalias() += eEye; - //std::cout<<"B:\n"< lltOfB(B); + mat_op::update_Bmat(B, AtDe, d, AtD, A); // predictor step & length calcstep(A, A_trans, B, llt, s, y, r1, r2, r3, r4, dx, ds, dt, dy, tmp, rhs); diff --git a/include/preprocess/max_inscribed_ellipsoid.hpp b/include/preprocess/max_inscribed_ellipsoid.hpp index 2a824e10f..92a835074 100644 --- a/include/preprocess/max_inscribed_ellipsoid.hpp +++ b/include/preprocess/max_inscribed_ellipsoid.hpp @@ -18,6 +18,7 @@ #include "Spectra/include/Spectra/SymEigsSolver.h" #include "Spectra/include/Spectra/Util/SelectionRule.h" #include "Spectra/include/Spectra/MatOp/DenseSymMatProd.h" +#include "mat_computational_operator.h" /* @@ -37,14 +38,14 @@ matrix E2^{-1} = E_transpose * E */ -// using Custom_MT as to deal with both dense and sparse matrices, MT will be the type of result matrix -// TODO: Change the return data structure to std::tuple -template -std::tuple max_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0, - unsigned int const& maxiter, - NT const& tol, NT const& reg) +// Using MT as to deal with both dense and sparse matrices, MT_dense will be the type of result matrix +template +std::tuple max_inscribed_ellipsoid(MT A, VT b, VT const& x0, + unsigned int const& maxiter, + NT const& tol, NT const& reg) { typedef Eigen::DiagonalMatrix Diagonal_MT; + typedef matrix_computational_operator mat_op; int m = A.rows(), n = A.cols(); bool converged = false; @@ -66,22 +67,23 @@ std::tuple max_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0 VT const bmAx0 = b - A * x0, ones_m = VT::Ones(m); - MT Q(m, m), E2(n, n), YQ(m,m), G(m,m), T(m,n), ATP(n,m), ATP_A(n,n); + MT_dense Q(m,m), YQ(m,m), G(m,m), T(m,n), ATP(n,m), ATP_A(n,n); Diagonal_MT Y(m); - Custom_MT YA(m, n); + MT YA(m, n); A = (ones_m.cwiseProduct(bmAx0.cwiseInverse())).asDiagonal() * A, b = ones_m; - Custom_MT A_trans = A.transpose(); + MT A_trans = A.transpose(), E2(n,n); + + auto llt = mat_op::initialize_chol(A_trans*A); int i = 1; while (i <= maxiter) { Y = y.asDiagonal(); - E2.noalias() = MT(A_trans * Y * A); - Eigen::LLT llt(E2); - - Q.noalias() = A * llt.solve(A_trans); + mat_op::update_Atrans_Diag_A(E2, A_trans, A, Y); + Q.noalias() = A * mat_op::solve_mat(llt, E2, A_trans, logdetE2); + h = Q.diagonal(); h = h.cwiseSqrt(); @@ -120,7 +122,6 @@ std::tuple max_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0 res = std::max(r1, r2); res = std::max(res, r3); - logdetE2 = llt.matrixL().toDenseMatrix().diagonal().array().log().sum(); objval = logdetE2; //logdet of E2 is already divided by 2 if (i % 10 == 0) { @@ -128,15 +129,13 @@ std::tuple max_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0 NT rel, Rel; // computing eigenvalues of E2 - Spectra::DenseSymMatProd op(E2); - // The value of ncv is chosen empirically - Spectra::SymEigsSolver> eigs(&op, 2, std::min(std::max(10, n/5), n)); - eigs.init(); - int nconv = eigs.compute(); - if (eigs.info() == Spectra::COMPUTATION_INFO::SUCCESSFUL) { - Rel = 1.0 / eigs.eigenvalues().coeff(1); - rel = 1.0 / eigs.eigenvalues().coeff(0); + auto op = mat_op::get_mat_prod_op(E2); + auto eigs = mat_op::get_eigs_solver(op, n); + eigs->init(); + int nconv = eigs->compute(); + if (eigs->info() == Spectra::COMPUTATION_INFO::SUCCESSFUL) { + Rel = 1.0 / eigs->eigenvalues().coeff(1); + rel = 1.0 / eigs->eigenvalues().coeff(0); } else { Eigen::SelfAdjointEigenSolver eigensolver(E2); // E2 is positive definite matrix if (eigensolver.info() == Eigen::ComputationInfo::Success) { @@ -176,7 +175,7 @@ std::tuple max_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0 YQ.noalias() = Y * Q; G = YQ.cwiseProduct(YQ.transpose()); y2h = 2.0 * yh; - YA.noalias() = Y * A; + mat_op::update_Diag_A(YA, Y, A); // YA = Y * A; vec_iter1 = y2h.data(); vec_iter2 = z.data(); @@ -190,10 +189,10 @@ std::tuple max_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0 G.diagonal() += y2h_z; h_z = h + z; - Eigen::PartialPivLU luG(G); - T.noalias() = luG.solve(h_z.asDiagonal()*YA); + Eigen::PartialPivLU luG(G); + T.noalias() = luG.solve(MT_dense(h_z.asDiagonal()*YA)); - ATP.noalias() = MT(y2h.asDiagonal()*T - YA).transpose(); + ATP.noalias() = MT_dense(y2h.asDiagonal()*T - YA).transpose(); vec_iter1 = R3.data(); vec_iter2 = y.data(); diff --git a/include/preprocess/max_inscribed_ellipsoid_rounding.hpp b/include/preprocess/max_inscribed_ellipsoid_rounding.hpp index e2a43f988..d44a60b2e 100644 --- a/include/preprocess/max_inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/max_inscribed_ellipsoid_rounding.hpp @@ -30,7 +30,7 @@ struct inscribed_ellispoid unsigned int const& maxiter, NT const& tol, NT const& reg) { - std::runtime_error("no roudning method is defined"); + std::runtime_error("No roudning method is defined"); return std::tuple(); } }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index babc605ee..6e417995d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -191,15 +191,15 @@ add_library(test_main OBJECT test_main.cpp) -#add_executable (new_rounding_test new_rounding_test.cpp $) -#add_test(NAME test_round_min_ellipsoid -# COMMAND new_rounding_test -tc=round_min_ellipsoid) -#add_test(NAME test_round_max_ellipsoid -# COMMAND new_rounding_test -tc=round_max_ellipsoid) -#add_test(NAME test_round_svd -# COMMAND new_rounding_test -tc=round_svd) -#add_test(NAME test_round_log_barrier_test -# COMMAND new_rounding_test -tc=round_log_barrier_test) +add_executable (new_rounding_test new_rounding_test.cpp $) +add_test(NAME test_round_min_ellipsoid + COMMAND new_rounding_test -tc=round_min_ellipsoid) +add_test(NAME test_round_max_ellipsoid + COMMAND new_rounding_test -tc=round_max_ellipsoid) +add_test(NAME test_round_svd + COMMAND new_rounding_test -tc=round_svd) +add_test(NAME test_round_log_barrier_test + COMMAND new_rounding_test -tc=round_log_barrier_test) @@ -223,5 +223,5 @@ set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -#TARGET_LINK_LIBRARIES(new_rounding_test lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(new_rounding_test lp_solve ${MKL_LINK} coverage_config) TARGET_LINK_LIBRARIES(test_internal_points lp_solve ${MKL_LINK} coverage_config) diff --git a/test/test_internal_points.cpp b/test/test_internal_points.cpp index f679bd1c3..c8decb500 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -91,7 +91,10 @@ void call_test_max_ball_sparse() { std::cout<<"converged2: "<(OP, Point(center)); + CHECK((center - center_).norm() <= 1e-06); CHECK(std::abs(radius - 0.207107) <= 1e-06); CHECK(converged); From 5df7093c13eb0ee2c3bb14a3ec5158cc6be244b8 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Mon, 24 Jun 2024 12:47:57 -0600 Subject: [PATCH 05/20] add sparse tests --- .../preprocess/max_inscribed_ellipsoid.hpp | 3 - test/CMakeLists.txt | 198 ++++++++- test/CMakeLists_2.txt | 403 ------------------ test/new_rounding_test.cpp | 60 +++ test/test_internal_points.cpp | 17 +- 5 files changed, 253 insertions(+), 428 deletions(-) delete mode 100644 test/CMakeLists_2.txt diff --git a/include/preprocess/max_inscribed_ellipsoid.hpp b/include/preprocess/max_inscribed_ellipsoid.hpp index 92a835074..4ab1ee4e1 100644 --- a/include/preprocess/max_inscribed_ellipsoid.hpp +++ b/include/preprocess/max_inscribed_ellipsoid.hpp @@ -15,9 +15,6 @@ #include #include -#include "Spectra/include/Spectra/SymEigsSolver.h" -#include "Spectra/include/Spectra/Util/SelectionRule.h" -#include "Spectra/include/Spectra/MatOp/DenseSymMatProd.h" #include "mat_computational_operator.h" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6e417995d..b4ef9ae02 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -185,11 +185,109 @@ add_definitions(${CMAKE_CXX_FLAGS} "-DMKL_ILP64") #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") #add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) - +add_executable (new_volume_example new_volume_example.cpp) +add_executable (benchmarks_sob benchmarks_sob.cpp) +add_executable (benchmarks_cg benchmarks_cg.cpp) +add_executable (benchmarks_cb benchmarks_cb.cpp) add_library(test_main OBJECT test_main.cpp) - +add_executable (mcmc_diagnostics_test mcmc_diagnostics_test.cpp $) +add_test(NAME test_psrf COMMAND mcmc_diagnostics_test -tc=psrf) +add_test(NAME test_univariate_psrf COMMAND mcmc_diagnostics_test -tc=univariate_psrf) +add_test(NAME test_interval_psrf COMMAND mcmc_diagnostics_test -tc=interval_psrf) +add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess) +add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke) +add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery) + +add_executable (sampling_test sampling_test.cpp $) +add_test(NAME test_dikin COMMAND sampling_test -tc=dikin) +add_test(NAME test_john COMMAND sampling_test -tc=john) +add_test(NAME test_vaidya COMMAND sampling_test -tc=vaidya) +add_test(NAME test_brdhr COMMAND sampling_test -tc=brdhr) +add_test(NAME test_bcdhr COMMAND sampling_test -tc=bcdhr) +add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr) +add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw) +add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc) + +add_executable (mmcs_test mmcs_test.cpp $) +add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs) + +add_executable (ode_solvers_test ode_solvers_test.cpp $) +add_test(NAME ode_solvers_test_first_order + COMMAND ode_solvers_test -tc=first_order) +add_test(NAME ode_solvers_test_second_order + COMMAND ode_solvers_test -tc=second_order) + +add_executable (root_finders_test root_finders_test.cpp $) +add_test(NAME root_finders_test_root_finders + COMMAND root_finders_test -tc=root_finders) + +#add_executable (benchmarks_crhmc benchmarks_crhmc.cpp ) +#add_executable (benchmarks_crhmc_sampling benchmarks_crhmc_sampling.cpp ) + +add_executable (crhmc_polytope_preparation_test crhmc_polytope_preparation_test.cpp $) +add_test(NAME crhmc_polytope_test_preparation + COMMAND crhmc_polytope_preparation_test -tc=test_preparation_crhmc) +add_test(NAME crhmc_test_fixed_vars + COMMAND crhmc_polytope_preparation_test -tc=test_fixed_vars_crhmc) +add_test(NAME crhmc_test_dep_vars + COMMAND crhmc_polytope_preparation_test -tc=test_dep_vars_crhmc) +add_test(NAME crhmc_test_center_computation + COMMAND crhmc_polytope_preparation_test -tc=test_center_computation) + +add_executable (boundary_oracles_test boundary_oracles_test.cpp $) +add_test(NAME boundary_oracles_test_h_poly_oracles + COMMAND boundary_oracles_test -tc=h_poly_oracles) + +add_executable (volume_sob_hpolytope volume_sob_hpolytope.cpp $) +add_test(NAME volume_sob_hpolytope_cube COMMAND volume_sob_hpolytope -tc=cube) +add_test(NAME volume_sob_hpolytope_cross COMMAND volume_sob_hpolytope -tc=cross) +add_test(NAME volume_sob_hpolytope_birkhoff COMMAND volume_sob_hpolytope -tc=birk) +add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) +add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) +add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) +add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) +set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) + +add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) +add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) +add_test(NAME volume_sob_vpolytope_cross COMMAND volume_sob_vpolytope -tc=cross) +add_test(NAME volume_sob_vpolytope_simplex COMMAND volume_sob_vpolytope -tc=simplex) + +add_executable (volume_cg_hpolytope volume_cg_hpolytope.cpp $) +add_test(NAME volume_cg_hpolytope_cube COMMAND volume_cg_hpolytope -tc=cube) +add_test(NAME volume_cg_hpolytope_cross COMMAND volume_cg_hpolytope -tc=cross) +add_test(NAME volume_cg_hpolytope_birkhoff COMMAND volume_cg_hpolytope -tc=birk) +add_test(NAME volume_cg_hpolytope_prod_simplex COMMAND volume_cg_hpolytope -tc=prod_simplex) +add_test(NAME volume_cg_hpolytope_simplex COMMAND volume_cg_hpolytope -tc=simplex) +add_test(NAME volume_cg_hpolytope_skinny_cube COMMAND volume_cg_hpolytope -tc=skinny_cube) + +add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $) +add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube) +add_test(NAME volume_cg_vpolytope_cross COMMAND volume_cg_vpolytope -tc=cross) +add_test(NAME volume_cg_vpolytope_simplex COMMAND volume_cg_vpolytope -tc=simplex) + +add_executable (volume_cb_hpolytope volume_cb_hpolytope.cpp $) +add_test(NAME volume_cb_hpolytope_cube COMMAND volume_cb_hpolytope -tc=cube) +add_test(NAME volume_cb_hpolytope_cross COMMAND volume_cb_hpolytope -tc=cross) +add_test(NAME volume_cb_hpolytope_birkhoff COMMAND volume_cb_hpolytope -tc=birk) +add_test(NAME volume_cb_hpolytope_prod_simplex COMMAND volume_cb_hpolytope -tc=prod_simplex) +add_test(NAME volume_cb_hpolytope_simplex COMMAND volume_cb_hpolytope -tc=simplex) +add_test(NAME volume_cb_hpolytope_skinny_cube COMMAND volume_cb_hpolytope -tc=skinny_cube) + +add_executable (volume_cb_vpolytope volume_cb_vpolytope.cpp $) +add_test(NAME volume_cb_vpolytope_cube COMMAND volume_cb_vpolytope -tc=cube) +add_test(NAME volume_cb_vpolytope_cross COMMAND volume_cb_vpolytope -tc=cross) +add_test(NAME volume_cb_vpolytope_simplex COMMAND volume_cb_vpolytope -tc=simplex) + +add_executable (volume_cb_zonotopes volume_cb_zonotopes.cpp $) +add_test(NAME volume_cb_zonotopes_uniform_zonotopes + COMMAND volume_cb_zonotopes -tc=uniform_zonotopes) + +add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_vpoly.cpp $) +add_test(NAME volume_cb_vpoly_intersection_vpoly_random_vpoly_sphere + COMMAND volume_cb_vpoly_intersection_vpoly -tc=random_vpoly_sphere) add_executable (new_rounding_test new_rounding_test.cpp $) add_test(NAME test_round_min_ellipsoid @@ -200,9 +298,61 @@ add_test(NAME test_round_svd COMMAND new_rounding_test -tc=round_svd) add_test(NAME test_round_log_barrier_test COMMAND new_rounding_test -tc=round_log_barrier_test) - - - +add_test(NAME round_max_ellipsoid_sparse + COMMAND new_rounding_test -tc=round_max_ellipsoid_sparse) + + + +add_executable (logconcave_sampling_test logconcave_sampling_test.cpp $) +add_test(NAME logconcave_sampling_test_hmc + COMMAND logconcave_sampling_test -tc=hmc) +add_test(NAME logconcave_sampling_test_uld + COMMAND logconcave_sampling_test -tc=uld) +add_test(NAME logconcave_sampling_test_exponential_biomass_sampling + COMMAND logconcave_sampling_test -tc=exponential_biomass_sampling) +add_test(NAME logconcave_sampling_test_nuts_hmc_truncated + COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated) +add_test(NAME logconcave_sampling_test_nuts_hmc + COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc) + + + +add_executable (crhmc_sampling_test crhmc_sampling_test.cpp $) +add_test(NAME crhmc_sampling_test_crhmc + COMMAND crhmc_sampling_test -tc=crhmc) +add_test(NAME crhmc_test_polytope_sampling + COMMAND crhmc_sampling_test -tc=test_polytope_sampling_crhmc) +add_test(NAME crhmc_test_sparse_sampling + COMMAND crhmc_sampling_test -tc=test_sampling_sparse_problem) +add_executable (simple_mc_integration simple_mc_integration.cpp $) +add_test(NAME simple_mc_integration_over_limits + COMMAND simple_mc_integration -tc=rectangle) +add_test(NAME simple_mc_integration_over_cubes + COMMAND simple_mc_integration -tc=cube) +add_test(NAME simple_mc_integration_over_simplices + COMMAND simple_mc_integration -tc=simplex) +add_test(NAME simple_mc_integration_over_product_simplices + COMMAND simple_mc_integration -tc=prod_simplex) +add_test(NAME simple_mc_integration_over_cross_polytopes + COMMAND simple_mc_integration -tc=cross) +add_test(NAME simple_mc_integration_over_birkhoff_polytopes + COMMAND simple_mc_integration -tc=birkhoff) + +add_executable (order_polytope order_polytope.cpp $) +add_test(NAME order_polytope_basics COMMAND order_polytope -tc=basics) +add_test(NAME order_polytope_line_intersect COMMAND order_polytope -tc=line_intersect) +add_test(NAME order_polytope_reflection COMMAND order_polytope -tc=reflection) +add_test(NAME order_polytope_vec_mult COMMAND order_polytope -tc=vec_mult) + +add_executable (matrix_sampling_test sampling_correlation_matrices_test.cpp $) +add_test(NAME test_corre_spectra_classes COMMAND matrix_sampling_test -tc=corre_spectra) +add_test(NAME test_new_ball_uniform COMMAND matrix_sampling_test -tc=new_ball_uniform) +add_test(NAME test_new_billiard_uniform COMMAND matrix_sampling_test -tc=new_billiard_uniform) +add_test(NAME test_new_accelerated_billiard_uniform COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform) +add_test(NAME test_new_ball_uniform_MT COMMAND matrix_sampling_test -tc=new_ball_uniform_MT) +add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr_uniform_MT) +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 @@ -213,7 +363,8 @@ 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) - + + set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") @@ -221,7 +372,38 @@ set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) #set_target_properties(benchmarks_crhmc_sampling # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) - - +set_target_properties(crhmc_polytope_preparation_test + PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) +set_target_properties(crhmc_sampling_test + PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) + +TARGET_LINK_LIBRARIES(new_volume_example lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(new_volume_example lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_sob_hpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_sob_vpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cg_hpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cg_vpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cb_hpolytope lp_solve coverage_config) +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(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) +TARGET_LINK_LIBRARIES(benchmarks_sob lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(benchmarks_cg lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(benchmarks_cb lp_solve ${MKL_LINK} coverage_config) +#TARGET_LINK_LIBRARIES(benchmarks_crhmc_sampling lp_solve ${MKL_LINK} QD_LIB coverage_config) +#TARGET_LINK_LIBRARIES(benchmarks_crhmc lp_solve ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(simple_mc_integration lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(ode_solvers_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(boundary_oracles_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(root_finders_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(crhmc_polytope_preparation_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +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/CMakeLists_2.txt b/test/CMakeLists_2.txt deleted file mode 100644 index 984c4d312..000000000 --- a/test/CMakeLists_2.txt +++ /dev/null @@ -1,403 +0,0 @@ -# VolEsti (volume computation and sampling library) -# Copyright (c) 2012-2020 Vissarion Fisikopoulos -# Copyright (c) 2018-2020 Apostolos Chalkis -# Copyright (c) 2021 Vaibhav Thakkar - -# Contributed and/or modified by Vaibhav Thakkar -# Contributed and/or modified by Ioannis Iakovidis -# Licensed under GNU LGPL.3, see LICENCE file - -project( VolEsti ) - -enable_testing() - -CMAKE_MINIMUM_REQUIRED(VERSION 3.11) - -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) - -# Locate Intel MKL root (in case it is enabled) - -if (APPLE) - set(MKLROOT /opt/intel/oneapi/mkl/latest) -elseif(UNIX) - set(MKLROOT /opt/intel/oneapi/mkl/latest) -endif() - - -option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) -option(BUILTIN_EIGEN "Use eigen from ../external" OFF) -option(BUILTIN_AUTODIFF "Use autodiff from ../external" ON) -option(USE_MKL "Use MKL library to build eigen" OFF) - -if(DISABLE_NLP_ORACLES) - add_definitions(-DDISABLE_NLP_ORACLES) -else() - find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) - find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) - find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) - find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - - if (NOT IFOPT) - - message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") - - elseif (NOT GMP) - - message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") - - elseif (NOT MPSOLVE) - - message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") - - elseif (NOT FFTW3) - - message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") - - else() - message(STATUS "Library ifopt found: ${IFOPT}") - message(STATUS "Library gmp found: ${GMP}") - message(STATUS "Library mpsolve found: ${MPSOLVE}") - message(STATUS "Library fftw3 found:" ${FFTW3}) - - endif(NOT IFOPT) - -endif(DISABLE_NLP_ORACLES) - -option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) - -if(DISABLE_NLP_ORACLES) - add_definitions(-DDISABLE_NLP_ORACLES) -else() - find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) - find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) - find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) - find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - - if (NOT IFOPT) - - message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") - - elseif (NOT GMP) - - message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") - - elseif (NOT MPSOLVE) - - message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") - - elseif (NOT FFTW3) - - message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") - - else() - message(STATUS "Library ifopt found: ${IFOPT}") - message(STATUS "Library gmp found: ${GMP}") - message(STATUS "Library mpsolve found: ${MPSOLVE}") - message(STATUS "Library fftw3 found:" ${FFTW3}) - - endif(NOT IFOPT) - -endif(DISABLE_NLP_ORACLES) - -if(COMMAND cmake_policy) - cmake_policy(SET CMP0003 NEW) -endif(COMMAND cmake_policy) - -include("../external/cmake-files/Autodiff.cmake") -GetAutodiff() - -include("../external/cmake-files/Eigen.cmake") -GetEigen() - -include("../external/cmake-files/Boost.cmake") -GetBoost() - -include("../external/cmake-files/LPSolve.cmake") -GetLPSolve() - -include("../external/cmake-files/QD.cmake") -GetQD() - -# Code Coverage Configuration -add_library(coverage_config INTERFACE) - -option(CODE_COVERAGE "Enable coverage reporting" OFF) -if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - # Add required flags (GCC & LLVM/Clang) - target_compile_options(coverage_config INTERFACE - -O1 # O0 (or no) optimization takes too much time and causes CircleCI test failure. - -g # generate debug info - --coverage # sets all required flags - ) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) - target_link_options(coverage_config INTERFACE --coverage) - else() - target_link_libraries(coverage_config INTERFACE --coverage) - endif() -endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - -if (BUILTIN_AUTODIFF) - include_directories (BEFORE ../../external/_deps/Autodiff) -else () - include_directories(BEFORE /usr/local/include) -endif(BUILTIN_AUTODIFF) - -set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") - -if (USE_MKL) - find_library(BLAS NAMES libblas.so libblas.dylib PATHS /usr/local/Cellar/lapack/3.9.1_1/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu /usr/local/Cellar/openblas/0.3.15_1/lib /usr/lib) - find_library(GFORTRAN NAME libgfortran.dylib PATHS /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10) - find_library(LAPACK NAME liblapack.dylib PATHS /usr/lib) - find_library(OPENMP NAME libiomp5.dylib PATHS /opt/intel/oneapi/compiler/2021.1.1/mac/compiler/lib) - include_directories (BEFORE ${MKLROOT}/include) - set(PROJECT_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES}) - set(MKL_LINK "-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl") - add_definitions(-DEIGEN_USE_MKL_ALL) -else() - set(MKL_LINK "") -endif(USE_MKL) - -include_directories (BEFORE ../external) -include_directories (BEFORE ../include) - -#for Eigen -if (${CMAKE_VERSION} VERSION_LESS "3.12.0") - add_compile_options(-D "EIGEN_NO_DEBUG") -else () - add_compile_definitions("EIGEN_NO_DEBUG") -endif () - -add_definitions(${CMAKE_CXX_FLAGS} "-g") # enable debuger -#add_definitions(${CMAKE_CXX_FLAGS} "-Wint-in-bool-context") -#add_definitions(${CMAKE_CXX_FLAGS} "-Wall") - -add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler -add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") #enable the c++17 support needed by autodiff -#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl") -add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm") -add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl") -add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR") -add_definitions(${CMAKE_CXX_FLAGS} "-DMKL_ILP64") -#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") -#add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) - -add_executable (new_volume_example new_volume_example.cpp) -add_executable (benchmarks_sob benchmarks_sob.cpp) -add_executable (benchmarks_cg benchmarks_cg.cpp) -add_executable (benchmarks_cb benchmarks_cb.cpp) - -add_library(test_main OBJECT test_main.cpp) - -add_executable (mcmc_diagnostics_test mcmc_diagnostics_test.cpp $) -add_test(NAME test_psrf COMMAND mcmc_diagnostics_test -tc=psrf) -add_test(NAME test_univariate_psrf COMMAND mcmc_diagnostics_test -tc=univariate_psrf) -add_test(NAME test_interval_psrf COMMAND mcmc_diagnostics_test -tc=interval_psrf) -add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess) -add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke) -add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery) - -add_executable (sampling_test sampling_test.cpp $) -add_test(NAME test_dikin COMMAND sampling_test -tc=dikin) -add_test(NAME test_john COMMAND sampling_test -tc=john) -add_test(NAME test_vaidya COMMAND sampling_test -tc=vaidya) -add_test(NAME test_brdhr COMMAND sampling_test -tc=brdhr) -add_test(NAME test_bcdhr COMMAND sampling_test -tc=bcdhr) -add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr) -add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw) -add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc) - -add_executable (mmcs_test mmcs_test.cpp $) -add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs) - -add_executable (ode_solvers_test ode_solvers_test.cpp $) -add_test(NAME ode_solvers_test_first_order - COMMAND ode_solvers_test -tc=first_order) -add_test(NAME ode_solvers_test_second_order - COMMAND ode_solvers_test -tc=second_order) - -add_executable (root_finders_test root_finders_test.cpp $) -add_test(NAME root_finders_test_root_finders - COMMAND root_finders_test -tc=root_finders) - -#add_executable (benchmarks_crhmc benchmarks_crhmc.cpp ) -#add_executable (benchmarks_crhmc_sampling benchmarks_crhmc_sampling.cpp ) - -add_executable (crhmc_polytope_preparation_test crhmc_polytope_preparation_test.cpp $) -add_test(NAME crhmc_polytope_test_preparation - COMMAND crhmc_polytope_preparation_test -tc=test_preparation_crhmc) -add_test(NAME crhmc_test_fixed_vars - COMMAND crhmc_polytope_preparation_test -tc=test_fixed_vars_crhmc) -add_test(NAME crhmc_test_dep_vars - COMMAND crhmc_polytope_preparation_test -tc=test_dep_vars_crhmc) -add_test(NAME crhmc_test_center_computation - COMMAND crhmc_polytope_preparation_test -tc=test_center_computation) - -add_executable (boundary_oracles_test boundary_oracles_test.cpp $) -add_test(NAME boundary_oracles_test_h_poly_oracles - COMMAND boundary_oracles_test -tc=h_poly_oracles) - -add_executable (volume_sob_hpolytope volume_sob_hpolytope.cpp $) -add_test(NAME volume_sob_hpolytope_cube COMMAND volume_sob_hpolytope -tc=cube) -add_test(NAME volume_sob_hpolytope_cross COMMAND volume_sob_hpolytope -tc=cross) -add_test(NAME volume_sob_hpolytope_birkhoff COMMAND volume_sob_hpolytope -tc=birk) -add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) -add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) -add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) -add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) -set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) - -add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) -add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) -add_test(NAME volume_sob_vpolytope_cross COMMAND volume_sob_vpolytope -tc=cross) -add_test(NAME volume_sob_vpolytope_simplex COMMAND volume_sob_vpolytope -tc=simplex) - -add_executable (volume_cg_hpolytope volume_cg_hpolytope.cpp $) -add_test(NAME volume_cg_hpolytope_cube COMMAND volume_cg_hpolytope -tc=cube) -add_test(NAME volume_cg_hpolytope_cross COMMAND volume_cg_hpolytope -tc=cross) -add_test(NAME volume_cg_hpolytope_birkhoff COMMAND volume_cg_hpolytope -tc=birk) -add_test(NAME volume_cg_hpolytope_prod_simplex COMMAND volume_cg_hpolytope -tc=prod_simplex) -add_test(NAME volume_cg_hpolytope_simplex COMMAND volume_cg_hpolytope -tc=simplex) -add_test(NAME volume_cg_hpolytope_skinny_cube COMMAND volume_cg_hpolytope -tc=skinny_cube) - -add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $) -add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube) -add_test(NAME volume_cg_vpolytope_cross COMMAND volume_cg_vpolytope -tc=cross) -add_test(NAME volume_cg_vpolytope_simplex COMMAND volume_cg_vpolytope -tc=simplex) - -add_executable (volume_cb_hpolytope volume_cb_hpolytope.cpp $) -add_test(NAME volume_cb_hpolytope_cube COMMAND volume_cb_hpolytope -tc=cube) -add_test(NAME volume_cb_hpolytope_cross COMMAND volume_cb_hpolytope -tc=cross) -add_test(NAME volume_cb_hpolytope_birkhoff COMMAND volume_cb_hpolytope -tc=birk) -add_test(NAME volume_cb_hpolytope_prod_simplex COMMAND volume_cb_hpolytope -tc=prod_simplex) -add_test(NAME volume_cb_hpolytope_simplex COMMAND volume_cb_hpolytope -tc=simplex) -add_test(NAME volume_cb_hpolytope_skinny_cube COMMAND volume_cb_hpolytope -tc=skinny_cube) - -add_executable (volume_cb_vpolytope volume_cb_vpolytope.cpp $) -add_test(NAME volume_cb_vpolytope_cube COMMAND volume_cb_vpolytope -tc=cube) -add_test(NAME volume_cb_vpolytope_cross COMMAND volume_cb_vpolytope -tc=cross) -add_test(NAME volume_cb_vpolytope_simplex COMMAND volume_cb_vpolytope -tc=simplex) - -add_executable (volume_cb_zonotopes volume_cb_zonotopes.cpp $) -add_test(NAME volume_cb_zonotopes_uniform_zonotopes - COMMAND volume_cb_zonotopes -tc=uniform_zonotopes) - -add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_vpoly.cpp $) -add_test(NAME volume_cb_vpoly_intersection_vpoly_random_vpoly_sphere - COMMAND volume_cb_vpoly_intersection_vpoly -tc=random_vpoly_sphere) - -add_executable (new_rounding_test new_rounding_test.cpp $) -add_test(NAME test_round_min_ellipsoid - COMMAND new_rounding_test -tc=round_min_ellipsoid) -add_test(NAME test_round_max_ellipsoid - COMMAND new_rounding_test -tc=round_max_ellipsoid) -add_test(NAME test_round_svd - COMMAND new_rounding_test -tc=round_svd) -add_test(NAME test_round_log_barrier_test - COMMAND new_rounding_test -tc=round_log_barrier_test) - - - -add_executable (logconcave_sampling_test logconcave_sampling_test.cpp $) -add_test(NAME logconcave_sampling_test_hmc - COMMAND logconcave_sampling_test -tc=hmc) -add_test(NAME logconcave_sampling_test_uld - COMMAND logconcave_sampling_test -tc=uld) -add_test(NAME logconcave_sampling_test_exponential_biomass_sampling - COMMAND logconcave_sampling_test -tc=exponential_biomass_sampling) -add_test(NAME logconcave_sampling_test_nuts_hmc_truncated - COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated) -add_test(NAME logconcave_sampling_test_nuts_hmc - COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc) - - - -add_executable (crhmc_sampling_test crhmc_sampling_test.cpp $) -add_test(NAME crhmc_sampling_test_crhmc - COMMAND crhmc_sampling_test -tc=crhmc) -add_test(NAME crhmc_test_polytope_sampling - COMMAND crhmc_sampling_test -tc=test_polytope_sampling_crhmc) -add_test(NAME crhmc_test_sparse_sampling - COMMAND crhmc_sampling_test -tc=test_sampling_sparse_problem) -add_executable (simple_mc_integration simple_mc_integration.cpp $) -add_test(NAME simple_mc_integration_over_limits - COMMAND simple_mc_integration -tc=rectangle) -add_test(NAME simple_mc_integration_over_cubes - COMMAND simple_mc_integration -tc=cube) -add_test(NAME simple_mc_integration_over_simplices - COMMAND simple_mc_integration -tc=simplex) -add_test(NAME simple_mc_integration_over_product_simplices - COMMAND simple_mc_integration -tc=prod_simplex) -add_test(NAME simple_mc_integration_over_cross_polytopes - COMMAND simple_mc_integration -tc=cross) -add_test(NAME simple_mc_integration_over_birkhoff_polytopes - COMMAND simple_mc_integration -tc=birkhoff) - -add_executable (order_polytope order_polytope.cpp $) -add_test(NAME order_polytope_basics COMMAND order_polytope -tc=basics) -add_test(NAME order_polytope_line_intersect COMMAND order_polytope -tc=line_intersect) -add_test(NAME order_polytope_reflection COMMAND order_polytope -tc=reflection) -add_test(NAME order_polytope_vec_mult COMMAND order_polytope -tc=vec_mult) - -add_executable (matrix_sampling_test sampling_correlation_matrices_test.cpp $) -add_test(NAME test_corre_spectra_classes COMMAND matrix_sampling_test -tc=corre_spectra) -add_test(NAME test_new_ball_uniform COMMAND matrix_sampling_test -tc=new_ball_uniform) -add_test(NAME test_new_billiard_uniform COMMAND matrix_sampling_test -tc=new_billiard_uniform) -add_test(NAME test_new_accelerated_billiard_uniform COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform) -add_test(NAME test_new_ball_uniform_MT COMMAND matrix_sampling_test -tc=new_ball_uniform_MT) -add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr_uniform_MT) -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) - -set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") - -#set_target_properties(benchmarks_crhmc -# PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -#set_target_properties(benchmarks_crhmc_sampling -# PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -set_target_properties(crhmc_polytope_preparation_test - PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -set_target_properties(crhmc_sampling_test - PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) - -TARGET_LINK_LIBRARIES(new_volume_example lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(new_volume_example lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_sob_hpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_sob_vpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cg_hpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cg_vpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cb_hpolytope lp_solve coverage_config) -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(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) -TARGET_LINK_LIBRARIES(benchmarks_sob lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(benchmarks_cg lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(benchmarks_cb lp_solve ${MKL_LINK} coverage_config) -#TARGET_LINK_LIBRARIES(benchmarks_crhmc_sampling lp_solve ${MKL_LINK} QD_LIB coverage_config) -#TARGET_LINK_LIBRARIES(benchmarks_crhmc lp_solve ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(simple_mc_integration lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(ode_solvers_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(boundary_oracles_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(root_finders_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(crhmc_polytope_preparation_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -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 index 01e2010ed..6db0698e4 100644 --- a/test/new_rounding_test.cpp +++ b/test/new_rounding_test.cpp @@ -122,6 +122,52 @@ void rounding_max_ellipsoid_test(Polytope &HP, test_values(volume, expectedBilliard, exact); } +template +void rounding_max_ellipsoid_sparse_test(double const& expectedBilliard, + double const& expected) +{ + typedef typename Polytope::PointType Point; + typedef typename Point::FT NT; + typedef typename Polytope::MT MT; + typedef typename Polytope::VT VT; + typedef typename Poset::RT RT; + typedef typename Poset::RV RV; + typedef Eigen::SparseMatrix SpMT; + + // Create Poset, 4 elements, a0 <= a1, a0 <= a2, a1 <= a3 + RV poset_data{{0, 1}, {0, 2}, {1, 3}}; + Poset poset(4, poset_data); + + // Initialize order polytope from the poset + OrderPolytope OP(poset); + OP.normalize(); + SpMT Asp = OP.get_mat(); + + + NT tol = 1e-08; + unsigned int maxiter = 500; + auto [center, radius, converged] = max_inscribed_ball(Asp, OP.get_vec(), maxiter, tol); + CHECK(OP.is_in(Point(center)) == -1); + auto [E, x0, round_val] = max_inscribed_ellipsoid_rounding(OP, Point(center)); + + MT A = MT(OP.get_mat()); + VT b = OP.get_vec(); + int d = OP.dimension(); + + Polytope HP(d, A, b); + + typedef BoostRandomNumberGenerator RNGType; + // 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 = round_val * volume_cooling_balls(HP, e, walk_len).second; + test_values(volume, expectedBilliard, expected); +} + template void rounding_log_barrier_test(Polytope &HP, double const& expectedBall, @@ -216,6 +262,16 @@ void call_test_max_ellipsoid() { rounding_max_ellipsoid_test(P, 0, 3070.64, 3188.25, 3262.61, 3200.0); } +template +void call_test_max_ellipsoid_sparse() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + + std::cout << "\n--- Testing max ellipsoid rounding of sparse Order Polytope" << std::endl; + rounding_max_ellipsoid_sparse_test(0.13979, 3070.64); +} + template void call_test_log_barrier() { typedef Cartesian Kernel; @@ -250,6 +306,10 @@ TEST_CASE("round_max_ellipsoid") { call_test_max_ellipsoid(); } +TEST_CASE("round_max_ellipsoid_sparse") { + call_test_max_ellipsoid_sparse(); +} + TEST_CASE("round_log_barrier_test") { call_test_log_barrier(); } diff --git a/test/test_internal_points.cpp b/test/test_internal_points.cpp index c8decb500..a849382a5 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -68,27 +68,16 @@ void call_test_max_ball_sparse() { OrderPolytope OP(poset); OP.normalize(); SpMT Asp = OP.get_mat(); - std::cout<<"Asp:\n" < InnerBall = OP.ComputeInnerBall(); + std::cout << "\n--- Testing Chebychev ball for sparse order Polytope" << std::endl; NT tol = 1e-08; unsigned int maxiter = 500; auto [center, radius, converged] = max_inscribed_ball(Asp, b, maxiter, tol); - std::cout<<"sparse ended\n"<(); -} \ No newline at end of file +} From d50b4cd6edbe35fd5f1bea78c908a1e933f3972a Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Mon, 24 Jun 2024 12:59:43 -0600 Subject: [PATCH 06/20] change main rounding function name --- .../volesti_lecount.cpp | 2 +- include/generators/h_polytopes_generator.h | 4 ++-- ..._rounding.hpp => inscribed_ellipsoid_rounding.hpp} | 11 +++++------ test/max_ellipsoid_rounding_test.cpp | 4 ++-- test/new_rounding_test.cpp | 8 ++++---- test/test_internal_points.cpp | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) rename include/preprocess/{max_inscribed_ellipsoid_rounding.hpp => inscribed_ellipsoid_rounding.hpp} (92%) diff --git a/examples/count-linear-extensions-using-hpolytope/volesti_lecount.cpp b/examples/count-linear-extensions-using-hpolytope/volesti_lecount.cpp index 9b0e99822..eb7133155 100644 --- a/examples/count-linear-extensions-using-hpolytope/volesti_lecount.cpp +++ b/examples/count-linear-extensions-using-hpolytope/volesti_lecount.cpp @@ -10,7 +10,7 @@ #include "volume_cooling_gaussians.hpp" #include "volume_cooling_balls.hpp" -#include "preprocess/max_inscribed_ellipsoid_rounding.hpp" +#include "preprocess/inscribed_ellipsoid_rounding.hpp" #include "preprocess/min_sampling_covering_ellipsoid_rounding.hpp" #include "preprocess/svd_rounding.hpp" diff --git a/include/generators/h_polytopes_generator.h b/include/generators/h_polytopes_generator.h index e9638b62f..0c9293baa 100644 --- a/include/generators/h_polytopes_generator.h +++ b/include/generators/h_polytopes_generator.h @@ -13,7 +13,7 @@ #include #include -#include "preprocess/max_inscribed_ellipsoid_rounding.hpp" +#include "preprocess/inscribed_ellipsoid_rounding.hpp" #ifndef isnan using std::isnan; @@ -121,7 +121,7 @@ Polytope skinny_random_hpoly(unsigned int dim, unsigned int m, const bool pre_ro if (pre_rounding) { Point x0(dim); // run only one iteration - max_inscribed_ellipsoid_rounding(P, x0, 1); + inscribed_ellipsoid_rounding(P, x0, 1); } MT cov = get_skinny_transformation(dim, eig_ratio, seed); diff --git a/include/preprocess/max_inscribed_ellipsoid_rounding.hpp b/include/preprocess/inscribed_ellipsoid_rounding.hpp similarity index 92% rename from include/preprocess/max_inscribed_ellipsoid_rounding.hpp rename to include/preprocess/inscribed_ellipsoid_rounding.hpp index d44a60b2e..4bc6d63ae 100644 --- a/include/preprocess/max_inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/inscribed_ellipsoid_rounding.hpp @@ -8,8 +8,8 @@ // Licensed under GNU LGPL.3, see LICENCE file -#ifndef MAX_ELLIPSOID_ROUNDING_HPP -#define MAX_ELLIPSOID_ROUNDING_HPP +#ifndef ELLIPSOID_ROUNDING_HPP +#define ELLIPSOID_ROUNDING_HPP #include "max_inscribed_ellipsoid.hpp" #include "analytic_center_linear_ineq.h" @@ -69,13 +69,13 @@ template typename Polytope, int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID > -std::tuple max_inscribed_ellipsoid_rounding(Polytope &P, +std::tuple inscribed_ellipsoid_rounding(Polytope &P, unsigned int const max_iterations = 5, NT const max_eig_ratio = NT(6)) { typedef typename Polytope::PointType Point; VT x = compute_feasible_point(P.get_mat(), P.get_vec()); - return max_inscribed_ellipsoid_rounding(P, Point(x), max_iterations, max_eig_ratio); + return inscribed_ellipsoid_rounding(P, Point(x), max_iterations, max_eig_ratio); } template @@ -87,7 +87,7 @@ template typename Point, int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID > -std::tuple max_inscribed_ellipsoid_rounding(Polytope &P, +std::tuple inscribed_ellipsoid_rounding(Polytope &P, Point const& InnerPoint, unsigned int const max_iterations = 5, NT const max_eig_ratio = NT(6)) @@ -105,7 +105,6 @@ std::tuple max_inscribed_ellipsoid_rounding(Polytope &P, while (true) { // compute the largest inscribed ellipsoid in P centered at x0 - //std::tie(E, center, converged) = max_inscribed_ellipsoid(P.get_mat(), P.get_vec(), x0, maxiter, tol, reg); std::tie(E, center, converged) = inscribed_ellispoid::template compute(P.get_mat(), P.get_vec(), x0, maxiter, tol, reg); diff --git a/test/max_ellipsoid_rounding_test.cpp b/test/max_ellipsoid_rounding_test.cpp index a9c25b8c1..edce7a7d2 100644 --- a/test/max_ellipsoid_rounding_test.cpp +++ b/test/max_ellipsoid_rounding_test.cpp @@ -22,7 +22,7 @@ #include "volume/volume_cooling_gaussians.hpp" #include "volume/volume_cooling_balls.hpp" -#include "preprocess/max_inscribed_ellipsoid_rounding.hpp" +#include "preprocess/inscribed_ellipsoid_rounding.hpp" #include "generators/known_polytope_generators.h" @@ -64,7 +64,7 @@ void rounding_test(Polytope &HP, RNGType rng(d); std::pair InnerBall = HP.ComputeInnerBall(); - std::tuple res = max_inscribed_ellipsoid_rounding(HP, InnerBall.first); + std::tuple res = inscribed_ellipsoid_rounding(HP, InnerBall.first); // Setup the parameters int walk_len = 10; diff --git a/test/new_rounding_test.cpp b/test/new_rounding_test.cpp index 6db0698e4..7e15c99a5 100644 --- a/test/new_rounding_test.cpp +++ b/test/new_rounding_test.cpp @@ -22,7 +22,7 @@ #include "volume/volume_cooling_balls.hpp" #include "preprocess/min_sampling_covering_ellipsoid_rounding.hpp" -#include "preprocess/max_inscribed_ellipsoid_rounding.hpp" +#include "preprocess/inscribed_ellipsoid_rounding.hpp" #include "preprocess/svd_rounding.hpp" #include "generators/known_polytope_generators.h" @@ -110,7 +110,7 @@ void rounding_max_ellipsoid_test(Polytope &HP, typedef BoostRandomNumberGenerator RNGType; RNGType rng(d); std::pair InnerBall = HP.ComputeInnerBall(); - std::tuple res = max_inscribed_ellipsoid_rounding(HP, InnerBall.first); + std::tuple res = inscribed_ellipsoid_rounding(HP, InnerBall.first); // Setup the parameters int walk_len = 1; NT e = 0.1; @@ -148,7 +148,7 @@ void rounding_max_ellipsoid_sparse_test(double const& expectedBilliard, unsigned int maxiter = 500; auto [center, radius, converged] = max_inscribed_ball(Asp, OP.get_vec(), maxiter, tol); CHECK(OP.is_in(Point(center)) == -1); - auto [E, x0, round_val] = max_inscribed_ellipsoid_rounding(OP, Point(center)); + auto [E, x0, round_val] = inscribed_ellipsoid_rounding(OP, Point(center)); MT A = MT(OP.get_mat()); VT b = OP.get_vec(); @@ -186,7 +186,7 @@ void rounding_log_barrier_test(Polytope &HP, typedef BoostRandomNumberGenerator RNGType; RNGType rng(d); std::pair InnerBall = HP.ComputeInnerBall(); - std::tuple res = max_inscribed_ellipsoid_rounding(HP, InnerBall.first); + std::tuple res = inscribed_ellipsoid_rounding(HP, InnerBall.first); // Setup the parameters int walk_len = 1; NT e = 0.1; diff --git a/test/test_internal_points.cpp b/test/test_internal_points.cpp index a849382a5..8d4df0240 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -82,7 +82,7 @@ void call_test_max_ball_sparse() { center_ << 0.207107, 0.5, 0.593398, 0.792893; CHECK(OP.is_in(Point(center)) == -1); - auto [E, x0, round_val] = max_inscribed_ellipsoid_rounding(OP, Point(center)); + auto [E, x0, round_val] = inscribed_ellipsoid_rounding(OP, Point(center)); CHECK((center - center_).norm() <= 1e-06); CHECK(std::abs(radius - 0.207107) <= 1e-06); From 6051ebc3bd4946349909b3a7e4419ab82cfcf433 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Mon, 24 Jun 2024 13:19:08 -0600 Subject: [PATCH 07/20] improve explaining comments --- include/preprocess/inscribed_ellipsoid_rounding.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/include/preprocess/inscribed_ellipsoid_rounding.hpp b/include/preprocess/inscribed_ellipsoid_rounding.hpp index 4bc6d63ae..796d3f170 100644 --- a/include/preprocess/inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/inscribed_ellipsoid_rounding.hpp @@ -70,8 +70,8 @@ template int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID > std::tuple inscribed_ellipsoid_rounding(Polytope &P, - unsigned int const max_iterations = 5, - NT const max_eig_ratio = NT(6)) + unsigned int const max_iterations = 5, + NT const max_eig_ratio = NT(6)) { typedef typename Polytope::PointType Point; VT x = compute_feasible_point(P.get_mat(), P.get_vec()); @@ -88,9 +88,9 @@ template int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID > std::tuple inscribed_ellipsoid_rounding(Polytope &P, - Point const& InnerPoint, - unsigned int const max_iterations = 5, - NT const max_eig_ratio = NT(6)) + Point const& InnerPoint, + unsigned int const max_iterations = 5, + NT const max_eig_ratio = NT(6)) { VT x0 = InnerPoint.getCoefficients(), center; MT E, L; @@ -104,7 +104,7 @@ std::tuple inscribed_ellipsoid_rounding(Polytope &P, while (true) { - // compute the largest inscribed ellipsoid in P centered at x0 + // compute the desired inscribed ellipsoid in P std::tie(E, center, converged) = inscribed_ellispoid::template compute(P.get_mat(), P.get_vec(), x0, maxiter, tol, reg); @@ -145,7 +145,6 @@ std::tuple inscribed_ellipsoid_rounding(Polytope &P, x0 = VT::Zero(d); // check the roundness of the polytope - std::cout<<"std::abs(R / r): "<= max_iterations)){ break; } From 25a39b1c36289d264c7976fd9fc3bc3d4db8a7a4 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Tue, 25 Jun 2024 09:47:54 -0600 Subject: [PATCH 08/20] resolve PR comments --- .../sampler.cpp | 10 +-- .../preprocess/analytic_center_linear_ineq.h | 6 +- include/preprocess/feasible_point.hpp | 2 +- .../inscribed_ellipsoid_rounding.hpp | 87 +++++++------------ .../preprocess/mat_computational_operator.h | 46 +++++----- include/preprocess/max_inscribed_ball.hpp | 8 +- .../preprocess/max_inscribed_ellipsoid.hpp | 2 +- test/CMakeLists.txt | 14 +-- ...ew_rounding_test.cpp => rounding_test.cpp} | 0 9 files changed, 76 insertions(+), 99 deletions(-) rename test/{new_rounding_test.cpp => rounding_test.cpp} (100%) diff --git a/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp b/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp index 6b4c74105..803d38dc3 100644 --- a/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp +++ b/examples/sampling-hpolytope-with-billiard-walks/sampler.cpp @@ -77,16 +77,12 @@ void sample_using_gaussian_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned i VT center; bool converged; std::tie(E, center, converged) = max_inscribed_ellipsoid(HP.get_mat(), - HP.get_vec(), - x0, - max_iter, - tol, - reg); + HP.get_vec(), x0, max_iter, tol, reg); + if (!converged) // not converged throw std::runtime_error("max_inscribed_ellipsoid not converged"); - MT A_ell = E; - EllipsoidType inscribed_ellipsoid(A_ell); + EllipsoidType inscribed_ellipsoid(E); // -------------------------------------------------------------------- Generator::apply(HP, q, inscribed_ellipsoid, num_points, walk_len, diff --git a/include/preprocess/analytic_center_linear_ineq.h b/include/preprocess/analytic_center_linear_ineq.h index ab188c314..aaecae544 100644 --- a/include/preprocess/analytic_center_linear_ineq.h +++ b/include/preprocess/analytic_center_linear_ineq.h @@ -12,9 +12,9 @@ #include -#include "max_inscribed_ball.hpp" -#include "feasible_point.hpp" -#include "mat_computational_operator.h" +#include "preprocess/max_inscribed_ball.hpp" +#include "preprocess/feasible_point.hpp" +#include "preprocess/mat_computational_operator.h" template NT get_max_step(VT const& Ad, VT const& b_Ax) diff --git a/include/preprocess/feasible_point.hpp b/include/preprocess/feasible_point.hpp index 42554fd91..6e7f5db0a 100644 --- a/include/preprocess/feasible_point.hpp +++ b/include/preprocess/feasible_point.hpp @@ -12,7 +12,7 @@ #include -#include "max_inscribed_ball.hpp" +#include "preprocess/max_inscribed_ball.hpp" // Using MT as to deal with both dense and sparse matrices template diff --git a/include/preprocess/inscribed_ellipsoid_rounding.hpp b/include/preprocess/inscribed_ellipsoid_rounding.hpp index 796d3f170..025557305 100644 --- a/include/preprocess/inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/inscribed_ellipsoid_rounding.hpp @@ -8,12 +8,12 @@ // Licensed under GNU LGPL.3, see LICENCE file -#ifndef ELLIPSOID_ROUNDING_HPP -#define ELLIPSOID_ROUNDING_HPP +#ifndef INSCRIBED_ELLIPSOID_ROUNDING_HPP +#define INSCRIBED_ELLIPSOID_ROUNDING_HPP -#include "max_inscribed_ellipsoid.hpp" -#include "analytic_center_linear_ineq.h" -#include "feasible_point.hpp" +#include "preprocess/max_inscribed_ellipsoid.hpp" +#include "preprocess/analytic_center_linear_ineq.h" +#include "preprocess/feasible_point.hpp" enum EllipsoidType { @@ -21,45 +21,24 @@ enum EllipsoidType LOG_BARRIER = 2 }; -template -struct inscribed_ellispoid +template +inline static std::tuple +compute_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0, + unsigned int const& maxiter, + NT const& tol, NT const& reg) { - template - inline static std::tuple - compute(Custom_MT A, VT b, VT const& x0, - unsigned int const& maxiter, - NT const& tol, NT const& reg) + if constexpr (ellipsoid_type == EllipsoidType::MAX_ELLIPSOID) { - std::runtime_error("No roudning method is defined"); - return std::tuple(); - } -}; - -template <> -struct inscribed_ellispoid -{ - template - inline static std::tuple - compute(Custom_MT A, VT b, VT const& x0, - unsigned int const& maxiter, - NT const& tol, NT const& reg) + return max_inscribed_ellipsoid(A, b, x0, maxiter, tol, reg); + } else if constexpr (ellipsoid_type == EllipsoidType::LOG_BARRIER) { - return max_inscribed_ellipsoid(A, b, x0, maxiter, tol, reg); - } -}; - -template <> -struct inscribed_ellispoid -{ - template - inline static std::tuple - compute(Custom_MT const& A, VT const& b, VT const& x0, - unsigned int const& maxiter, - NT const& tol, NT&) + return analytic_center_linear_ineq(A, b, x0); + } else { - return analytic_center_linear_ineq(A, b, x0); + std::runtime_error("Unknown rounding method."); } -}; + return {}; +} template < @@ -67,7 +46,7 @@ template typename VT, typename NT, typename Polytope, - int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID + int ellipsoid_type = EllipsoidType::MAX_ELLIPSOID > std::tuple inscribed_ellipsoid_rounding(Polytope &P, unsigned int const max_iterations = 5, @@ -85,36 +64,32 @@ template typename NT, typename Polytope, typename Point, - int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID + int ellipsoid_type = EllipsoidType::MAX_ELLIPSOID > std::tuple inscribed_ellipsoid_rounding(Polytope &P, Point const& InnerPoint, unsigned int const max_iterations = 5, NT const max_eig_ratio = NT(6)) { - VT x0 = InnerPoint.getCoefficients(), center; - MT E, L; - bool converged; unsigned int maxiter = 500, iter = 1, d = P.dimension(); - + VT x0 = InnerPoint.getCoefficients(), center, shift = VT::Zero(d); + MT E, L, T = MT::Identity(d, d); + bool converged; NT R = 100.0, r = 1.0, tol = std::pow(10, -6.0), reg = std::pow(10, -4.0), round_val = 1.0; - MT T = MT::Identity(d, d); - VT shift = VT::Zero(d); - while (true) { - // compute the desired inscribed ellipsoid in P + // Compute the desired inscribed ellipsoid in P std::tie(E, center, converged) = - inscribed_ellispoid::template compute(P.get_mat(), P.get_vec(), - x0, maxiter, tol, reg); + compute_inscribed_ellipsoid(P.get_mat(), P.get_vec(), x0, maxiter, tol, reg); + E = (E + E.transpose()) / 2.0; E += MT::Identity(d, d)*std::pow(10, -8.0); //normalize E Eigen::LLT lltOfA(E.llt().solve(MT::Identity(E.cols(), E.cols()))); // compute the Cholesky decomposition of E^{-1} L = lltOfA.matrixL(); - // computing eigenvalues of E + // Computing eigenvalues of E Spectra::DenseSymMatProd op(E); // The value of ncv is chosen empirically Spectra::SymEigsSolver inscribed_ellipsoid_rounding(Polytope &P, if (eigs.info() == Spectra::COMPUTATION_INFO::SUCCESSFUL) { R = 1.0 / eigs.eigenvalues().coeff(1); r = 1.0 / eigs.eigenvalues().coeff(0); - } else { + } else { Eigen::SelfAdjointEigenSolver eigensolver(E); if (eigensolver.info() == Eigen::ComputationInfo::Success) { R = 1.0 / eigensolver.eigenvalues().coeff(0); @@ -133,7 +108,7 @@ std::tuple inscribed_ellipsoid_rounding(Polytope &P, std::runtime_error("Computations failed."); } } - // shift polytope and apply the linear transformation on P + // Shift polytope and apply the linear transformation on P P.shift(center); shift.noalias() += T * center; T.applyOnTheRight(L); // T = T * L; @@ -144,8 +119,8 @@ std::tuple inscribed_ellipsoid_rounding(Polytope &P, P.normalize(); x0 = VT::Zero(d); - // check the roundness of the polytope - if(((std::abs(R / r) <= max_eig_ratio && converged) || iter >= max_iterations)){ + // Check the roundness of the polytope + if(((std::abs(R / r) <= max_eig_ratio && converged) || iter >= max_iterations)) { break; } diff --git a/include/preprocess/mat_computational_operator.h b/include/preprocess/mat_computational_operator.h index fb4caf7b0..880baa09b 100644 --- a/include/preprocess/mat_computational_operator.h +++ b/include/preprocess/mat_computational_operator.h @@ -7,8 +7,8 @@ // Licensed under GNU LGPL.3, see LICENCE file -#ifndef MATRIX_COMPUTATIONAL_OPERATOR_H -#define MATRIX_COMPUTATIONAL_OPERATOR_H +#ifndef MAT_COMPUTATIONAL_OPERATOR_H +#define MAT_COMPUTATIONAL_OPERATOR_H #include @@ -68,18 +68,22 @@ struct matrix_computational_operator> get_mat_prod_op(MT const& E) + inline static std::unique_ptr> + get_mat_prod_op(MT const& E) { - return std::unique_ptr>(new Spectra::DenseSymMatProd(E)); + return std::make_unique>(E); } - - inline static std::unique_ptr>> get_eigs_solver(std::unique_ptr> const& op, - int const n) + + inline static auto get_eigs_solver(std::unique_ptr> const& op, int const n) { - return std::unique_ptr>>(new Spectra::SymEigsSolver>(op.get(), 2, std::min(std::max(10, n/5), n))); + using SymDenseEigsSolver = Spectra::SymEigsSolver + < + NT, + Spectra::SELECT_EIGENVALUE::BOTH_ENDS, + Spectra::DenseSymMatProd + >; + // The value of ncv is chosen empirically + return std::make_unique(op.get(), 2, std::min(std::max(10, n/5), n)); } inline static void init_Bmat(MT &B, int const n, MT const& , MT const& ) @@ -110,8 +114,7 @@ struct matrix_computational_operator> inline static std::unique_ptr>> initialize_chol(Eigen::SparseMatrix const& mat) { - std::unique_ptr>> llt = - std::unique_ptr>>(new Eigen::SimplicialLLT>()); + auto llt = std::make_unique>>(); llt->analyzePattern(mat); return llt; } @@ -163,13 +166,16 @@ struct matrix_computational_operator> return std::unique_ptr>(new Spectra::SparseSymMatProd(E)); } - inline static std::unique_ptr>> get_eigs_solver(std::unique_ptr> const& op, - int const n) + inline static auto get_eigs_solver(std::unique_ptr> const& op, int const n) { - return std::unique_ptr>>(new Spectra::SymEigsSolver>(op.get(), 2, std::min(std::max(10, n/5), n))); + using SymSparseEigsSolver = Spectra::SymEigsSolver + < + NT, + Spectra::SELECT_EIGENVALUE::BOTH_ENDS, + Spectra::SparseSymMatProd + >; + // The value of ncv is chosen empirically + return std::make_unique(op.get(), 2, std::min(std::max(10, n/5), n)); } inline static void init_Bmat(Eigen::SparseMatrix &B, @@ -249,4 +255,4 @@ struct matrix_computational_operator> }; -#endif // MATRIX_COMPUTATIONAL_OPERATOR_H +#endif // MAT_COMPUTATIONAL_OPERATOR_H diff --git a/include/preprocess/max_inscribed_ball.hpp b/include/preprocess/max_inscribed_ball.hpp index 4e1024074..cfd1acef9 100644 --- a/include/preprocess/max_inscribed_ball.hpp +++ b/include/preprocess/max_inscribed_ball.hpp @@ -8,10 +8,10 @@ // Licensed under GNU LGPL.3, see LICENCE file -#ifndef MAX_INNER_BALL -#define MAX_INNER_BALL +#ifndef MAX_INSCRIBED_BALL_HPP +#define MAX_INSCRIBED_BALL_HPP -#include "mat_computational_operator.h" +#include "preprocess/mat_computational_operator.h" /* This implmentation computes the largest inscribed ball in a given convex polytope P. @@ -214,4 +214,4 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, return result; } -#endif +#endif // MAX_INSCRIBED_BALL_HPP diff --git a/include/preprocess/max_inscribed_ellipsoid.hpp b/include/preprocess/max_inscribed_ellipsoid.hpp index 4ab1ee4e1..7798827a5 100644 --- a/include/preprocess/max_inscribed_ellipsoid.hpp +++ b/include/preprocess/max_inscribed_ellipsoid.hpp @@ -15,7 +15,7 @@ #include #include -#include "mat_computational_operator.h" +#include "preprocess/mat_computational_operator.h" /* diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b4ef9ae02..cdda6087c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -289,17 +289,17 @@ 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 (new_rounding_test new_rounding_test.cpp $) +add_executable (rounding_test rounding_test.cpp $) add_test(NAME test_round_min_ellipsoid - COMMAND new_rounding_test -tc=round_min_ellipsoid) + COMMAND rounding_test -tc=round_min_ellipsoid) add_test(NAME test_round_max_ellipsoid - COMMAND new_rounding_test -tc=round_max_ellipsoid) + COMMAND rounding_test -tc=round_max_ellipsoid) add_test(NAME test_round_svd - COMMAND new_rounding_test -tc=round_svd) + COMMAND rounding_test -tc=round_svd) add_test(NAME test_round_log_barrier_test - COMMAND new_rounding_test -tc=round_log_barrier_test) + COMMAND rounding_test -tc=round_log_barrier_test) add_test(NAME round_max_ellipsoid_sparse - COMMAND new_rounding_test -tc=round_max_ellipsoid_sparse) + COMMAND rounding_test -tc=round_max_ellipsoid_sparse) @@ -388,7 +388,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(new_rounding_test lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(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) diff --git a/test/new_rounding_test.cpp b/test/rounding_test.cpp similarity index 100% rename from test/new_rounding_test.cpp rename to test/rounding_test.cpp From 416800265053253dc459922cb78a04b6ee1fca41 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Tue, 25 Jun 2024 09:51:48 -0600 Subject: [PATCH 09/20] changing the dates in copyrights --- include/preprocess/estimate_L_smooth_parameter.hpp | 4 ++-- include/preprocess/inscribed_ellipsoid_rounding.hpp | 4 ++-- include/preprocess/max_inscribed_ball.hpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/preprocess/estimate_L_smooth_parameter.hpp b/include/preprocess/estimate_L_smooth_parameter.hpp index 8f5a1e89c..180f20947 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-2020 Vissarion Fisikopoulos -// Copyright (c) 2018-2020 Apostolos Chalkis +// Copyright (c) 2012-2024 Vissarion Fisikopoulos +// Copyright (c) 2018-2024 Apostolos Chalkis //Contributed and/or modified by Alexandros Manochis, as part of Google Summer of Code 2020 program. diff --git a/include/preprocess/inscribed_ellipsoid_rounding.hpp b/include/preprocess/inscribed_ellipsoid_rounding.hpp index 025557305..dd20d533d 100644 --- a/include/preprocess/inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/inscribed_ellipsoid_rounding.hpp @@ -1,7 +1,7 @@ // VolEsti (volume computation and sampling library) -// Copyright (c) 2012-2020 Vissarion Fisikopoulos -// Copyright (c) 2018-2020 Apostolos Chalkis +// Copyright (c) 2012-2024 Vissarion Fisikopoulos +// Copyright (c) 2018-2024 Apostolos Chalkis //Contributed and/or modified by Alexandros Manochis, as part of Google Summer of Code 2020 program. diff --git a/include/preprocess/max_inscribed_ball.hpp b/include/preprocess/max_inscribed_ball.hpp index cfd1acef9..3ee49303c 100644 --- a/include/preprocess/max_inscribed_ball.hpp +++ b/include/preprocess/max_inscribed_ball.hpp @@ -1,7 +1,7 @@ // VolEsti (volume computation and sampling library) -// Copyright (c) 2012-2020 Vissarion Fisikopoulos -// Copyright (c) 2018-2020 Apostolos Chalkis +// Copyright (c) 2012-2024 Vissarion Fisikopoulos +// Copyright (c) 2018-2024 Apostolos Chalkis //Contributed and/or modified by Alexandros Manochis, as part of Google Summer of Code 2020 program. From 960969c6f50c070968388ac8041c49032e834125 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Tue, 25 Jun 2024 18:07:07 -0600 Subject: [PATCH 10/20] use if constexpr instead of SNIFAE --- .../preprocess/analytic_center_linear_ineq.h | 8 +- .../preprocess/mat_computational_operator.h | 326 +++++++++++------- include/preprocess/max_inscribed_ball.hpp | 12 +- .../preprocess/max_inscribed_ellipsoid.hpp | 14 +- 4 files changed, 208 insertions(+), 152 deletions(-) diff --git a/include/preprocess/analytic_center_linear_ineq.h b/include/preprocess/analytic_center_linear_ineq.h index aaecae544..bb841ef75 100644 --- a/include/preprocess/analytic_center_linear_ineq.h +++ b/include/preprocess/analytic_center_linear_ineq.h @@ -41,7 +41,7 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, // Gradient of the log-barrier function grad.noalias() = A_trans * s; // Hessian of the log-barrier function - matrix_computational_operator::update_Atrans_Diag_A(H, A_trans, A, s_sq.asDiagonal()); + update_Atrans_Diag_A(H, A_trans, A, s_sq.asDiagonal()); } /* @@ -71,7 +71,6 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT cons NT const grad_err_tol = 1e-08, NT const rel_pos_err_tol = 1e-12) { - typedef matrix_computational_operator mat_op; // Initialization VT x = x0; VT Ax = A * x; @@ -83,14 +82,13 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT cons bool converged = false; const NT tol_bnd = NT(0.01); - auto llt = mat_op::initialize_chol(A_trans*A); - + auto llt = initialize_chol(A_trans, A); get_hessian_grad_logbarrier(A, A_trans, b, x, Ax, H, grad, b_Ax); do { iter++; // Compute the direction - d.noalias() = - mat_op::solve_vec(llt, H, grad); + d.noalias() = - solve_vec(llt, H, grad); Ad.noalias() = A * d; // Compute the step length step = std::min((NT(1) - tol_bnd) * get_max_step(Ad, b_Ax), NT(1)); diff --git a/include/preprocess/mat_computational_operator.h b/include/preprocess/mat_computational_operator.h index 880baa09b..c7ee90b9c 100644 --- a/include/preprocess/mat_computational_operator.h +++ b/include/preprocess/mat_computational_operator.h @@ -17,171 +17,211 @@ #include "Spectra/include/Spectra/MatOp/SparseSymMatProd.h" -template -struct matrix_computational_operator {}; +template +struct AssertFalseType : std::false_type {}; - -// Dense matrix operator -template -struct matrix_computational_operator> +template +inline static auto +initialize_chol(MT const& mat) { - typedef Eigen::Matrix MT; - - inline static std::unique_ptr> - initialize_chol(MT const&) + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) { - return std::unique_ptr>(new Eigen::LLT()); - } - - template - inline static VT solve_vec(std::unique_ptr> const& llt, - MT const& H, VT const& b) + return std::make_unique>(); + } else if constexpr (std::is_same::value) { - llt->compute(H); - return llt->solve(b); - } - - inline static MT solve_mat(std::unique_ptr> const& llt, - MT const& E, MT const& mat, NT &logdetE) + auto llt = std::make_unique>(); + llt->analyzePattern(mat); + return llt; + } else { - llt->compute(E); - logdetE = llt->matrixL().toDenseMatrix().diagonal().array().log().sum(); - return llt->solve(mat); + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } +} - template - inline static void update_Atrans_Diag_A(MT &H, MT const& A_trans, - MT const& A, diag_MT const& D) +template +inline static auto +initialize_chol(MT const& A_trans, MT const& A) +{ + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) { - H.noalias() = A_trans * D * A; - } - - template - inline static void update_Diag_A(MT &H, diag_MT const& D, MT const& A) + return std::make_unique>(); + } else if constexpr (std::is_same::value) { - H.noalias() = D * A; - } - - template - inline static void update_A_Diag(MT &H, MT const& A, diag_MT const& D) + MT mat = A_trans * A; + return initialize_chol(mat); + } else { - H.noalias() = A * D; + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } +} - inline static std::unique_ptr> - get_mat_prod_op(MT const& E) - { - return std::make_unique>(E); - } - - inline static auto get_eigs_solver(std::unique_ptr> const& op, int const n) +template typename Eigen_llt, typename MT, typename VT> +inline static VT solve_vec(std::unique_ptr> const& llt, + MT const& H, VT const& b) +{ + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) { - using SymDenseEigsSolver = Spectra::SymEigsSolver - < - NT, - Spectra::SELECT_EIGENVALUE::BOTH_ENDS, - Spectra::DenseSymMatProd - >; - // The value of ncv is chosen empirically - return std::make_unique(op.get(), 2, std::min(std::max(10, n/5), n)); - } - - inline static void init_Bmat(MT &B, int const n, MT const& , MT const& ) + llt->compute(H); + return llt->solve(b); + } else if constexpr (std::is_same::value) { - B.resize(n+1, n+1); - } - - template - inline static void update_Bmat(MT &B, VT const& AtDe, VT const& d, - MT const& AtD, MT const& A) + llt->factorize(H); + return llt->solve(b); + } else { - const int n = A.cols(); - B.block(0, 0, n, n).noalias() = AtD * A; - B.block(0, n, n, 1).noalias() = AtDe; - B.block(n, 0, 1, n).noalias() = AtDe.transpose(); - B(n, n) = d.sum(); - B.noalias() += 1e-14 * MT::Identity(n + 1, n + 1); + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } -}; - +} -// Sparse matrix operator -template -struct matrix_computational_operator> +template typename Eigen_llt, typename MT, typename NT> +inline static Eigen::Matrix +solve_mat(std::unique_ptr> const& llt, + MT const& H, MT const& mat, NT &logdetE) { - typedef Eigen::Matrix MT; - - inline static std::unique_ptr>> - initialize_chol(Eigen::SparseMatrix const& mat) + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) { - auto llt = std::make_unique>>(); - llt->analyzePattern(mat); - return llt; - } - - template - inline static VT solve_vec(std::unique_ptr>> const& llt, - Eigen::SparseMatrix const& H, VT const& b) + llt->compute(H); + logdetE = llt->matrixL().toDenseMatrix().diagonal().array().log().sum(); + return llt->solve(mat); + } else if constexpr (std::is_same::value) { llt->factorize(H); - return llt->solve(b); - } - - inline static MT solve_mat(std::unique_ptr>> const& llt, - Eigen::SparseMatrix const& E, Eigen::SparseMatrix const& mat, NT &logdetE) - { - llt->factorize(E); logdetE = llt->matrixL().nestedExpression().diagonal().array().log().sum(); return llt->solve(mat); + } else + { + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } +} - template - inline static void update_Atrans_Diag_A(Eigen::SparseMatrix &H, - Eigen::SparseMatrix const& A_trans, - Eigen::SparseMatrix const& A, - diag_MT const& D) +template +inline static void update_Atrans_Diag_A(MT &H, MT const& A_trans, + MT const& A, diag_MT const& D) +{ + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) + { + H.noalias() = A_trans * D * A; + } else if constexpr (std::is_same::value) { H = A_trans * D * A; + } else + { + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } +} - template - inline static void update_Diag_A(Eigen::SparseMatrix &H, - diag_MT const& D, - Eigen::SparseMatrix const& A) +template +inline static void update_Diag_A(MT &H, diag_MT const& D, MT const& A) +{ + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) + { + H.noalias() = D * A; + } else if constexpr (std::is_same::value) { H = D * A; + } else + { + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } +} - template - inline static void update_A_Diag(Eigen::SparseMatrix &H, - Eigen::SparseMatrix const& A, - diag_MT const& D) +template +inline static void update_A_Diag(MT &H, MT const& A, diag_MT const& D) +{ + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) + { + H.noalias() = A * D; + } else if constexpr (std::is_same::value) { H = A * D; + } else + { + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } +} - inline static std::unique_ptr> - get_mat_prod_op(Eigen::SparseMatrix const& E) +template +inline static auto +get_mat_prod_op(MT const& E) +{ + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) + { + return std::make_unique>(E); + } else if constexpr (std::is_same::value) { - return std::unique_ptr>(new Spectra::SparseSymMatProd(E)); + return std::make_unique>(E); + } else + { + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } +} - inline static auto get_eigs_solver(std::unique_ptr> const& op, int const n) +template typename SpectraMatProd> +inline static auto get_eigs_solver(std::unique_ptr> const& op, int const n) +{ + using DenseMatProd = Spectra::DenseSymMatProd; + using SparseMatProd = Spectra::SparseSymMatProd; + if constexpr (std::is_same, DenseMatProd>::value) + { + using SymDenseEigsSolver = Spectra::SymEigsSolver + < + NT, + Spectra::SELECT_EIGENVALUE::BOTH_ENDS, + DenseMatProd + >; + // The value of ncv is chosen empirically + return std::make_unique(op.get(), 2, std::min(std::max(10, n/5), n)); + } else if constexpr (std::is_same, SparseMatProd>::value) { using SymSparseEigsSolver = Spectra::SymEigsSolver < NT, Spectra::SELECT_EIGENVALUE::BOTH_ENDS, - Spectra::SparseSymMatProd + SparseMatProd >; // The value of ncv is chosen empirically return std::make_unique(op.get(), 2, std::min(std::max(10, n/5), n)); + } else + { + static_assert(AssertFalseType>::value, + "Matrix-vector multiplication multiplication is not supported."); } +} - inline static void init_Bmat(Eigen::SparseMatrix &B, - int const n, - Eigen::SparseMatrix const& A_trans, - Eigen::SparseMatrix const& A) +template +inline static void +init_Bmat(MT &B, int const n, MT const& A_trans, MT const& A) +{ + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + if constexpr (std::is_same::value) + { + B.resize(n+1, n+1); + } else if constexpr (std::is_same::value) { // Initialize the structure of matrix B typedef Eigen::Triplet triplet; @@ -194,37 +234,51 @@ struct matrix_computational_operator> } trp.push_back(triplet(n, n, NT(1))); - Eigen::SparseMatrix ATA = A_trans * A; + MT ATA = A_trans * A; for (int k=0; k::InnerIterator it(ATA,k); it; ++it) + for (typename MT::InnerIterator it(ATA,k); it; ++it) { - if (it.row() == it.col()) continue; // Diagonal element already allocated + if (it.row() == it.col()) continue; // Diagonal elements are already allocated trp.push_back(triplet(it.row(), it.col(), NT(1))); } } B.resize(n+1, n+1); B.setFromTriplets(trp.begin(), trp.end()); + } else + { + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } +} - template - inline static void update_Bmat(Eigen::SparseMatrix &B, - VT const& AtDe, - VT const& d, - Eigen::SparseMatrix const& AtD, - Eigen::SparseMatrix const& A) - { - /* - B is (n+1)x(n+1) and AtD_A is nxn. - We set B(1:n), 1:n) = AtD_A, B(n+1, :) = AtD^T, B(:, n+1) = AtD, B(n+1, n+1) = d.sum() - */ - const int n = A.cols(); - Eigen::SparseMatrix AtD_A = AtD * A; +template +inline static void +update_Bmat(MT &B, VT const& AtDe, VT const& d, + MT const& AtD, MT const& A) +{ + using DenseMT = Eigen::Matrix; + using SparseMT = Eigen::SparseMatrix; + const int n = A.cols(); + /* + B is (n+1)x(n+1) and AtD_A is nxn. + We set B(1:n), 1:n) = AtD_A, B(n+1, :) = AtD^T, B(:, n+1) = AtD, B(n+1, n+1) = d.sum() + */ + if constexpr (std::is_same::value) + { + B.block(0, 0, n, n).noalias() = AtD * A; + B.block(0, n, n, 1).noalias() = AtDe; + B.block(n, 0, 1, n).noalias() = AtDe.transpose(); + B(n, n) = d.sum(); + B.noalias() += 1e-14 * MT::Identity(n + 1, n + 1); + } else if constexpr (std::is_same::value) + { + MT AtD_A = AtD * A; int k = 0; while(k < B.outerSize()) { - typename Eigen::SparseMatrix::InnerIterator it2(AtD_A, k <= n-1 ? k : k-1); - for (typename Eigen::SparseMatrix::InnerIterator it1(B, k); it1; ++it1) + typename MT::InnerIterator it2(AtD_A, k <= n-1 ? k : k-1); + for (typename MT::InnerIterator it1(B, k); it1; ++it1) { if (it1.row() <= n-1 && it1.col() <= n-1) { @@ -251,8 +305,12 @@ struct matrix_computational_operator> } k++; } + } else + { + static_assert(AssertFalseType::value, + "Matrix type is not supported."); } -}; +} #endif // MAT_COMPUTATIONAL_OPERATOR_H diff --git a/include/preprocess/max_inscribed_ball.hpp b/include/preprocess/max_inscribed_ball.hpp index 3ee49303c..bc463b2bb 100644 --- a/include/preprocess/max_inscribed_ball.hpp +++ b/include/preprocess/max_inscribed_ball.hpp @@ -45,7 +45,7 @@ void calcstep(MT const& A, MT const& A_trans, MT const& B, rhs.block(0,0,n,1).noalias() = r2 + A_trans * tmp; rhs(n) = r3 + tmp.sum(); - VT dxdt = matrix_computational_operator::solve_vec(llt, B, rhs); + VT dxdt = solve_vec(llt, B, rhs); dx = dxdt.block(0,0,n,1); dt = dxdt(n); @@ -65,7 +65,7 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, unsigned int maxiter, NT tol, const bool feasibility_only = false) { - typedef matrix_computational_operator mat_op; + //typedef matrix_computational_operator mat_op; int m = A.rows(), n = A.cols(); bool converge = false; @@ -90,8 +90,8 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, MT B, AtD(n, m), A_trans = A.transpose(); - mat_op::init_Bmat(B, n, A_trans, A); - auto llt = mat_op::initialize_chol(B); + init_Bmat(B, n, A_trans, A); + auto llt = initialize_chol(B); for (unsigned int i = 0; i < maxiter; ++i) { @@ -140,10 +140,10 @@ std::tuple max_inscribed_ball(MT const& A, VT const& b, vec_iter3++; vec_iter2++; } - mat_op::update_A_Diag(AtD, A_trans, d.asDiagonal()); // AtD = A_trans*d.asDiagonal() + update_A_Diag(AtD, A_trans, d.asDiagonal()); // AtD = A_trans*d.asDiagonal() AtDe.noalias() = AtD * e_m; - mat_op::update_Bmat(B, AtDe, d, AtD, A); + update_Bmat(B, AtDe, d, AtD, A); // predictor step & length calcstep(A, A_trans, B, llt, s, y, r1, r2, r3, r4, dx, ds, dt, dy, tmp, rhs); diff --git a/include/preprocess/max_inscribed_ellipsoid.hpp b/include/preprocess/max_inscribed_ellipsoid.hpp index 7798827a5..46102f50f 100644 --- a/include/preprocess/max_inscribed_ellipsoid.hpp +++ b/include/preprocess/max_inscribed_ellipsoid.hpp @@ -42,7 +42,7 @@ std::tuple max_inscribed_ellipsoid(MT A, VT b, VT const& x0, NT const& tol, NT const& reg) { typedef Eigen::DiagonalMatrix Diagonal_MT; - typedef matrix_computational_operator mat_op; + //typedef matrix_computational_operator mat_op; int m = A.rows(), n = A.cols(); bool converged = false; @@ -71,15 +71,15 @@ std::tuple max_inscribed_ellipsoid(MT A, VT b, VT const& x0, A = (ones_m.cwiseProduct(bmAx0.cwiseInverse())).asDiagonal() * A, b = ones_m; MT A_trans = A.transpose(), E2(n,n); - auto llt = mat_op::initialize_chol(A_trans*A); + auto llt = initialize_chol(A_trans, A); int i = 1; while (i <= maxiter) { Y = y.asDiagonal(); - mat_op::update_Atrans_Diag_A(E2, A_trans, A, Y); - Q.noalias() = A * mat_op::solve_mat(llt, E2, A_trans, logdetE2); + update_Atrans_Diag_A(E2, A_trans, A, Y); + Q.noalias() = A * solve_mat(llt, E2, A_trans, logdetE2); h = Q.diagonal(); h = h.cwiseSqrt(); @@ -126,8 +126,8 @@ std::tuple max_inscribed_ellipsoid(MT A, VT b, VT const& x0, NT rel, Rel; // computing eigenvalues of E2 - auto op = mat_op::get_mat_prod_op(E2); - auto eigs = mat_op::get_eigs_solver(op, n); + auto op = get_mat_prod_op(E2); + auto eigs = get_eigs_solver(op, n); eigs->init(); int nconv = eigs->compute(); if (eigs->info() == Spectra::COMPUTATION_INFO::SUCCESSFUL) { @@ -172,7 +172,7 @@ std::tuple max_inscribed_ellipsoid(MT A, VT b, VT const& x0, YQ.noalias() = Y * Q; G = YQ.cwiseProduct(YQ.transpose()); y2h = 2.0 * yh; - mat_op::update_Diag_A(YA, Y, A); // YA = Y * A; + update_Diag_A(YA, Y, A); // YA = Y * A; vec_iter1 = y2h.data(); vec_iter2 = z.data(); From da7348db6ac6761e4546ff7fccc2b56c577be8fe Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Tue, 25 Jun 2024 18:30:58 -0600 Subject: [PATCH 11/20] update the examples to cpp17 --- examples/EnvelopeProblemSOS/CMakeLists.txt | 4 ++-- .../count-linear-extensions-using-hpolytope/CMakeLists.txt | 1 + examples/crhmc_prepare/CMakeLists.txt | 1 + examples/crhmc_sampling/CMakeLists.txt | 2 +- examples/ellipsoid-sampling/CMakeLists.txt | 2 +- examples/hpolytope-volume/CMakeLists.txt | 1 + examples/logconcave/CMakeLists.txt | 2 +- examples/mmcs_method/CMakeLists.txt | 2 +- examples/multithread_sampling/CMakeLists.txt | 2 +- examples/optimization_spectrahedra/CMakeLists.txt | 1 + examples/order-polytope-basics/CMakeLists.txt | 1 + .../sampling-hpolytope-with-billiard-walks/CMakeLists.txt | 2 +- examples/volume_spectrahedron/CMakeLists.txt | 2 +- examples/vpolytope-volume/CMakeLists.txt | 1 + 14 files changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/EnvelopeProblemSOS/CMakeLists.txt b/examples/EnvelopeProblemSOS/CMakeLists.txt index e8f5b1a61..6d4e2a2a4 100644 --- a/examples/EnvelopeProblemSOS/CMakeLists.txt +++ b/examples/EnvelopeProblemSOS/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.15) project(EnvelopeProblem) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS_DEBUG_CUSTOM "-O0 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -DIPM_USE_DOUBLE -DIPM_DOUBLE=double") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG_CUSTOM}") @@ -83,4 +83,4 @@ else () target_link_directories(EnvelopeProblem PRIVATE ${OPENMP_LIBRARIES}) endif () target_link_libraries(EnvelopeProblem Python2::Python Python2::NumPy) -endif () \ No newline at end of file +endif () diff --git a/examples/count-linear-extensions-using-hpolytope/CMakeLists.txt b/examples/count-linear-extensions-using-hpolytope/CMakeLists.txt index f3e66b634..49f295303 100644 --- a/examples/count-linear-extensions-using-hpolytope/CMakeLists.txt +++ b/examples/count-linear-extensions-using-hpolytope/CMakeLists.txt @@ -98,6 +98,7 @@ 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 3575c4a46..9d99477c2 100644 --- a/examples/crhmc_prepare/CMakeLists.txt +++ b/examples/crhmc_prepare/CMakeLists.txt @@ -105,6 +105,7 @@ 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/crhmc_sampling/CMakeLists.txt b/examples/crhmc_sampling/CMakeLists.txt index 91fe46a7f..e3dddb905 100644 --- a/examples/crhmc_sampling/CMakeLists.txt +++ b/examples/crhmc_sampling/CMakeLists.txt @@ -113,7 +113,7 @@ else () endif () - add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + 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 -DTIME_KEEPING" ${ADDITIONAL_FLAGS}) # optimization of the compiler #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl") diff --git a/examples/ellipsoid-sampling/CMakeLists.txt b/examples/ellipsoid-sampling/CMakeLists.txt index b275ed9b9..d16704b17 100644 --- a/examples/ellipsoid-sampling/CMakeLists.txt +++ b/examples/ellipsoid-sampling/CMakeLists.txt @@ -99,7 +99,7 @@ else () endif () - add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++11 standard 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/hpolytope-volume/CMakeLists.txt b/examples/hpolytope-volume/CMakeLists.txt index eff88889a..ad9bb7e39 100644 --- a/examples/hpolytope-volume/CMakeLists.txt +++ b/examples/hpolytope-volume/CMakeLists.txt @@ -88,6 +88,7 @@ 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/logconcave/CMakeLists.txt b/examples/logconcave/CMakeLists.txt index 33725d0c9..cc62d286c 100644 --- a/examples/logconcave/CMakeLists.txt +++ b/examples/logconcave/CMakeLists.txt @@ -123,7 +123,7 @@ else () endif () - add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++11 standard 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/mmcs_method/CMakeLists.txt b/examples/mmcs_method/CMakeLists.txt index 01b8a040c..5ecd129f2 100644 --- a/examples/mmcs_method/CMakeLists.txt +++ b/examples/mmcs_method/CMakeLists.txt @@ -97,7 +97,7 @@ else () endif () - add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard 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/multithread_sampling/CMakeLists.txt b/examples/multithread_sampling/CMakeLists.txt index ded4b4dbb..81ad78285 100644 --- a/examples/multithread_sampling/CMakeLists.txt +++ b/examples/multithread_sampling/CMakeLists.txt @@ -97,7 +97,7 @@ else () endif () - #add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard 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/optimization_spectrahedra/CMakeLists.txt b/examples/optimization_spectrahedra/CMakeLists.txt index a35aee4c7..7c941640c 100644 --- a/examples/optimization_spectrahedra/CMakeLists.txt +++ b/examples/optimization_spectrahedra/CMakeLists.txt @@ -10,6 +10,7 @@ if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) +add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") add_executable (read_write_sdpa_file read_write_sdpa_file.cpp) diff --git a/examples/order-polytope-basics/CMakeLists.txt b/examples/order-polytope-basics/CMakeLists.txt index b45ef374c..beea52cfd 100644 --- a/examples/order-polytope-basics/CMakeLists.txt +++ b/examples/order-polytope-basics/CMakeLists.txt @@ -15,6 +15,7 @@ if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) +add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) option(BUILTIN_EIGEN "Use eigen from ../../external" OFF) diff --git a/examples/sampling-hpolytope-with-billiard-walks/CMakeLists.txt b/examples/sampling-hpolytope-with-billiard-walks/CMakeLists.txt index c10fb041c..5c47fe0ad 100644 --- a/examples/sampling-hpolytope-with-billiard-walks/CMakeLists.txt +++ b/examples/sampling-hpolytope-with-billiard-walks/CMakeLists.txt @@ -102,7 +102,7 @@ else () endif () - add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard 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/volume_spectrahedron/CMakeLists.txt b/examples/volume_spectrahedron/CMakeLists.txt index 424c457b3..57ecd27e0 100644 --- a/examples/volume_spectrahedron/CMakeLists.txt +++ b/examples/volume_spectrahedron/CMakeLists.txt @@ -98,7 +98,7 @@ else () endif () - add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard 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/vpolytope-volume/CMakeLists.txt b/examples/vpolytope-volume/CMakeLists.txt index e1a0c2576..2f7020fb1 100644 --- a/examples/vpolytope-volume/CMakeLists.txt +++ b/examples/vpolytope-volume/CMakeLists.txt @@ -91,6 +91,7 @@ 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") From 035cfe82643f1b268901376a13bba11827a379b4 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Tue, 25 Jun 2024 19:19:47 -0600 Subject: [PATCH 12/20] update to cpp17 order polytope example --- examples/order-polytope-basics/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/order-polytope-basics/CMakeLists.txt b/examples/order-polytope-basics/CMakeLists.txt index beea52cfd..70026f61b 100644 --- a/examples/order-polytope-basics/CMakeLists.txt +++ b/examples/order-polytope-basics/CMakeLists.txt @@ -15,7 +15,6 @@ if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) -add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) option(BUILTIN_EIGEN "Use eigen from ../../external" OFF) @@ -100,7 +99,7 @@ else () endif () - add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard + add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl") add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm") From 9b72f5f580a054bd80334ffd080a4e9fee99291b Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Wed, 26 Jun 2024 16:26:19 -0600 Subject: [PATCH 13/20] fix templating in mat_computational_operators --- include/preprocess/mat_computational_operator.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/preprocess/mat_computational_operator.h b/include/preprocess/mat_computational_operator.h index c7ee90b9c..bd921bb34 100644 --- a/include/preprocess/mat_computational_operator.h +++ b/include/preprocess/mat_computational_operator.h @@ -61,7 +61,7 @@ initialize_chol(MT const& A_trans, MT const& A) } } -template typename Eigen_llt, typename MT, typename VT> +template typename Eigen_llt, typename MT, typename VT> inline static VT solve_vec(std::unique_ptr> const& llt, MT const& H, VT const& b) { @@ -82,7 +82,7 @@ inline static VT solve_vec(std::unique_ptr> const& llt, } } -template typename Eigen_llt, typename MT, typename NT> +template typename Eigen_llt, typename MT, typename NT> inline static Eigen::Matrix solve_mat(std::unique_ptr> const& llt, MT const& H, MT const& mat, NT &logdetE) @@ -180,7 +180,7 @@ get_mat_prod_op(MT const& E) } } -template typename SpectraMatProd> +template typename SpectraMatProd> inline static auto get_eigs_solver(std::unique_ptr> const& op, int const n) { using DenseMatProd = Spectra::DenseSymMatProd; From 11b494892e792a1044ba29990372504aaa9cb441 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Wed, 26 Jun 2024 16:54:36 -0600 Subject: [PATCH 14/20] fix templating errors and change header file to mat_computational_operators --- .../preprocess/analytic_center_linear_ineq.h | 2 +- ...erator.h => mat_computational_operators.h} | 24 +++++++++---------- include/preprocess/max_inscribed_ball.hpp | 2 +- .../preprocess/max_inscribed_ellipsoid.hpp | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) rename include/preprocess/{mat_computational_operator.h => mat_computational_operators.h} (92%) diff --git a/include/preprocess/analytic_center_linear_ineq.h b/include/preprocess/analytic_center_linear_ineq.h index bb841ef75..80d731f6c 100644 --- a/include/preprocess/analytic_center_linear_ineq.h +++ b/include/preprocess/analytic_center_linear_ineq.h @@ -14,7 +14,7 @@ #include "preprocess/max_inscribed_ball.hpp" #include "preprocess/feasible_point.hpp" -#include "preprocess/mat_computational_operator.h" +#include "preprocess/mat_computational_operators.h" template NT get_max_step(VT const& Ad, VT const& b_Ax) diff --git a/include/preprocess/mat_computational_operator.h b/include/preprocess/mat_computational_operators.h similarity index 92% rename from include/preprocess/mat_computational_operator.h rename to include/preprocess/mat_computational_operators.h index bd921bb34..af200d221 100644 --- a/include/preprocess/mat_computational_operator.h +++ b/include/preprocess/mat_computational_operators.h @@ -7,8 +7,8 @@ // Licensed under GNU LGPL.3, see LICENCE file -#ifndef MAT_COMPUTATIONAL_OPERATOR_H -#define MAT_COMPUTATIONAL_OPERATOR_H +#ifndef MAT_COMPUTATIONAL_OPERATORS_H +#define MAT_COMPUTATIONAL_OPERATORS_H #include @@ -61,8 +61,8 @@ initialize_chol(MT const& A_trans, MT const& A) } } -template typename Eigen_llt, typename MT, typename VT> -inline static VT solve_vec(std::unique_ptr> const& llt, +template +inline static VT solve_vec(std::unique_ptr const& llt, MT const& H, VT const& b) { using DenseMT = Eigen::Matrix; @@ -82,9 +82,9 @@ inline static VT solve_vec(std::unique_ptr> const& llt, } } -template typename Eigen_llt, typename MT, typename NT> +template inline static Eigen::Matrix -solve_mat(std::unique_ptr> const& llt, +solve_mat(std::unique_ptr const& llt, MT const& H, MT const& mat, NT &logdetE) { using DenseMT = Eigen::Matrix; @@ -180,12 +180,12 @@ get_mat_prod_op(MT const& E) } } -template typename SpectraMatProd> -inline static auto get_eigs_solver(std::unique_ptr> const& op, int const n) +template +inline static auto get_eigs_solver(std::unique_ptr const& op, int const n) { using DenseMatProd = Spectra::DenseSymMatProd; using SparseMatProd = Spectra::SparseSymMatProd; - if constexpr (std::is_same, DenseMatProd>::value) + if constexpr (std::is_same::value) { using SymDenseEigsSolver = Spectra::SymEigsSolver < @@ -195,7 +195,7 @@ inline static auto get_eigs_solver(std::unique_ptr> const& op >; // The value of ncv is chosen empirically return std::make_unique(op.get(), 2, std::min(std::max(10, n/5), n)); - } else if constexpr (std::is_same, SparseMatProd>::value) + } else if constexpr (std::is_same::value) { using SymSparseEigsSolver = Spectra::SymEigsSolver < @@ -207,7 +207,7 @@ inline static auto get_eigs_solver(std::unique_ptr> const& op return std::make_unique(op.get(), 2, std::min(std::max(10, n/5), n)); } else { - static_assert(AssertFalseType>::value, + static_assert(AssertFalseType::value, "Matrix-vector multiplication multiplication is not supported."); } } @@ -313,4 +313,4 @@ update_Bmat(MT &B, VT const& AtDe, VT const& d, } -#endif // MAT_COMPUTATIONAL_OPERATOR_H +#endif // MAT_COMPUTATIONAL_OPERATORS_H diff --git a/include/preprocess/max_inscribed_ball.hpp b/include/preprocess/max_inscribed_ball.hpp index bc463b2bb..573813dd7 100644 --- a/include/preprocess/max_inscribed_ball.hpp +++ b/include/preprocess/max_inscribed_ball.hpp @@ -11,7 +11,7 @@ #ifndef MAX_INSCRIBED_BALL_HPP #define MAX_INSCRIBED_BALL_HPP -#include "preprocess/mat_computational_operator.h" +#include "preprocess/mat_computational_operators.h" /* This implmentation computes the largest inscribed ball in a given convex polytope P. diff --git a/include/preprocess/max_inscribed_ellipsoid.hpp b/include/preprocess/max_inscribed_ellipsoid.hpp index 46102f50f..f44f60ff0 100644 --- a/include/preprocess/max_inscribed_ellipsoid.hpp +++ b/include/preprocess/max_inscribed_ellipsoid.hpp @@ -15,7 +15,7 @@ #include #include -#include "preprocess/mat_computational_operator.h" +#include "preprocess/mat_computational_operators.h" /* From e5738acbea9348445c576eaea23c6cf46aaac8cd Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Fri, 28 Jun 2024 19:21:32 -0600 Subject: [PATCH 15/20] first implementation of the volumetric barrier ellipsoid --- ...r_ineq.h => analytic_center_ellipsoid.hpp} | 40 +- .../inscribed_ellipsoid_rounding.hpp | 4 +- ...tors.h => mat_computational_operators.hpp} | 21 +- include/preprocess/max_inscribed_ball.hpp | 2 +- .../preprocess/max_inscribed_ellipsoid.hpp | 2 +- .../volumetric_center_ellipsoid.hpp | 133 ++++++ test/CMakeLists.txt | 184 +------- test/CMakeLists_2.txt | 409 ++++++++++++++++++ test/test_internal_points.cpp | 51 ++- 9 files changed, 627 insertions(+), 219 deletions(-) rename include/preprocess/{analytic_center_linear_ineq.h => analytic_center_ellipsoid.hpp} (72%) rename include/preprocess/{mat_computational_operators.h => mat_computational_operators.hpp} (94%) create mode 100644 include/preprocess/volumetric_center_ellipsoid.hpp create mode 100644 test/CMakeLists_2.txt diff --git a/include/preprocess/analytic_center_linear_ineq.h b/include/preprocess/analytic_center_ellipsoid.hpp similarity index 72% rename from include/preprocess/analytic_center_linear_ineq.h rename to include/preprocess/analytic_center_ellipsoid.hpp index 80d731f6c..5328b8507 100644 --- a/include/preprocess/analytic_center_linear_ineq.h +++ b/include/preprocess/analytic_center_ellipsoid.hpp @@ -7,29 +7,15 @@ // Licensed under GNU LGPL.3, see LICENCE file -#ifndef ANALYTIC_CENTER_H -#define ANALYTIC_CENTER_H +#ifndef ANALYTIC_CENTER_ELLIPSOID_HPP +#define ANALYTIC_CENTER_ELLIPSOID_HPP #include #include "preprocess/max_inscribed_ball.hpp" #include "preprocess/feasible_point.hpp" -#include "preprocess/mat_computational_operators.h" +#include "preprocess/mat_computational_operators.hpp" -template -NT get_max_step(VT const& Ad, VT const& b_Ax) -{ - const int m = Ad.size(); - NT max_element = std::numeric_limits::lowest(), max_element_temp; - for (int i = 0; i < m; i++) { - max_element_temp = Ad.coeff(i) / b_Ax.coeff(i); - if (max_element_temp > max_element) { - max_element = max_element_temp; - } - } - - return NT(1) / max_element; -} template void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, @@ -66,10 +52,10 @@ void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, Note: Using MT as to deal with both dense and sparse matrices, MT_dense will be the type of result matrix */ template -std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, VT const& x0, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) +std::tuple analytic_center_ellipsoid_linear_ineq(MT const& A, VT const& b, VT const& x0, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) { // Initialization VT x = x0; @@ -122,13 +108,13 @@ std::tuple analytic_center_linear_ineq(MT const& A, VT cons } template -std::tuple analytic_center_linear_ineq(MT const& A, VT const& b, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) +std::tuple analytic_center_ellipsoid_linear_ineq(MT const& A, VT const& b, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) { VT x0 = compute_feasible_point(A, b); - return analytic_center_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); + return analytic_center_ellipsoid_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); } -#endif +#endif // ANALYTIC_CENTER_ELLIPSOID_HPP diff --git a/include/preprocess/inscribed_ellipsoid_rounding.hpp b/include/preprocess/inscribed_ellipsoid_rounding.hpp index dd20d533d..5986fb488 100644 --- a/include/preprocess/inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/inscribed_ellipsoid_rounding.hpp @@ -12,7 +12,7 @@ #define INSCRIBED_ELLIPSOID_ROUNDING_HPP #include "preprocess/max_inscribed_ellipsoid.hpp" -#include "preprocess/analytic_center_linear_ineq.h" +#include "preprocess/analytic_center_ellipsoid.hpp" #include "preprocess/feasible_point.hpp" enum EllipsoidType @@ -32,7 +32,7 @@ compute_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0, return max_inscribed_ellipsoid(A, b, x0, maxiter, tol, reg); } else if constexpr (ellipsoid_type == EllipsoidType::LOG_BARRIER) { - return analytic_center_linear_ineq(A, b, x0); + return analytic_center_ellipsoid_linear_ineq(A, b, x0); } else { std::runtime_error("Unknown rounding method."); diff --git a/include/preprocess/mat_computational_operators.h b/include/preprocess/mat_computational_operators.hpp similarity index 94% rename from include/preprocess/mat_computational_operators.h rename to include/preprocess/mat_computational_operators.hpp index af200d221..f95860ea2 100644 --- a/include/preprocess/mat_computational_operators.h +++ b/include/preprocess/mat_computational_operators.hpp @@ -7,8 +7,8 @@ // Licensed under GNU LGPL.3, see LICENCE file -#ifndef MAT_COMPUTATIONAL_OPERATORS_H -#define MAT_COMPUTATIONAL_OPERATORS_H +#ifndef MAT_COMPUTATIONAL_OPERATORS_HPP +#define MAT_COMPUTATIONAL_OPERATORS_HPP #include @@ -20,6 +20,21 @@ template struct AssertFalseType : std::false_type {}; +template +NT get_max_step(VT const& Ad, VT const& b_Ax) +{ + const int m = Ad.size(); + NT max_element = std::numeric_limits::lowest(), max_element_temp; + for (int i = 0; i < m; i++) { + max_element_temp = Ad.coeff(i) / b_Ax.coeff(i); + if (max_element_temp > max_element) { + max_element = max_element_temp; + } + } + + return NT(1) / max_element; +} + template inline static auto initialize_chol(MT const& mat) @@ -313,4 +328,4 @@ update_Bmat(MT &B, VT const& AtDe, VT const& d, } -#endif // MAT_COMPUTATIONAL_OPERATORS_H +#endif // MAT_COMPUTATIONAL_OPERATORS_HPP diff --git a/include/preprocess/max_inscribed_ball.hpp b/include/preprocess/max_inscribed_ball.hpp index 573813dd7..2cfe68929 100644 --- a/include/preprocess/max_inscribed_ball.hpp +++ b/include/preprocess/max_inscribed_ball.hpp @@ -11,7 +11,7 @@ #ifndef MAX_INSCRIBED_BALL_HPP #define MAX_INSCRIBED_BALL_HPP -#include "preprocess/mat_computational_operators.h" +#include "preprocess/mat_computational_operators.hpp" /* This implmentation computes the largest inscribed ball in a given convex polytope P. diff --git a/include/preprocess/max_inscribed_ellipsoid.hpp b/include/preprocess/max_inscribed_ellipsoid.hpp index f44f60ff0..74f6c0b4d 100644 --- a/include/preprocess/max_inscribed_ellipsoid.hpp +++ b/include/preprocess/max_inscribed_ellipsoid.hpp @@ -15,7 +15,7 @@ #include #include -#include "preprocess/mat_computational_operators.h" +#include "preprocess/mat_computational_operators.hpp" /* diff --git a/include/preprocess/volumetric_center_ellipsoid.hpp b/include/preprocess/volumetric_center_ellipsoid.hpp new file mode 100644 index 000000000..b2081ccae --- /dev/null +++ b/include/preprocess/volumetric_center_ellipsoid.hpp @@ -0,0 +1,133 @@ +// VolEsti (volume computation and sampling library) + +// Copyright (c) 2024 Vissarion Fisikopoulos +// Copyright (c) 2024 Apostolos Chalkis +// Copyright (c) 2024 Elias Tsigaridas + +// Licensed under GNU LGPL.3, see LICENCE file + + +#ifndef VOLUMETRIC_CENTER_ELLIPSOID_HPP +#define VOLUMETRIC_CENTER_ELLIPSOID_HPP + +#include + +#include "preprocess/max_inscribed_ball.hpp" +#include "preprocess/feasible_point.hpp" +#include "preprocess/mat_computational_operators.hpp" + +template +void get_hessian_grad_volumetric_barrier(MT const& A, MT const& A_trans, VT const& b, + VT const& x, VT const& Ax, llt_type const& llt, + MT &H, VT &grad, VT &b_Ax, NT &obj_val) +{ + b_Ax.noalias() = b - Ax; + VT s = b_Ax.cwiseInverse(); + VT s_sq = s.cwiseProduct(s); + // Hessian of the log-barrier function + update_Atrans_Diag_A(H, A_trans, A, s_sq.asDiagonal()); + // Computing sigma(x)_i = (a_i^T H^{-1} a_i) / (b_i - a_i^Tx)^2 + MT_dense HA = solve_mat(llt, H, A_trans, obj_val); + MT_dense aiHai = HA.transpose().cwiseProduct(A); + VT sigma = (aiHai.rowwise().sum()).cwiseProduct(s_sq); + // Gradient of the volumetric barrier function + grad.noalias() = A_trans * (s.cwiseProduct(sigma)); + // Hessian of the volumetric barrier function + update_Atrans_Diag_A(H, A_trans, A, s_sq.cwiseProduct(sigma).asDiagonal()); + //std::cout<<"H:\n"< +std::tuple volumetric_center_ellipsoid_linear_ineq(MT const& A, VT const& b, VT const& x0, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) +{ + // Initialization + VT x = x0; + VT Ax = A * x; + const int n = A.cols(), m = A.rows(); + MT H(n, n), A_trans = A.transpose(); + VT grad(n), d(n), Ad(m), b_Ax(m), step_d(n), x_prev; + NT grad_err, rel_pos_err, rel_pos_err_temp, step, obj_val, obj_val_prev; + unsigned int iter = 0; + bool converged = false; + const NT tol_bnd = NT(0.01), tol_obj = NT(1e-06); + NT step_iter = NT(0.5); + + auto llt = initialize_chol(A_trans, A); + get_hessian_grad_volumetric_barrier(A, A_trans, b, x, Ax, llt, + H, grad, b_Ax, obj_val); + do { + iter++; + // Compute the direction + d.noalias() = - solve_vec(llt, H, grad); + Ad.noalias() = A * d; + // Compute the step length + step = std::min(NT(0.4) * get_max_step(Ad, b_Ax), step_iter); + step_d.noalias() = step*d; + x_prev = x; + x += step_d; + Ax.noalias() += step*Ad; + + // Compute the max_i\{ |step*d_i| ./ |x_i| \} + rel_pos_err = std::numeric_limits::lowest(); + for (int i = 0; i < n; i++) + { + rel_pos_err_temp = std::abs(step_d.coeff(i) / x_prev.coeff(i)); + if (rel_pos_err_temp > rel_pos_err) + { + rel_pos_err = rel_pos_err_temp; + } + } + + obj_val_prev = obj_val; + get_hessian_grad_volumetric_barrier(A, A_trans, b, x, Ax, llt, + H, grad, b_Ax, obj_val); + grad_err = grad.norm(); + std::cout<<"iter: "<= max_iters || grad_err <= grad_err_tol || rel_pos_err <= rel_pos_err_tol) + { + converged = true; + break; + } + step_iter *= NT(0.999); + } while (true); + + return std::make_tuple(MT_dense(H), x, converged); +} + +template +std::tuple volumetric_center_ellipsoid_linear_ineq(MT const& A, VT const& b, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) +{ + VT x0 = compute_feasible_point(A, b); + std::cout<<"x0: "<(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); +} + +#endif // VOLUMETRIC_CENTER_ELLIPSOID_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cdda6087c..be42255d9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -185,109 +185,13 @@ add_definitions(${CMAKE_CXX_FLAGS} "-DMKL_ILP64") #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") #add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) -add_executable (new_volume_example new_volume_example.cpp) -add_executable (benchmarks_sob benchmarks_sob.cpp) -add_executable (benchmarks_cg benchmarks_cg.cpp) -add_executable (benchmarks_cb benchmarks_cb.cpp) -add_library(test_main OBJECT test_main.cpp) -add_executable (mcmc_diagnostics_test mcmc_diagnostics_test.cpp $) -add_test(NAME test_psrf COMMAND mcmc_diagnostics_test -tc=psrf) -add_test(NAME test_univariate_psrf COMMAND mcmc_diagnostics_test -tc=univariate_psrf) -add_test(NAME test_interval_psrf COMMAND mcmc_diagnostics_test -tc=interval_psrf) -add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess) -add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke) -add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery) - -add_executable (sampling_test sampling_test.cpp $) -add_test(NAME test_dikin COMMAND sampling_test -tc=dikin) -add_test(NAME test_john COMMAND sampling_test -tc=john) -add_test(NAME test_vaidya COMMAND sampling_test -tc=vaidya) -add_test(NAME test_brdhr COMMAND sampling_test -tc=brdhr) -add_test(NAME test_bcdhr COMMAND sampling_test -tc=bcdhr) -add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr) -add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw) -add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc) - -add_executable (mmcs_test mmcs_test.cpp $) -add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs) - -add_executable (ode_solvers_test ode_solvers_test.cpp $) -add_test(NAME ode_solvers_test_first_order - COMMAND ode_solvers_test -tc=first_order) -add_test(NAME ode_solvers_test_second_order - COMMAND ode_solvers_test -tc=second_order) - -add_executable (root_finders_test root_finders_test.cpp $) -add_test(NAME root_finders_test_root_finders - COMMAND root_finders_test -tc=root_finders) +add_library(test_main OBJECT test_main.cpp) #add_executable (benchmarks_crhmc benchmarks_crhmc.cpp ) #add_executable (benchmarks_crhmc_sampling benchmarks_crhmc_sampling.cpp ) -add_executable (crhmc_polytope_preparation_test crhmc_polytope_preparation_test.cpp $) -add_test(NAME crhmc_polytope_test_preparation - COMMAND crhmc_polytope_preparation_test -tc=test_preparation_crhmc) -add_test(NAME crhmc_test_fixed_vars - COMMAND crhmc_polytope_preparation_test -tc=test_fixed_vars_crhmc) -add_test(NAME crhmc_test_dep_vars - COMMAND crhmc_polytope_preparation_test -tc=test_dep_vars_crhmc) -add_test(NAME crhmc_test_center_computation - COMMAND crhmc_polytope_preparation_test -tc=test_center_computation) - -add_executable (boundary_oracles_test boundary_oracles_test.cpp $) -add_test(NAME boundary_oracles_test_h_poly_oracles - COMMAND boundary_oracles_test -tc=h_poly_oracles) - -add_executable (volume_sob_hpolytope volume_sob_hpolytope.cpp $) -add_test(NAME volume_sob_hpolytope_cube COMMAND volume_sob_hpolytope -tc=cube) -add_test(NAME volume_sob_hpolytope_cross COMMAND volume_sob_hpolytope -tc=cross) -add_test(NAME volume_sob_hpolytope_birkhoff COMMAND volume_sob_hpolytope -tc=birk) -add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) -add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) -add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) -add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) -set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) - -add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) -add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) -add_test(NAME volume_sob_vpolytope_cross COMMAND volume_sob_vpolytope -tc=cross) -add_test(NAME volume_sob_vpolytope_simplex COMMAND volume_sob_vpolytope -tc=simplex) - -add_executable (volume_cg_hpolytope volume_cg_hpolytope.cpp $) -add_test(NAME volume_cg_hpolytope_cube COMMAND volume_cg_hpolytope -tc=cube) -add_test(NAME volume_cg_hpolytope_cross COMMAND volume_cg_hpolytope -tc=cross) -add_test(NAME volume_cg_hpolytope_birkhoff COMMAND volume_cg_hpolytope -tc=birk) -add_test(NAME volume_cg_hpolytope_prod_simplex COMMAND volume_cg_hpolytope -tc=prod_simplex) -add_test(NAME volume_cg_hpolytope_simplex COMMAND volume_cg_hpolytope -tc=simplex) -add_test(NAME volume_cg_hpolytope_skinny_cube COMMAND volume_cg_hpolytope -tc=skinny_cube) - -add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $) -add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube) -add_test(NAME volume_cg_vpolytope_cross COMMAND volume_cg_vpolytope -tc=cross) -add_test(NAME volume_cg_vpolytope_simplex COMMAND volume_cg_vpolytope -tc=simplex) - -add_executable (volume_cb_hpolytope volume_cb_hpolytope.cpp $) -add_test(NAME volume_cb_hpolytope_cube COMMAND volume_cb_hpolytope -tc=cube) -add_test(NAME volume_cb_hpolytope_cross COMMAND volume_cb_hpolytope -tc=cross) -add_test(NAME volume_cb_hpolytope_birkhoff COMMAND volume_cb_hpolytope -tc=birk) -add_test(NAME volume_cb_hpolytope_prod_simplex COMMAND volume_cb_hpolytope -tc=prod_simplex) -add_test(NAME volume_cb_hpolytope_simplex COMMAND volume_cb_hpolytope -tc=simplex) -add_test(NAME volume_cb_hpolytope_skinny_cube COMMAND volume_cb_hpolytope -tc=skinny_cube) - -add_executable (volume_cb_vpolytope volume_cb_vpolytope.cpp $) -add_test(NAME volume_cb_vpolytope_cube COMMAND volume_cb_vpolytope -tc=cube) -add_test(NAME volume_cb_vpolytope_cross COMMAND volume_cb_vpolytope -tc=cross) -add_test(NAME volume_cb_vpolytope_simplex COMMAND volume_cb_vpolytope -tc=simplex) - -add_executable (volume_cb_zonotopes volume_cb_zonotopes.cpp $) -add_test(NAME volume_cb_zonotopes_uniform_zonotopes - COMMAND volume_cb_zonotopes -tc=uniform_zonotopes) - -add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_vpoly.cpp $) -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_test(NAME test_round_min_ellipsoid @@ -302,58 +206,6 @@ add_test(NAME round_max_ellipsoid_sparse COMMAND rounding_test -tc=round_max_ellipsoid_sparse) - -add_executable (logconcave_sampling_test logconcave_sampling_test.cpp $) -add_test(NAME logconcave_sampling_test_hmc - COMMAND logconcave_sampling_test -tc=hmc) -add_test(NAME logconcave_sampling_test_uld - COMMAND logconcave_sampling_test -tc=uld) -add_test(NAME logconcave_sampling_test_exponential_biomass_sampling - COMMAND logconcave_sampling_test -tc=exponential_biomass_sampling) -add_test(NAME logconcave_sampling_test_nuts_hmc_truncated - COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated) -add_test(NAME logconcave_sampling_test_nuts_hmc - COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc) - - - -add_executable (crhmc_sampling_test crhmc_sampling_test.cpp $) -add_test(NAME crhmc_sampling_test_crhmc - COMMAND crhmc_sampling_test -tc=crhmc) -add_test(NAME crhmc_test_polytope_sampling - COMMAND crhmc_sampling_test -tc=test_polytope_sampling_crhmc) -add_test(NAME crhmc_test_sparse_sampling - COMMAND crhmc_sampling_test -tc=test_sampling_sparse_problem) -add_executable (simple_mc_integration simple_mc_integration.cpp $) -add_test(NAME simple_mc_integration_over_limits - COMMAND simple_mc_integration -tc=rectangle) -add_test(NAME simple_mc_integration_over_cubes - COMMAND simple_mc_integration -tc=cube) -add_test(NAME simple_mc_integration_over_simplices - COMMAND simple_mc_integration -tc=simplex) -add_test(NAME simple_mc_integration_over_product_simplices - COMMAND simple_mc_integration -tc=prod_simplex) -add_test(NAME simple_mc_integration_over_cross_polytopes - COMMAND simple_mc_integration -tc=cross) -add_test(NAME simple_mc_integration_over_birkhoff_polytopes - COMMAND simple_mc_integration -tc=birkhoff) - -add_executable (order_polytope order_polytope.cpp $) -add_test(NAME order_polytope_basics COMMAND order_polytope -tc=basics) -add_test(NAME order_polytope_line_intersect COMMAND order_polytope -tc=line_intersect) -add_test(NAME order_polytope_reflection COMMAND order_polytope -tc=reflection) -add_test(NAME order_polytope_vec_mult COMMAND order_polytope -tc=vec_mult) - -add_executable (matrix_sampling_test sampling_correlation_matrices_test.cpp $) -add_test(NAME test_corre_spectra_classes COMMAND matrix_sampling_test -tc=corre_spectra) -add_test(NAME test_new_ball_uniform COMMAND matrix_sampling_test -tc=new_ball_uniform) -add_test(NAME test_new_billiard_uniform COMMAND matrix_sampling_test -tc=new_billiard_uniform) -add_test(NAME test_new_accelerated_billiard_uniform COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform) -add_test(NAME test_new_ball_uniform_MT COMMAND matrix_sampling_test -tc=new_ball_uniform_MT) -add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr_uniform_MT) -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) @@ -372,38 +224,6 @@ set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) #set_target_properties(benchmarks_crhmc_sampling # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -set_target_properties(crhmc_polytope_preparation_test - PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -set_target_properties(crhmc_sampling_test - PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) - -TARGET_LINK_LIBRARIES(new_volume_example lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(new_volume_example lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_sob_hpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_sob_vpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cg_hpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cg_vpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cb_hpolytope lp_solve coverage_config) -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(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) -TARGET_LINK_LIBRARIES(benchmarks_sob lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(benchmarks_cg lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(benchmarks_cb lp_solve ${MKL_LINK} coverage_config) -#TARGET_LINK_LIBRARIES(benchmarks_crhmc_sampling lp_solve ${MKL_LINK} QD_LIB coverage_config) -#TARGET_LINK_LIBRARIES(benchmarks_crhmc lp_solve ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(simple_mc_integration lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(ode_solvers_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(boundary_oracles_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(root_finders_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(crhmc_polytope_preparation_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -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/CMakeLists_2.txt b/test/CMakeLists_2.txt new file mode 100644 index 000000000..cdda6087c --- /dev/null +++ b/test/CMakeLists_2.txt @@ -0,0 +1,409 @@ +# VolEsti (volume computation and sampling library) +# Copyright (c) 2012-2020 Vissarion Fisikopoulos +# Copyright (c) 2018-2020 Apostolos Chalkis +# Copyright (c) 2021 Vaibhav Thakkar + +# Contributed and/or modified by Vaibhav Thakkar +# Contributed and/or modified by Ioannis Iakovidis +# Licensed under GNU LGPL.3, see LICENCE file + +project( VolEsti ) + +enable_testing() + +CMAKE_MINIMUM_REQUIRED(VERSION 3.11) + +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + +# Locate Intel MKL root (in case it is enabled) + +if (APPLE) + set(MKLROOT /opt/intel/oneapi/mkl/latest) +elseif(UNIX) + set(MKLROOT /opt/intel/oneapi/mkl/latest) +endif() + + +option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) +option(BUILTIN_EIGEN "Use eigen from ../external" OFF) +option(BUILTIN_AUTODIFF "Use autodiff from ../external" ON) +option(USE_MKL "Use MKL library to build eigen" OFF) + +if(DISABLE_NLP_ORACLES) + add_definitions(-DDISABLE_NLP_ORACLES) +else() + find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) + find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) + find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) + find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + + if (NOT IFOPT) + + message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") + + elseif (NOT GMP) + + message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") + + elseif (NOT MPSOLVE) + + message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") + + elseif (NOT FFTW3) + + message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") + + else() + message(STATUS "Library ifopt found: ${IFOPT}") + message(STATUS "Library gmp found: ${GMP}") + message(STATUS "Library mpsolve found: ${MPSOLVE}") + message(STATUS "Library fftw3 found:" ${FFTW3}) + + endif(NOT IFOPT) + +endif(DISABLE_NLP_ORACLES) + +option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) + +if(DISABLE_NLP_ORACLES) + add_definitions(-DDISABLE_NLP_ORACLES) +else() + find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) + find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) + find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) + find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) + + if (NOT IFOPT) + + message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") + + elseif (NOT GMP) + + message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") + + elseif (NOT MPSOLVE) + + message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") + + elseif (NOT FFTW3) + + message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") + + else() + message(STATUS "Library ifopt found: ${IFOPT}") + message(STATUS "Library gmp found: ${GMP}") + message(STATUS "Library mpsolve found: ${MPSOLVE}") + message(STATUS "Library fftw3 found:" ${FFTW3}) + + endif(NOT IFOPT) + +endif(DISABLE_NLP_ORACLES) + +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +include("../external/cmake-files/Autodiff.cmake") +GetAutodiff() + +include("../external/cmake-files/Eigen.cmake") +GetEigen() + +include("../external/cmake-files/Boost.cmake") +GetBoost() + +include("../external/cmake-files/LPSolve.cmake") +GetLPSolve() + +include("../external/cmake-files/QD.cmake") +GetQD() + +# Code Coverage Configuration +add_library(coverage_config INTERFACE) + +option(CODE_COVERAGE "Enable coverage reporting" OFF) +if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + # Add required flags (GCC & LLVM/Clang) + target_compile_options(coverage_config INTERFACE + -O1 # O0 (or no) optimization takes too much time and causes CircleCI test failure. + -g # generate debug info + --coverage # sets all required flags + ) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(coverage_config INTERFACE --coverage) + else() + target_link_libraries(coverage_config INTERFACE --coverage) + endif() +endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + +if (BUILTIN_AUTODIFF) + include_directories (BEFORE ../../external/_deps/Autodiff) +else () + include_directories(BEFORE /usr/local/include) +endif(BUILTIN_AUTODIFF) + +set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") + +if (USE_MKL) + find_library(BLAS NAMES libblas.so libblas.dylib PATHS /usr/local/Cellar/lapack/3.9.1_1/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu /usr/local/Cellar/openblas/0.3.15_1/lib /usr/lib) + find_library(GFORTRAN NAME libgfortran.dylib PATHS /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10) + find_library(LAPACK NAME liblapack.dylib PATHS /usr/lib) + find_library(OPENMP NAME libiomp5.dylib PATHS /opt/intel/oneapi/compiler/2021.1.1/mac/compiler/lib) + include_directories (BEFORE ${MKLROOT}/include) + set(PROJECT_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES}) + set(MKL_LINK "-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl") + add_definitions(-DEIGEN_USE_MKL_ALL) +else() + set(MKL_LINK "") +endif(USE_MKL) + +include_directories (BEFORE ../external) +include_directories (BEFORE ../include) + +#for Eigen +if (${CMAKE_VERSION} VERSION_LESS "3.12.0") + add_compile_options(-D "EIGEN_NO_DEBUG") +else () + add_compile_definitions("EIGEN_NO_DEBUG") +endif () + +add_definitions(${CMAKE_CXX_FLAGS} "-g") # enable debuger +#add_definitions(${CMAKE_CXX_FLAGS} "-Wint-in-bool-context") +#add_definitions(${CMAKE_CXX_FLAGS} "-Wall") + +add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler +add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") #enable the c++17 support needed by autodiff +#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl") +add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm") +add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl") +add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR") +add_definitions(${CMAKE_CXX_FLAGS} "-DMKL_ILP64") +#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") +#add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) + +add_executable (new_volume_example new_volume_example.cpp) +add_executable (benchmarks_sob benchmarks_sob.cpp) +add_executable (benchmarks_cg benchmarks_cg.cpp) +add_executable (benchmarks_cb benchmarks_cb.cpp) + +add_library(test_main OBJECT test_main.cpp) + +add_executable (mcmc_diagnostics_test mcmc_diagnostics_test.cpp $) +add_test(NAME test_psrf COMMAND mcmc_diagnostics_test -tc=psrf) +add_test(NAME test_univariate_psrf COMMAND mcmc_diagnostics_test -tc=univariate_psrf) +add_test(NAME test_interval_psrf COMMAND mcmc_diagnostics_test -tc=interval_psrf) +add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess) +add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke) +add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery) + +add_executable (sampling_test sampling_test.cpp $) +add_test(NAME test_dikin COMMAND sampling_test -tc=dikin) +add_test(NAME test_john COMMAND sampling_test -tc=john) +add_test(NAME test_vaidya COMMAND sampling_test -tc=vaidya) +add_test(NAME test_brdhr COMMAND sampling_test -tc=brdhr) +add_test(NAME test_bcdhr COMMAND sampling_test -tc=bcdhr) +add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr) +add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw) +add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc) + +add_executable (mmcs_test mmcs_test.cpp $) +add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs) + +add_executable (ode_solvers_test ode_solvers_test.cpp $) +add_test(NAME ode_solvers_test_first_order + COMMAND ode_solvers_test -tc=first_order) +add_test(NAME ode_solvers_test_second_order + COMMAND ode_solvers_test -tc=second_order) + +add_executable (root_finders_test root_finders_test.cpp $) +add_test(NAME root_finders_test_root_finders + COMMAND root_finders_test -tc=root_finders) + +#add_executable (benchmarks_crhmc benchmarks_crhmc.cpp ) +#add_executable (benchmarks_crhmc_sampling benchmarks_crhmc_sampling.cpp ) + +add_executable (crhmc_polytope_preparation_test crhmc_polytope_preparation_test.cpp $) +add_test(NAME crhmc_polytope_test_preparation + COMMAND crhmc_polytope_preparation_test -tc=test_preparation_crhmc) +add_test(NAME crhmc_test_fixed_vars + COMMAND crhmc_polytope_preparation_test -tc=test_fixed_vars_crhmc) +add_test(NAME crhmc_test_dep_vars + COMMAND crhmc_polytope_preparation_test -tc=test_dep_vars_crhmc) +add_test(NAME crhmc_test_center_computation + COMMAND crhmc_polytope_preparation_test -tc=test_center_computation) + +add_executable (boundary_oracles_test boundary_oracles_test.cpp $) +add_test(NAME boundary_oracles_test_h_poly_oracles + COMMAND boundary_oracles_test -tc=h_poly_oracles) + +add_executable (volume_sob_hpolytope volume_sob_hpolytope.cpp $) +add_test(NAME volume_sob_hpolytope_cube COMMAND volume_sob_hpolytope -tc=cube) +add_test(NAME volume_sob_hpolytope_cross COMMAND volume_sob_hpolytope -tc=cross) +add_test(NAME volume_sob_hpolytope_birkhoff COMMAND volume_sob_hpolytope -tc=birk) +add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) +add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) +add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) +add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) +set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) + +add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) +add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) +add_test(NAME volume_sob_vpolytope_cross COMMAND volume_sob_vpolytope -tc=cross) +add_test(NAME volume_sob_vpolytope_simplex COMMAND volume_sob_vpolytope -tc=simplex) + +add_executable (volume_cg_hpolytope volume_cg_hpolytope.cpp $) +add_test(NAME volume_cg_hpolytope_cube COMMAND volume_cg_hpolytope -tc=cube) +add_test(NAME volume_cg_hpolytope_cross COMMAND volume_cg_hpolytope -tc=cross) +add_test(NAME volume_cg_hpolytope_birkhoff COMMAND volume_cg_hpolytope -tc=birk) +add_test(NAME volume_cg_hpolytope_prod_simplex COMMAND volume_cg_hpolytope -tc=prod_simplex) +add_test(NAME volume_cg_hpolytope_simplex COMMAND volume_cg_hpolytope -tc=simplex) +add_test(NAME volume_cg_hpolytope_skinny_cube COMMAND volume_cg_hpolytope -tc=skinny_cube) + +add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $) +add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube) +add_test(NAME volume_cg_vpolytope_cross COMMAND volume_cg_vpolytope -tc=cross) +add_test(NAME volume_cg_vpolytope_simplex COMMAND volume_cg_vpolytope -tc=simplex) + +add_executable (volume_cb_hpolytope volume_cb_hpolytope.cpp $) +add_test(NAME volume_cb_hpolytope_cube COMMAND volume_cb_hpolytope -tc=cube) +add_test(NAME volume_cb_hpolytope_cross COMMAND volume_cb_hpolytope -tc=cross) +add_test(NAME volume_cb_hpolytope_birkhoff COMMAND volume_cb_hpolytope -tc=birk) +add_test(NAME volume_cb_hpolytope_prod_simplex COMMAND volume_cb_hpolytope -tc=prod_simplex) +add_test(NAME volume_cb_hpolytope_simplex COMMAND volume_cb_hpolytope -tc=simplex) +add_test(NAME volume_cb_hpolytope_skinny_cube COMMAND volume_cb_hpolytope -tc=skinny_cube) + +add_executable (volume_cb_vpolytope volume_cb_vpolytope.cpp $) +add_test(NAME volume_cb_vpolytope_cube COMMAND volume_cb_vpolytope -tc=cube) +add_test(NAME volume_cb_vpolytope_cross COMMAND volume_cb_vpolytope -tc=cross) +add_test(NAME volume_cb_vpolytope_simplex COMMAND volume_cb_vpolytope -tc=simplex) + +add_executable (volume_cb_zonotopes volume_cb_zonotopes.cpp $) +add_test(NAME volume_cb_zonotopes_uniform_zonotopes + COMMAND volume_cb_zonotopes -tc=uniform_zonotopes) + +add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_vpoly.cpp $) +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_test(NAME test_round_min_ellipsoid + COMMAND rounding_test -tc=round_min_ellipsoid) +add_test(NAME test_round_max_ellipsoid + COMMAND 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_executable (logconcave_sampling_test logconcave_sampling_test.cpp $) +add_test(NAME logconcave_sampling_test_hmc + COMMAND logconcave_sampling_test -tc=hmc) +add_test(NAME logconcave_sampling_test_uld + COMMAND logconcave_sampling_test -tc=uld) +add_test(NAME logconcave_sampling_test_exponential_biomass_sampling + COMMAND logconcave_sampling_test -tc=exponential_biomass_sampling) +add_test(NAME logconcave_sampling_test_nuts_hmc_truncated + COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated) +add_test(NAME logconcave_sampling_test_nuts_hmc + COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc) + + + +add_executable (crhmc_sampling_test crhmc_sampling_test.cpp $) +add_test(NAME crhmc_sampling_test_crhmc + COMMAND crhmc_sampling_test -tc=crhmc) +add_test(NAME crhmc_test_polytope_sampling + COMMAND crhmc_sampling_test -tc=test_polytope_sampling_crhmc) +add_test(NAME crhmc_test_sparse_sampling + COMMAND crhmc_sampling_test -tc=test_sampling_sparse_problem) +add_executable (simple_mc_integration simple_mc_integration.cpp $) +add_test(NAME simple_mc_integration_over_limits + COMMAND simple_mc_integration -tc=rectangle) +add_test(NAME simple_mc_integration_over_cubes + COMMAND simple_mc_integration -tc=cube) +add_test(NAME simple_mc_integration_over_simplices + COMMAND simple_mc_integration -tc=simplex) +add_test(NAME simple_mc_integration_over_product_simplices + COMMAND simple_mc_integration -tc=prod_simplex) +add_test(NAME simple_mc_integration_over_cross_polytopes + COMMAND simple_mc_integration -tc=cross) +add_test(NAME simple_mc_integration_over_birkhoff_polytopes + COMMAND simple_mc_integration -tc=birkhoff) + +add_executable (order_polytope order_polytope.cpp $) +add_test(NAME order_polytope_basics COMMAND order_polytope -tc=basics) +add_test(NAME order_polytope_line_intersect COMMAND order_polytope -tc=line_intersect) +add_test(NAME order_polytope_reflection COMMAND order_polytope -tc=reflection) +add_test(NAME order_polytope_vec_mult COMMAND order_polytope -tc=vec_mult) + +add_executable (matrix_sampling_test sampling_correlation_matrices_test.cpp $) +add_test(NAME test_corre_spectra_classes COMMAND matrix_sampling_test -tc=corre_spectra) +add_test(NAME test_new_ball_uniform COMMAND matrix_sampling_test -tc=new_ball_uniform) +add_test(NAME test_new_billiard_uniform COMMAND matrix_sampling_test -tc=new_billiard_uniform) +add_test(NAME test_new_accelerated_billiard_uniform COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform) +add_test(NAME test_new_ball_uniform_MT COMMAND matrix_sampling_test -tc=new_ball_uniform_MT) +add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr_uniform_MT) +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) + + + +set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") + +#set_target_properties(benchmarks_crhmc +# PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) +#set_target_properties(benchmarks_crhmc_sampling +# PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) +set_target_properties(crhmc_polytope_preparation_test + PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) +set_target_properties(crhmc_sampling_test + PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) + +TARGET_LINK_LIBRARIES(new_volume_example lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(new_volume_example lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_sob_hpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_sob_vpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cg_hpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cg_vpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cb_hpolytope lp_solve coverage_config) +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(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) +TARGET_LINK_LIBRARIES(benchmarks_sob lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(benchmarks_cg lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(benchmarks_cb lp_solve ${MKL_LINK} coverage_config) +#TARGET_LINK_LIBRARIES(benchmarks_crhmc_sampling lp_solve ${MKL_LINK} QD_LIB coverage_config) +#TARGET_LINK_LIBRARIES(benchmarks_crhmc lp_solve ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(simple_mc_integration lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(ode_solvers_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(boundary_oracles_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(root_finders_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(crhmc_polytope_preparation_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +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/test_internal_points.cpp b/test/test_internal_points.cpp index 8d4df0240..f54252e08 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -17,7 +17,8 @@ #include "convex_bodies/hpolytope.h" #include "preprocess/max_inscribed_ball.hpp" -#include "preprocess/analytic_center_linear_ineq.h" +#include "preprocess/analytic_center_ellipsoid.hpp" +#include "preprocess/volumetric_center_ellipsoid.hpp" #include "generators/known_polytope_generators.h" #include "generators/h_polytopes_generator.h" @@ -129,10 +130,10 @@ void call_test_analytic_center() { P = skinny_random_hpoly(3, 15, pre_rounding, max_min_eig_ratio, 127); P.normalize(); - auto [Hessian, analytic_center, converged] = analytic_center_linear_ineq(P.get_mat(), P.get_vec()); + auto [Hessian, analytic_center, converged] = analytic_center_ellipsoid_linear_ineq(P.get_mat(), P.get_vec()); SpMT Asp = P.get_mat().sparseView(); - auto [Hessian_sp, analytic_center2, converged2] = analytic_center_linear_ineq(Asp, P.get_vec()); + auto [Hessian_sp, analytic_center2, converged2] = analytic_center_ellipsoid_linear_ineq(Asp, P.get_vec()); CHECK(P.is_in(Point(analytic_center)) == -1); CHECK(converged); @@ -149,6 +150,46 @@ void call_test_analytic_center() { CHECK((Hessian - Hessian_sp).norm() < 1e-12); } +template +void call_test_volumetric_center() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + typedef typename Hpolytope::MT MT; + typedef typename Hpolytope::VT VT; + typedef boost::mt19937 PolyRNGType; + typedef Eigen::SparseMatrix SpMT; + Hpolytope P; + + std::cout << "\n--- Testing volumetric center for skinny H-polytope" << std::endl; + bool pre_rounding = true; // round random polytope before applying the skinny transformation + NT max_min_eig_ratio = NT(100); + P = skinny_random_hpoly(3, 15, pre_rounding, max_min_eig_ratio, 127); + P.normalize(); + std::cout<<"A:\n"<(P.get_mat(), P.get_vec()); + SpMT Asp = P.get_mat().sparseView(); + + auto [Hessian_sp, analytic_center2, converged2] = volumetric_center_ellipsoid_linear_ineq(Asp, P.get_vec()); + std::cout<<"analytic_center: "<(); } @@ -161,6 +202,10 @@ TEST_CASE("test_analytic_center") { call_test_analytic_center(); } +TEST_CASE("test_volumetric_center") { + call_test_volumetric_center(); +} + TEST_CASE("test_max_ball_sparse") { call_test_max_ball_sparse(); } From c0e85102d6ef3f11f7c741a420b122e55ad49932 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Sat, 29 Jun 2024 15:51:49 -0600 Subject: [PATCH 16/20] add criterion for step_iter --- include/preprocess/volumetric_center_ellipsoid.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/preprocess/volumetric_center_ellipsoid.hpp b/include/preprocess/volumetric_center_ellipsoid.hpp index b2081ccae..7afd45a3d 100644 --- a/include/preprocess/volumetric_center_ellipsoid.hpp +++ b/include/preprocess/volumetric_center_ellipsoid.hpp @@ -34,7 +34,6 @@ void get_hessian_grad_volumetric_barrier(MT const& A, MT const& A_trans, VT cons grad.noalias() = A_trans * (s.cwiseProduct(sigma)); // Hessian of the volumetric barrier function update_Atrans_Diag_A(H, A_trans, A, s_sq.cwiseProduct(sigma).asDiagonal()); - //std::cout<<"H:\n"< volumetric_center_ellipsoid_linear_ineq(MT const get_hessian_grad_volumetric_barrier(A, A_trans, b, x, Ax, llt, H, grad, b_Ax, obj_val); grad_err = grad.norm(); - std::cout<<"iter: "<= max_iters || grad_err <= grad_err_tol || rel_pos_err <= rel_pos_err_tol) { converged = true; break; } - step_iter *= NT(0.999); + step_iter *= (obj_val_prev <= obj_val - tol_obj) ? NT(0.9) : NT(0.999); } while (true); return std::make_tuple(MT_dense(H), x, converged); @@ -126,7 +125,6 @@ std::tuple volumetric_center_ellipsoid_linear_ineq(MT const NT const rel_pos_err_tol = 1e-12) { VT x0 = compute_feasible_point(A, b); - std::cout<<"x0: "<(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); } From cc5ec47b4a0cb1709f97544c982706d170c585f0 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Sun, 30 Jun 2024 16:55:35 -0600 Subject: [PATCH 17/20] restructure code that computes barriers' centers --- ...psoid.hpp => barrier_center_ellipsoid.hpp} | 77 ++-- .../inscribed_ellipsoid_rounding.hpp | 12 +- include/preprocess/max_inscribed_ball.hpp | 2 +- .../preprocess/max_inscribed_ellipsoid.hpp | 2 +- ...rators.hpp => rounding_util_functions.hpp} | 82 +++- .../volumetric_center_ellipsoid.hpp | 131 ------ test/CMakeLists.txt | 192 +++++++- test/CMakeLists_2.txt | 409 ------------------ test/rounding_test.cpp | 46 ++ test/test_internal_points.cpp | 34 +- 10 files changed, 367 insertions(+), 620 deletions(-) rename include/preprocess/{analytic_center_ellipsoid.hpp => barrier_center_ellipsoid.hpp} (55%) rename include/preprocess/{mat_computational_operators.hpp => rounding_util_functions.hpp} (79%) delete mode 100644 include/preprocess/volumetric_center_ellipsoid.hpp delete mode 100644 test/CMakeLists_2.txt diff --git a/include/preprocess/analytic_center_ellipsoid.hpp b/include/preprocess/barrier_center_ellipsoid.hpp similarity index 55% rename from include/preprocess/analytic_center_ellipsoid.hpp rename to include/preprocess/barrier_center_ellipsoid.hpp index 5328b8507..cfbfebc27 100644 --- a/include/preprocess/analytic_center_ellipsoid.hpp +++ b/include/preprocess/barrier_center_ellipsoid.hpp @@ -7,55 +7,46 @@ // Licensed under GNU LGPL.3, see LICENCE file -#ifndef ANALYTIC_CENTER_ELLIPSOID_HPP -#define ANALYTIC_CENTER_ELLIPSOID_HPP +#ifndef BARRIER_CENTER_ELLIPSOID_HPP +#define BARRIER_CENTER_ELLIPSOID_HPP #include #include "preprocess/max_inscribed_ball.hpp" #include "preprocess/feasible_point.hpp" -#include "preprocess/mat_computational_operators.hpp" - - -template -void get_hessian_grad_logbarrier(MT const& A, MT const& A_trans, VT const& b, - VT const& x, VT const& Ax, MT &H, VT &grad, VT &b_Ax) -{ - b_Ax.noalias() = b - Ax; - VT s = b_Ax.cwiseInverse(); - VT s_sq = s.cwiseProduct(s); - // Gradient of the log-barrier function - grad.noalias() = A_trans * s; - // Hessian of the log-barrier function - update_Atrans_Diag_A(H, A_trans, A, s_sq.asDiagonal()); -} +#include "preprocess/rounding_util_functions.hpp" /* - This implementation computes the analytic center of a polytope given - as a set of linear inequalities P = {x | Ax <= b}. The analytic center - is the minimizer of the log barrier function i.e., the optimal solution + This implementation computes the analytic or the volumetric center of a polytope given + as a set of linear inequalities P = {x | Ax <= b}. The analytic center is the tminimizer + of the log barrier function, i.e., the optimal solution of the following optimization problem (Convex Optimization, Boyd and Vandenberghe, Section 8.5.3), \min -\sum \log(b_i - a_i^Tx), where a_i is the i-th row of A. - The function solves the problem by using the Newton method. + The volumetric center is the minimizer of the volumetric barrier function, i.e., the optimal + solution of the following optimization problem, + + \min logdet \nabla^2 f(x), where f(x) the log barrier function + + The function solves the problems by using the Newton method. Input: (i) Matrix A, vector b such that the polytope P = {x | Ax<=b} (ii) The number of maximum iterations, max_iters (iii) Tolerance parameter grad_err_tol to bound the L2-norm of the gradient (iv) Tolerance parameter rel_pos_err_tol to check the relative progress in each iteration - Output: (i) The Hessian computed on the analytic center - (ii) The analytic center of the polytope + Output: (i) The Hessian of the barrier function + (ii) The analytic/volumetric center of the polytope (iii) A boolean variable that declares convergence Note: Using MT as to deal with both dense and sparse matrices, MT_dense will be the type of result matrix */ -template -std::tuple analytic_center_ellipsoid_linear_ineq(MT const& A, VT const& b, VT const& x0, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) +template +std::tuple barrier_center_ellipsoid_linear_ineq(MT const& A, VT const& b, VT const& x0, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) { // Initialization VT x = x0; @@ -63,21 +54,22 @@ std::tuple analytic_center_ellipsoid_linear_ineq(MT const& const int n = A.cols(), m = A.rows(); MT H(n, n), A_trans = A.transpose(); VT grad(n), d(n), Ad(m), b_Ax(m), step_d(n), x_prev; - NT grad_err, rel_pos_err, rel_pos_err_temp, step; + NT grad_err, rel_pos_err, rel_pos_err_temp, step, obj_val, obj_val_prev; unsigned int iter = 0; bool converged = false; - const NT tol_bnd = NT(0.01); + const NT tol_bnd = NT(0.01), tol_obj = NT(1e-06); + auto [step_iter, max_step_multiplier] = init_step(); auto llt = initialize_chol(A_trans, A); - get_hessian_grad_logbarrier(A, A_trans, b, x, Ax, H, grad, b_Ax); - + get_barrier_hessian_grad(A, A_trans, b, x, Ax, llt, + H, grad, b_Ax, obj_val); do { iter++; // Compute the direction d.noalias() = - solve_vec(llt, H, grad); Ad.noalias() = A * d; // Compute the step length - step = std::min((NT(1) - tol_bnd) * get_max_step(Ad, b_Ax), NT(1)); + step = std::min(max_step_multiplier * get_max_step(Ad, b_Ax), step_iter); step_d.noalias() = step*d; x_prev = x; x += step_d; @@ -94,7 +86,9 @@ std::tuple analytic_center_ellipsoid_linear_ineq(MT const& } } - get_hessian_grad_logbarrier(A, A_trans, b, x, Ax, H, grad, b_Ax); + obj_val_prev = obj_val; + get_barrier_hessian_grad(A, A_trans, b, x, Ax, llt, + H, grad, b_Ax, obj_val); grad_err = grad.norm(); if (iter >= max_iters || grad_err <= grad_err_tol || rel_pos_err <= rel_pos_err_tol) @@ -102,19 +96,20 @@ std::tuple analytic_center_ellipsoid_linear_ineq(MT const& converged = true; break; } + get_step_next_iteration(obj_val_prev, obj_val, tol_obj, step_iter); } while (true); return std::make_tuple(MT_dense(H), x, converged); } -template -std::tuple analytic_center_ellipsoid_linear_ineq(MT const& A, VT const& b, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) +template +std::tuple barrier_center_ellipsoid_linear_ineq(MT const& A, VT const& b, + unsigned int const max_iters = 500, + NT const grad_err_tol = 1e-08, + NT const rel_pos_err_tol = 1e-12) { VT x0 = compute_feasible_point(A, b); - return analytic_center_ellipsoid_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); + return barrier_center_ellipsoid_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); } -#endif // ANALYTIC_CENTER_ELLIPSOID_HPP +#endif // BARRIER_CENTER_ELLIPSOID_HPP diff --git a/include/preprocess/inscribed_ellipsoid_rounding.hpp b/include/preprocess/inscribed_ellipsoid_rounding.hpp index 5986fb488..720ff1f58 100644 --- a/include/preprocess/inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/inscribed_ellipsoid_rounding.hpp @@ -12,14 +12,9 @@ #define INSCRIBED_ELLIPSOID_ROUNDING_HPP #include "preprocess/max_inscribed_ellipsoid.hpp" -#include "preprocess/analytic_center_ellipsoid.hpp" +#include "preprocess/barrier_center_ellipsoid.hpp" #include "preprocess/feasible_point.hpp" -enum EllipsoidType -{ - MAX_ELLIPSOID = 1, - LOG_BARRIER = 2 -}; template inline static std::tuple @@ -30,9 +25,10 @@ compute_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0, if constexpr (ellipsoid_type == EllipsoidType::MAX_ELLIPSOID) { return max_inscribed_ellipsoid(A, b, x0, maxiter, tol, reg); - } else if constexpr (ellipsoid_type == EllipsoidType::LOG_BARRIER) + } else if constexpr (ellipsoid_type == EllipsoidType::LOG_BARRIER || + ellipsoid_type == EllipsoidType::VOLUMETRIC_BARRIER) { - return analytic_center_ellipsoid_linear_ineq(A, b, x0); + return barrier_center_ellipsoid_linear_ineq(A, b, x0); } else { std::runtime_error("Unknown rounding method."); diff --git a/include/preprocess/max_inscribed_ball.hpp b/include/preprocess/max_inscribed_ball.hpp index 2cfe68929..5f95970ba 100644 --- a/include/preprocess/max_inscribed_ball.hpp +++ b/include/preprocess/max_inscribed_ball.hpp @@ -11,7 +11,7 @@ #ifndef MAX_INSCRIBED_BALL_HPP #define MAX_INSCRIBED_BALL_HPP -#include "preprocess/mat_computational_operators.hpp" +#include "preprocess/rounding_util_functions.hpp" /* This implmentation computes the largest inscribed ball in a given convex polytope P. diff --git a/include/preprocess/max_inscribed_ellipsoid.hpp b/include/preprocess/max_inscribed_ellipsoid.hpp index 74f6c0b4d..cc65006b9 100644 --- a/include/preprocess/max_inscribed_ellipsoid.hpp +++ b/include/preprocess/max_inscribed_ellipsoid.hpp @@ -15,7 +15,7 @@ #include #include -#include "preprocess/mat_computational_operators.hpp" +#include "preprocess/rounding_util_functions.hpp" /* diff --git a/include/preprocess/mat_computational_operators.hpp b/include/preprocess/rounding_util_functions.hpp similarity index 79% rename from include/preprocess/mat_computational_operators.hpp rename to include/preprocess/rounding_util_functions.hpp index f95860ea2..1ee859b25 100644 --- a/include/preprocess/mat_computational_operators.hpp +++ b/include/preprocess/rounding_util_functions.hpp @@ -1,14 +1,15 @@ // VolEsti (volume computation and sampling library) -// Copyright (c) 2024 Vissarion Fisikopoulos -// Copyright (c) 2024 Apostolos Chalkis -// Copyright (c) 2024 Elias Tsigaridas +// Copyright (c) 2012-2024 Vissarion Fisikopoulos +// Copyright (c) 2018-2024 Apostolos Chalkis + +//Contributed and/or modified by Alexandros Manochis, as part of Google Summer of Code 2020 program. // Licensed under GNU LGPL.3, see LICENCE file -#ifndef MAT_COMPUTATIONAL_OPERATORS_HPP -#define MAT_COMPUTATIONAL_OPERATORS_HPP +#ifndef ROUNDING_UTIL_FUNCTIONS_HPP +#define ROUNDING_UTIL_FUNCTIONS_HPP #include @@ -17,6 +18,16 @@ #include "Spectra/include/Spectra/MatOp/SparseSymMatProd.h" +enum EllipsoidType +{ + MAX_ELLIPSOID = 1, + LOG_BARRIER = 2, + VOLUMETRIC_BARRIER = 3 +}; + +template +struct AssertBarrierFalseType : std::false_type {}; + template struct AssertFalseType : std::false_type {}; @@ -327,5 +338,64 @@ update_Bmat(MT &B, VT const& AtDe, VT const& d, } } +template +std::tuple init_step() +{ + if constexpr (BarrierType == EllipsoidType::LOG_BARRIER) + { + return {NT(1), NT(0.99)}; + } else if constexpr (BarrierType == EllipsoidType::VOLUMETRIC_BARRIER) + { + return {NT(0.5), NT(0.4)}; + } else { + static_assert(AssertBarrierFalseType::value, + "Barrier type is not supported."); + } +} + +template +void get_barrier_hessian_grad(MT const& A, MT const& A_trans, VT const& b, + VT const& x, VT const& Ax, llt_type const& llt, + MT &H, VT &grad, VT &b_Ax, NT &obj_val) +{ + b_Ax.noalias() = b - Ax; + VT s = b_Ax.cwiseInverse(); + VT s_sq = s.cwiseProduct(s); + // Hessian of the log-barrier function + update_Atrans_Diag_A(H, A_trans, A, s_sq.asDiagonal()); + if constexpr (BarrierType == EllipsoidType::LOG_BARRIER) + { + grad.noalias() = A_trans * s; + } else if constexpr (BarrierType == EllipsoidType::VOLUMETRIC_BARRIER) + { + // Computing sigma(x)_i = (a_i^T H^{-1} a_i) / (b_i - a_i^Tx)^2 + MT_dense HA = solve_mat(llt, H, A_trans, obj_val); + MT_dense aiHai = HA.transpose().cwiseProduct(A); + VT sigma = (aiHai.rowwise().sum()).cwiseProduct(s_sq); + // Gradient of the volumetric barrier function + grad.noalias() = A_trans * (s.cwiseProduct(sigma)); + // Hessian of the volumetric barrier function + update_Atrans_Diag_A(H, A_trans, A, s_sq.cwiseProduct(sigma).asDiagonal()); + } else { + static_assert(AssertBarrierFalseType::value, + "Barrier type is not supported."); + } +} + +template +void get_step_next_iteration(NT const obj_val_prev, NT const obj_val, + NT const tol_obj, NT &step_iter) +{ + if constexpr (BarrierType == EllipsoidType::LOG_BARRIER) + { + step_iter = NT(1); + } else if constexpr (BarrierType == EllipsoidType::VOLUMETRIC_BARRIER) + { + step_iter *= (obj_val_prev <= obj_val - tol_obj) ? NT(0.9) : NT(0.999); + } else { + static_assert(AssertBarrierFalseType::value, + "Barrier type is not supported."); + } +} -#endif // MAT_COMPUTATIONAL_OPERATORS_HPP +#endif // ROUNDING_UTIL_FUNCTIONS_HPP \ No newline at end of file diff --git a/include/preprocess/volumetric_center_ellipsoid.hpp b/include/preprocess/volumetric_center_ellipsoid.hpp deleted file mode 100644 index 7afd45a3d..000000000 --- a/include/preprocess/volumetric_center_ellipsoid.hpp +++ /dev/null @@ -1,131 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2024 Vissarion Fisikopoulos -// Copyright (c) 2024 Apostolos Chalkis -// Copyright (c) 2024 Elias Tsigaridas - -// Licensed under GNU LGPL.3, see LICENCE file - - -#ifndef VOLUMETRIC_CENTER_ELLIPSOID_HPP -#define VOLUMETRIC_CENTER_ELLIPSOID_HPP - -#include - -#include "preprocess/max_inscribed_ball.hpp" -#include "preprocess/feasible_point.hpp" -#include "preprocess/mat_computational_operators.hpp" - -template -void get_hessian_grad_volumetric_barrier(MT const& A, MT const& A_trans, VT const& b, - VT const& x, VT const& Ax, llt_type const& llt, - MT &H, VT &grad, VT &b_Ax, NT &obj_val) -{ - b_Ax.noalias() = b - Ax; - VT s = b_Ax.cwiseInverse(); - VT s_sq = s.cwiseProduct(s); - // Hessian of the log-barrier function - update_Atrans_Diag_A(H, A_trans, A, s_sq.asDiagonal()); - // Computing sigma(x)_i = (a_i^T H^{-1} a_i) / (b_i - a_i^Tx)^2 - MT_dense HA = solve_mat(llt, H, A_trans, obj_val); - MT_dense aiHai = HA.transpose().cwiseProduct(A); - VT sigma = (aiHai.rowwise().sum()).cwiseProduct(s_sq); - // Gradient of the volumetric barrier function - grad.noalias() = A_trans * (s.cwiseProduct(sigma)); - // Hessian of the volumetric barrier function - update_Atrans_Diag_A(H, A_trans, A, s_sq.cwiseProduct(sigma).asDiagonal()); -} - -/* - This implementation computes the volumetric center of a polytope given - as a set of linear inequalities P = {x | Ax <= b}. The volumetric center - is the minimizer of the volumetric barrier function i.e., the optimal solution - of the following optimization problem, - - \min -, - - The function solves the problem by using the Newton method. - - Input: (i) Matrix A, vector b such that the polytope P = {x | Ax<=b} - (ii) The number of maximum iterations, max_iters - (iii) Tolerance parameter grad_err_tol to bound the L2-norm of the gradient - (iv) Tolerance parameter rel_pos_err_tol to check the relative progress in each iteration - - Output: (i) The Hessian computed on the volumetric center - (ii) The volumetric center of the polytope - (iii) A boolean variable that declares convergence - - Note: Using MT as to deal with both dense and sparse matrices, MT_dense will be the type of result matrix -*/ -template -std::tuple volumetric_center_ellipsoid_linear_ineq(MT const& A, VT const& b, VT const& x0, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) -{ - // Initialization - VT x = x0; - VT Ax = A * x; - const int n = A.cols(), m = A.rows(); - MT H(n, n), A_trans = A.transpose(); - VT grad(n), d(n), Ad(m), b_Ax(m), step_d(n), x_prev; - NT grad_err, rel_pos_err, rel_pos_err_temp, step, obj_val, obj_val_prev; - unsigned int iter = 0; - bool converged = false; - const NT tol_bnd = NT(0.01), tol_obj = NT(1e-06); - NT step_iter = NT(0.5); - - auto llt = initialize_chol(A_trans, A); - get_hessian_grad_volumetric_barrier(A, A_trans, b, x, Ax, llt, - H, grad, b_Ax, obj_val); - do { - iter++; - // Compute the direction - d.noalias() = - solve_vec(llt, H, grad); - Ad.noalias() = A * d; - // Compute the step length - step = std::min(NT(0.4) * get_max_step(Ad, b_Ax), step_iter); - step_d.noalias() = step*d; - x_prev = x; - x += step_d; - Ax.noalias() += step*Ad; - - // Compute the max_i\{ |step*d_i| ./ |x_i| \} - rel_pos_err = std::numeric_limits::lowest(); - for (int i = 0; i < n; i++) - { - rel_pos_err_temp = std::abs(step_d.coeff(i) / x_prev.coeff(i)); - if (rel_pos_err_temp > rel_pos_err) - { - rel_pos_err = rel_pos_err_temp; - } - } - - obj_val_prev = obj_val; - get_hessian_grad_volumetric_barrier(A, A_trans, b, x, Ax, llt, - H, grad, b_Ax, obj_val); - grad_err = grad.norm(); - //std::cout<<"iter: "<= max_iters || grad_err <= grad_err_tol || rel_pos_err <= rel_pos_err_tol) - { - converged = true; - break; - } - step_iter *= (obj_val_prev <= obj_val - tol_obj) ? NT(0.9) : NT(0.999); - } while (true); - - return std::make_tuple(MT_dense(H), x, converged); -} - -template -std::tuple volumetric_center_ellipsoid_linear_ineq(MT const& A, VT const& b, - unsigned int const max_iters = 500, - NT const grad_err_tol = 1e-08, - NT const rel_pos_err_tol = 1e-12) -{ - VT x0 = compute_feasible_point(A, b); - return volumetric_center_ellipsoid_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); -} - -#endif // VOLUMETRIC_CENTER_ELLIPSOID_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index be42255d9..b524403ce 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -185,13 +185,109 @@ add_definitions(${CMAKE_CXX_FLAGS} "-DMKL_ILP64") #add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") #add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) - +add_executable (new_volume_example new_volume_example.cpp) +add_executable (benchmarks_sob benchmarks_sob.cpp) +add_executable (benchmarks_cg benchmarks_cg.cpp) +add_executable (benchmarks_cb benchmarks_cb.cpp) add_library(test_main OBJECT test_main.cpp) +add_executable (mcmc_diagnostics_test mcmc_diagnostics_test.cpp $) +add_test(NAME test_psrf COMMAND mcmc_diagnostics_test -tc=psrf) +add_test(NAME test_univariate_psrf COMMAND mcmc_diagnostics_test -tc=univariate_psrf) +add_test(NAME test_interval_psrf COMMAND mcmc_diagnostics_test -tc=interval_psrf) +add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess) +add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke) +add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery) + +add_executable (sampling_test sampling_test.cpp $) +add_test(NAME test_dikin COMMAND sampling_test -tc=dikin) +add_test(NAME test_john COMMAND sampling_test -tc=john) +add_test(NAME test_vaidya COMMAND sampling_test -tc=vaidya) +add_test(NAME test_brdhr COMMAND sampling_test -tc=brdhr) +add_test(NAME test_bcdhr COMMAND sampling_test -tc=bcdhr) +add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr) +add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw) +add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc) + +add_executable (mmcs_test mmcs_test.cpp $) +add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs) + +add_executable (ode_solvers_test ode_solvers_test.cpp $) +add_test(NAME ode_solvers_test_first_order + COMMAND ode_solvers_test -tc=first_order) +add_test(NAME ode_solvers_test_second_order + COMMAND ode_solvers_test -tc=second_order) + +add_executable (root_finders_test root_finders_test.cpp $) +add_test(NAME root_finders_test_root_finders + COMMAND root_finders_test -tc=root_finders) + #add_executable (benchmarks_crhmc benchmarks_crhmc.cpp ) #add_executable (benchmarks_crhmc_sampling benchmarks_crhmc_sampling.cpp ) +add_executable (crhmc_polytope_preparation_test crhmc_polytope_preparation_test.cpp $) +add_test(NAME crhmc_polytope_test_preparation + COMMAND crhmc_polytope_preparation_test -tc=test_preparation_crhmc) +add_test(NAME crhmc_test_fixed_vars + COMMAND crhmc_polytope_preparation_test -tc=test_fixed_vars_crhmc) +add_test(NAME crhmc_test_dep_vars + COMMAND crhmc_polytope_preparation_test -tc=test_dep_vars_crhmc) +add_test(NAME crhmc_test_center_computation + COMMAND crhmc_polytope_preparation_test -tc=test_center_computation) + +add_executable (boundary_oracles_test boundary_oracles_test.cpp $) +add_test(NAME boundary_oracles_test_h_poly_oracles + COMMAND boundary_oracles_test -tc=h_poly_oracles) + +add_executable (volume_sob_hpolytope volume_sob_hpolytope.cpp $) +add_test(NAME volume_sob_hpolytope_cube COMMAND volume_sob_hpolytope -tc=cube) +add_test(NAME volume_sob_hpolytope_cross COMMAND volume_sob_hpolytope -tc=cross) +add_test(NAME volume_sob_hpolytope_birkhoff COMMAND volume_sob_hpolytope -tc=birk) +add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) +add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) +add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) +add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) +set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) + +add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) +add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) +add_test(NAME volume_sob_vpolytope_cross COMMAND volume_sob_vpolytope -tc=cross) +add_test(NAME volume_sob_vpolytope_simplex COMMAND volume_sob_vpolytope -tc=simplex) + +add_executable (volume_cg_hpolytope volume_cg_hpolytope.cpp $) +add_test(NAME volume_cg_hpolytope_cube COMMAND volume_cg_hpolytope -tc=cube) +add_test(NAME volume_cg_hpolytope_cross COMMAND volume_cg_hpolytope -tc=cross) +add_test(NAME volume_cg_hpolytope_birkhoff COMMAND volume_cg_hpolytope -tc=birk) +add_test(NAME volume_cg_hpolytope_prod_simplex COMMAND volume_cg_hpolytope -tc=prod_simplex) +add_test(NAME volume_cg_hpolytope_simplex COMMAND volume_cg_hpolytope -tc=simplex) +add_test(NAME volume_cg_hpolytope_skinny_cube COMMAND volume_cg_hpolytope -tc=skinny_cube) + +add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $) +add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube) +add_test(NAME volume_cg_vpolytope_cross COMMAND volume_cg_vpolytope -tc=cross) +add_test(NAME volume_cg_vpolytope_simplex COMMAND volume_cg_vpolytope -tc=simplex) + +add_executable (volume_cb_hpolytope volume_cb_hpolytope.cpp $) +add_test(NAME volume_cb_hpolytope_cube COMMAND volume_cb_hpolytope -tc=cube) +add_test(NAME volume_cb_hpolytope_cross COMMAND volume_cb_hpolytope -tc=cross) +add_test(NAME volume_cb_hpolytope_birkhoff COMMAND volume_cb_hpolytope -tc=birk) +add_test(NAME volume_cb_hpolytope_prod_simplex COMMAND volume_cb_hpolytope -tc=prod_simplex) +add_test(NAME volume_cb_hpolytope_simplex COMMAND volume_cb_hpolytope -tc=simplex) +add_test(NAME volume_cb_hpolytope_skinny_cube COMMAND volume_cb_hpolytope -tc=skinny_cube) + +add_executable (volume_cb_vpolytope volume_cb_vpolytope.cpp $) +add_test(NAME volume_cb_vpolytope_cube COMMAND volume_cb_vpolytope -tc=cube) +add_test(NAME volume_cb_vpolytope_cross COMMAND volume_cb_vpolytope -tc=cross) +add_test(NAME volume_cb_vpolytope_simplex COMMAND volume_cb_vpolytope -tc=simplex) + +add_executable (volume_cb_zonotopes volume_cb_zonotopes.cpp $) +add_test(NAME volume_cb_zonotopes_uniform_zonotopes + COMMAND volume_cb_zonotopes -tc=uniform_zonotopes) + +add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_vpoly.cpp $) +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_test(NAME test_round_min_ellipsoid @@ -204,7 +300,61 @@ 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_executable (logconcave_sampling_test logconcave_sampling_test.cpp $) +add_test(NAME logconcave_sampling_test_hmc + COMMAND logconcave_sampling_test -tc=hmc) +add_test(NAME logconcave_sampling_test_uld + COMMAND logconcave_sampling_test -tc=uld) +add_test(NAME logconcave_sampling_test_exponential_biomass_sampling + COMMAND logconcave_sampling_test -tc=exponential_biomass_sampling) +add_test(NAME logconcave_sampling_test_nuts_hmc_truncated + COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated) +add_test(NAME logconcave_sampling_test_nuts_hmc + COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc) + + + +add_executable (crhmc_sampling_test crhmc_sampling_test.cpp $) +add_test(NAME crhmc_sampling_test_crhmc + COMMAND crhmc_sampling_test -tc=crhmc) +add_test(NAME crhmc_test_polytope_sampling + COMMAND crhmc_sampling_test -tc=test_polytope_sampling_crhmc) +add_test(NAME crhmc_test_sparse_sampling + COMMAND crhmc_sampling_test -tc=test_sampling_sparse_problem) +add_executable (simple_mc_integration simple_mc_integration.cpp $) +add_test(NAME simple_mc_integration_over_limits + COMMAND simple_mc_integration -tc=rectangle) +add_test(NAME simple_mc_integration_over_cubes + COMMAND simple_mc_integration -tc=cube) +add_test(NAME simple_mc_integration_over_simplices + COMMAND simple_mc_integration -tc=simplex) +add_test(NAME simple_mc_integration_over_product_simplices + COMMAND simple_mc_integration -tc=prod_simplex) +add_test(NAME simple_mc_integration_over_cross_polytopes + COMMAND simple_mc_integration -tc=cross) +add_test(NAME simple_mc_integration_over_birkhoff_polytopes + COMMAND simple_mc_integration -tc=birkhoff) + +add_executable (order_polytope order_polytope.cpp $) +add_test(NAME order_polytope_basics COMMAND order_polytope -tc=basics) +add_test(NAME order_polytope_line_intersect COMMAND order_polytope -tc=line_intersect) +add_test(NAME order_polytope_reflection COMMAND order_polytope -tc=reflection) +add_test(NAME order_polytope_vec_mult COMMAND order_polytope -tc=vec_mult) + +add_executable (matrix_sampling_test sampling_correlation_matrices_test.cpp $) +add_test(NAME test_corre_spectra_classes COMMAND matrix_sampling_test -tc=corre_spectra) +add_test(NAME test_new_ball_uniform COMMAND matrix_sampling_test -tc=new_ball_uniform) +add_test(NAME test_new_billiard_uniform COMMAND matrix_sampling_test -tc=new_billiard_uniform) +add_test(NAME test_new_accelerated_billiard_uniform COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform) +add_test(NAME test_new_ball_uniform_MT COMMAND matrix_sampling_test -tc=new_ball_uniform_MT) +add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr_uniform_MT) +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 @@ -215,7 +365,9 @@ 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) + set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") @@ -224,6 +376,38 @@ set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) #set_target_properties(benchmarks_crhmc_sampling # PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) - +set_target_properties(crhmc_polytope_preparation_test + PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) +set_target_properties(crhmc_sampling_test + PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) + +TARGET_LINK_LIBRARIES(new_volume_example lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(new_volume_example lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_sob_hpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_sob_vpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cg_hpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cg_vpolytope lp_solve coverage_config) +TARGET_LINK_LIBRARIES(volume_cb_hpolytope lp_solve coverage_config) +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(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) +TARGET_LINK_LIBRARIES(benchmarks_sob lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(benchmarks_cg lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(benchmarks_cb lp_solve ${MKL_LINK} coverage_config) +#TARGET_LINK_LIBRARIES(benchmarks_crhmc_sampling lp_solve ${MKL_LINK} QD_LIB coverage_config) +#TARGET_LINK_LIBRARIES(benchmarks_crhmc lp_solve ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(simple_mc_integration lp_solve ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(ode_solvers_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(boundary_oracles_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(root_finders_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +TARGET_LINK_LIBRARIES(crhmc_polytope_preparation_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) +TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) +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/CMakeLists_2.txt b/test/CMakeLists_2.txt deleted file mode 100644 index cdda6087c..000000000 --- a/test/CMakeLists_2.txt +++ /dev/null @@ -1,409 +0,0 @@ -# VolEsti (volume computation and sampling library) -# Copyright (c) 2012-2020 Vissarion Fisikopoulos -# Copyright (c) 2018-2020 Apostolos Chalkis -# Copyright (c) 2021 Vaibhav Thakkar - -# Contributed and/or modified by Vaibhav Thakkar -# Contributed and/or modified by Ioannis Iakovidis -# Licensed under GNU LGPL.3, see LICENCE file - -project( VolEsti ) - -enable_testing() - -CMAKE_MINIMUM_REQUIRED(VERSION 3.11) - -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) - -# Locate Intel MKL root (in case it is enabled) - -if (APPLE) - set(MKLROOT /opt/intel/oneapi/mkl/latest) -elseif(UNIX) - set(MKLROOT /opt/intel/oneapi/mkl/latest) -endif() - - -option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) -option(BUILTIN_EIGEN "Use eigen from ../external" OFF) -option(BUILTIN_AUTODIFF "Use autodiff from ../external" ON) -option(USE_MKL "Use MKL library to build eigen" OFF) - -if(DISABLE_NLP_ORACLES) - add_definitions(-DDISABLE_NLP_ORACLES) -else() - find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) - find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) - find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) - find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - - if (NOT IFOPT) - - message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") - - elseif (NOT GMP) - - message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") - - elseif (NOT MPSOLVE) - - message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") - - elseif (NOT FFTW3) - - message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") - - else() - message(STATUS "Library ifopt found: ${IFOPT}") - message(STATUS "Library gmp found: ${GMP}") - message(STATUS "Library mpsolve found: ${MPSOLVE}") - message(STATUS "Library fftw3 found:" ${FFTW3}) - - endif(NOT IFOPT) - -endif(DISABLE_NLP_ORACLES) - -option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) - -if(DISABLE_NLP_ORACLES) - add_definitions(-DDISABLE_NLP_ORACLES) -else() - find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) - find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) - find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) - find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) - - if (NOT IFOPT) - - message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") - - elseif (NOT GMP) - - message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") - - elseif (NOT MPSOLVE) - - message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") - - elseif (NOT FFTW3) - - message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") - - else() - message(STATUS "Library ifopt found: ${IFOPT}") - message(STATUS "Library gmp found: ${GMP}") - message(STATUS "Library mpsolve found: ${MPSOLVE}") - message(STATUS "Library fftw3 found:" ${FFTW3}) - - endif(NOT IFOPT) - -endif(DISABLE_NLP_ORACLES) - -if(COMMAND cmake_policy) - cmake_policy(SET CMP0003 NEW) -endif(COMMAND cmake_policy) - -include("../external/cmake-files/Autodiff.cmake") -GetAutodiff() - -include("../external/cmake-files/Eigen.cmake") -GetEigen() - -include("../external/cmake-files/Boost.cmake") -GetBoost() - -include("../external/cmake-files/LPSolve.cmake") -GetLPSolve() - -include("../external/cmake-files/QD.cmake") -GetQD() - -# Code Coverage Configuration -add_library(coverage_config INTERFACE) - -option(CODE_COVERAGE "Enable coverage reporting" OFF) -if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - # Add required flags (GCC & LLVM/Clang) - target_compile_options(coverage_config INTERFACE - -O1 # O0 (or no) optimization takes too much time and causes CircleCI test failure. - -g # generate debug info - --coverage # sets all required flags - ) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) - target_link_options(coverage_config INTERFACE --coverage) - else() - target_link_libraries(coverage_config INTERFACE --coverage) - endif() -endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - -if (BUILTIN_AUTODIFF) - include_directories (BEFORE ../../external/_deps/Autodiff) -else () - include_directories(BEFORE /usr/local/include) -endif(BUILTIN_AUTODIFF) - -set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") - -if (USE_MKL) - find_library(BLAS NAMES libblas.so libblas.dylib PATHS /usr/local/Cellar/lapack/3.9.1_1/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu /usr/local/Cellar/openblas/0.3.15_1/lib /usr/lib) - find_library(GFORTRAN NAME libgfortran.dylib PATHS /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10) - find_library(LAPACK NAME liblapack.dylib PATHS /usr/lib) - find_library(OPENMP NAME libiomp5.dylib PATHS /opt/intel/oneapi/compiler/2021.1.1/mac/compiler/lib) - include_directories (BEFORE ${MKLROOT}/include) - set(PROJECT_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES}) - set(MKL_LINK "-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl") - add_definitions(-DEIGEN_USE_MKL_ALL) -else() - set(MKL_LINK "") -endif(USE_MKL) - -include_directories (BEFORE ../external) -include_directories (BEFORE ../include) - -#for Eigen -if (${CMAKE_VERSION} VERSION_LESS "3.12.0") - add_compile_options(-D "EIGEN_NO_DEBUG") -else () - add_compile_definitions("EIGEN_NO_DEBUG") -endif () - -add_definitions(${CMAKE_CXX_FLAGS} "-g") # enable debuger -#add_definitions(${CMAKE_CXX_FLAGS} "-Wint-in-bool-context") -#add_definitions(${CMAKE_CXX_FLAGS} "-Wall") - -add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler -add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") #enable the c++17 support needed by autodiff -#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl") -add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm") -add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl") -add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR") -add_definitions(${CMAKE_CXX_FLAGS} "-DMKL_ILP64") -#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas") -#add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" ) - -add_executable (new_volume_example new_volume_example.cpp) -add_executable (benchmarks_sob benchmarks_sob.cpp) -add_executable (benchmarks_cg benchmarks_cg.cpp) -add_executable (benchmarks_cb benchmarks_cb.cpp) - -add_library(test_main OBJECT test_main.cpp) - -add_executable (mcmc_diagnostics_test mcmc_diagnostics_test.cpp $) -add_test(NAME test_psrf COMMAND mcmc_diagnostics_test -tc=psrf) -add_test(NAME test_univariate_psrf COMMAND mcmc_diagnostics_test -tc=univariate_psrf) -add_test(NAME test_interval_psrf COMMAND mcmc_diagnostics_test -tc=interval_psrf) -add_test(NAME test_ess COMMAND mcmc_diagnostics_test -tc=ess) -add_test(NAME test_geweke COMMAND mcmc_diagnostics_test -tc=geweke) -add_test(NAME test_raftery COMMAND mcmc_diagnostics_test -tc=raftery) - -add_executable (sampling_test sampling_test.cpp $) -add_test(NAME test_dikin COMMAND sampling_test -tc=dikin) -add_test(NAME test_john COMMAND sampling_test -tc=john) -add_test(NAME test_vaidya COMMAND sampling_test -tc=vaidya) -add_test(NAME test_brdhr COMMAND sampling_test -tc=brdhr) -add_test(NAME test_bcdhr COMMAND sampling_test -tc=bcdhr) -add_test(NAME test_grdhr COMMAND sampling_test -tc=grdhr) -add_test(NAME test_gbaw COMMAND sampling_test -tc=gbaw) -add_test(NAME test_ghmc COMMAND sampling_test -tc=ghmc) - -add_executable (mmcs_test mmcs_test.cpp $) -add_test(NAME test_mmcs COMMAND mmcs_test -tc=mmcs) - -add_executable (ode_solvers_test ode_solvers_test.cpp $) -add_test(NAME ode_solvers_test_first_order - COMMAND ode_solvers_test -tc=first_order) -add_test(NAME ode_solvers_test_second_order - COMMAND ode_solvers_test -tc=second_order) - -add_executable (root_finders_test root_finders_test.cpp $) -add_test(NAME root_finders_test_root_finders - COMMAND root_finders_test -tc=root_finders) - -#add_executable (benchmarks_crhmc benchmarks_crhmc.cpp ) -#add_executable (benchmarks_crhmc_sampling benchmarks_crhmc_sampling.cpp ) - -add_executable (crhmc_polytope_preparation_test crhmc_polytope_preparation_test.cpp $) -add_test(NAME crhmc_polytope_test_preparation - COMMAND crhmc_polytope_preparation_test -tc=test_preparation_crhmc) -add_test(NAME crhmc_test_fixed_vars - COMMAND crhmc_polytope_preparation_test -tc=test_fixed_vars_crhmc) -add_test(NAME crhmc_test_dep_vars - COMMAND crhmc_polytope_preparation_test -tc=test_dep_vars_crhmc) -add_test(NAME crhmc_test_center_computation - COMMAND crhmc_polytope_preparation_test -tc=test_center_computation) - -add_executable (boundary_oracles_test boundary_oracles_test.cpp $) -add_test(NAME boundary_oracles_test_h_poly_oracles - COMMAND boundary_oracles_test -tc=h_poly_oracles) - -add_executable (volume_sob_hpolytope volume_sob_hpolytope.cpp $) -add_test(NAME volume_sob_hpolytope_cube COMMAND volume_sob_hpolytope -tc=cube) -add_test(NAME volume_sob_hpolytope_cross COMMAND volume_sob_hpolytope -tc=cross) -add_test(NAME volume_sob_hpolytope_birkhoff COMMAND volume_sob_hpolytope -tc=birk) -add_test(NAME volume_sob_hpolytope_prod_simplex COMMAND volume_sob_hpolytope -tc=prod_simplex) -add_test(NAME volume_sob_hpolytope_simplex COMMAND volume_sob_hpolytope -tc=simplex) -add_test(NAME volume_sob_hpolytope_skinny_cube COMMAND volume_sob_hpolytope -tc=skinny_cube) -add_test(NAME volume_sob_hpolytope_cube_overflow COMMAND volume_sob_hpolytope -tc=cube_overflow) -set_property(TEST volume_sob_hpolytope_cube_overflow PROPERTY TIMEOUT 1) - -add_executable (volume_sob_vpolytope volume_sob_vpolytope.cpp $) -add_test(NAME volume_sob_vpolytope_cube COMMAND volume_sob_vpolytope -tc=cube) -add_test(NAME volume_sob_vpolytope_cross COMMAND volume_sob_vpolytope -tc=cross) -add_test(NAME volume_sob_vpolytope_simplex COMMAND volume_sob_vpolytope -tc=simplex) - -add_executable (volume_cg_hpolytope volume_cg_hpolytope.cpp $) -add_test(NAME volume_cg_hpolytope_cube COMMAND volume_cg_hpolytope -tc=cube) -add_test(NAME volume_cg_hpolytope_cross COMMAND volume_cg_hpolytope -tc=cross) -add_test(NAME volume_cg_hpolytope_birkhoff COMMAND volume_cg_hpolytope -tc=birk) -add_test(NAME volume_cg_hpolytope_prod_simplex COMMAND volume_cg_hpolytope -tc=prod_simplex) -add_test(NAME volume_cg_hpolytope_simplex COMMAND volume_cg_hpolytope -tc=simplex) -add_test(NAME volume_cg_hpolytope_skinny_cube COMMAND volume_cg_hpolytope -tc=skinny_cube) - -add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $) -add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube) -add_test(NAME volume_cg_vpolytope_cross COMMAND volume_cg_vpolytope -tc=cross) -add_test(NAME volume_cg_vpolytope_simplex COMMAND volume_cg_vpolytope -tc=simplex) - -add_executable (volume_cb_hpolytope volume_cb_hpolytope.cpp $) -add_test(NAME volume_cb_hpolytope_cube COMMAND volume_cb_hpolytope -tc=cube) -add_test(NAME volume_cb_hpolytope_cross COMMAND volume_cb_hpolytope -tc=cross) -add_test(NAME volume_cb_hpolytope_birkhoff COMMAND volume_cb_hpolytope -tc=birk) -add_test(NAME volume_cb_hpolytope_prod_simplex COMMAND volume_cb_hpolytope -tc=prod_simplex) -add_test(NAME volume_cb_hpolytope_simplex COMMAND volume_cb_hpolytope -tc=simplex) -add_test(NAME volume_cb_hpolytope_skinny_cube COMMAND volume_cb_hpolytope -tc=skinny_cube) - -add_executable (volume_cb_vpolytope volume_cb_vpolytope.cpp $) -add_test(NAME volume_cb_vpolytope_cube COMMAND volume_cb_vpolytope -tc=cube) -add_test(NAME volume_cb_vpolytope_cross COMMAND volume_cb_vpolytope -tc=cross) -add_test(NAME volume_cb_vpolytope_simplex COMMAND volume_cb_vpolytope -tc=simplex) - -add_executable (volume_cb_zonotopes volume_cb_zonotopes.cpp $) -add_test(NAME volume_cb_zonotopes_uniform_zonotopes - COMMAND volume_cb_zonotopes -tc=uniform_zonotopes) - -add_executable (volume_cb_vpoly_intersection_vpoly volume_cb_vpoly_intersection_vpoly.cpp $) -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_test(NAME test_round_min_ellipsoid - COMMAND rounding_test -tc=round_min_ellipsoid) -add_test(NAME test_round_max_ellipsoid - COMMAND 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_executable (logconcave_sampling_test logconcave_sampling_test.cpp $) -add_test(NAME logconcave_sampling_test_hmc - COMMAND logconcave_sampling_test -tc=hmc) -add_test(NAME logconcave_sampling_test_uld - COMMAND logconcave_sampling_test -tc=uld) -add_test(NAME logconcave_sampling_test_exponential_biomass_sampling - COMMAND logconcave_sampling_test -tc=exponential_biomass_sampling) -add_test(NAME logconcave_sampling_test_nuts_hmc_truncated - COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc_truncated) -add_test(NAME logconcave_sampling_test_nuts_hmc - COMMAND logconcave_sampling_test -tc=benchmark_nuts_hmc) - - - -add_executable (crhmc_sampling_test crhmc_sampling_test.cpp $) -add_test(NAME crhmc_sampling_test_crhmc - COMMAND crhmc_sampling_test -tc=crhmc) -add_test(NAME crhmc_test_polytope_sampling - COMMAND crhmc_sampling_test -tc=test_polytope_sampling_crhmc) -add_test(NAME crhmc_test_sparse_sampling - COMMAND crhmc_sampling_test -tc=test_sampling_sparse_problem) -add_executable (simple_mc_integration simple_mc_integration.cpp $) -add_test(NAME simple_mc_integration_over_limits - COMMAND simple_mc_integration -tc=rectangle) -add_test(NAME simple_mc_integration_over_cubes - COMMAND simple_mc_integration -tc=cube) -add_test(NAME simple_mc_integration_over_simplices - COMMAND simple_mc_integration -tc=simplex) -add_test(NAME simple_mc_integration_over_product_simplices - COMMAND simple_mc_integration -tc=prod_simplex) -add_test(NAME simple_mc_integration_over_cross_polytopes - COMMAND simple_mc_integration -tc=cross) -add_test(NAME simple_mc_integration_over_birkhoff_polytopes - COMMAND simple_mc_integration -tc=birkhoff) - -add_executable (order_polytope order_polytope.cpp $) -add_test(NAME order_polytope_basics COMMAND order_polytope -tc=basics) -add_test(NAME order_polytope_line_intersect COMMAND order_polytope -tc=line_intersect) -add_test(NAME order_polytope_reflection COMMAND order_polytope -tc=reflection) -add_test(NAME order_polytope_vec_mult COMMAND order_polytope -tc=vec_mult) - -add_executable (matrix_sampling_test sampling_correlation_matrices_test.cpp $) -add_test(NAME test_corre_spectra_classes COMMAND matrix_sampling_test -tc=corre_spectra) -add_test(NAME test_new_ball_uniform COMMAND matrix_sampling_test -tc=new_ball_uniform) -add_test(NAME test_new_billiard_uniform COMMAND matrix_sampling_test -tc=new_billiard_uniform) -add_test(NAME test_new_accelerated_billiard_uniform COMMAND matrix_sampling_test -tc=new_accelerated_billiard_uniform) -add_test(NAME test_new_ball_uniform_MT COMMAND matrix_sampling_test -tc=new_ball_uniform_MT) -add_test(NAME test_new_rdhr_uniform_MT COMMAND matrix_sampling_test -tc=new_rdhr_uniform_MT) -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) - - - -set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") - -#set_target_properties(benchmarks_crhmc -# PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -#set_target_properties(benchmarks_crhmc_sampling -# PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -set_target_properties(crhmc_polytope_preparation_test - PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) -set_target_properties(crhmc_sampling_test - PROPERTIES COMPILE_FLAGS ${ADDITIONAL_FLAGS}) - -TARGET_LINK_LIBRARIES(new_volume_example lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(new_volume_example lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_sob_hpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_sob_vpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cg_hpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cg_vpolytope lp_solve coverage_config) -TARGET_LINK_LIBRARIES(volume_cb_hpolytope lp_solve coverage_config) -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(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) -TARGET_LINK_LIBRARIES(benchmarks_sob lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(benchmarks_cg lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(benchmarks_cb lp_solve ${MKL_LINK} coverage_config) -#TARGET_LINK_LIBRARIES(benchmarks_crhmc_sampling lp_solve ${MKL_LINK} QD_LIB coverage_config) -#TARGET_LINK_LIBRARIES(benchmarks_crhmc lp_solve ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(simple_mc_integration lp_solve ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(ode_solvers_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(boundary_oracles_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(root_finders_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -TARGET_LINK_LIBRARIES(crhmc_polytope_preparation_test ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} QD_LIB coverage_config) -TARGET_LINK_LIBRARIES(logconcave_sampling_test lp_solve ${IFOPT} ${IFOPT_IPOPT} ${PTHREAD} ${GMP} ${MPSOLVE} ${FFTW3} ${MKL_LINK} coverage_config) -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/rounding_test.cpp b/test/rounding_test.cpp index 7e15c99a5..3817cebb3 100644 --- a/test/rounding_test.cpp +++ b/test/rounding_test.cpp @@ -198,6 +198,36 @@ void rounding_log_barrier_test(Polytope &HP, test_values(volume, expectedBilliard, exact); } +template +void rounding_volumetric_barrier_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 = 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, @@ -284,6 +314,18 @@ void call_test_log_barrier() { rounding_log_barrier_test(P, 0, 3070.64, 3188.25, 3262.77, 3200.0); } +template +void call_test_volumetric_barrier() { + typedef Cartesian Kernel; + typedef typename Kernel::Point Point; + typedef HPolytope Hpolytope; + Hpolytope P; + + std::cout << "\n--- Testing volumetric barrier rounding of H-skinny_cube5" << std::endl; + P = generate_skinny_cube(5); + rounding_volumetric_barrier_test(P, 0, 3070.64, 3188.25, 3262.77, 3200.0); +} + template void call_test_svd() { @@ -314,6 +356,10 @@ TEST_CASE("round_log_barrier_test") { call_test_log_barrier(); } +TEST_CASE("round_volumetric_barrier_test") { + call_test_volumetric_barrier(); +} + TEST_CASE("round_svd") { call_test_svd(); } diff --git a/test/test_internal_points.cpp b/test/test_internal_points.cpp index f54252e08..4caf0ecce 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -17,8 +17,9 @@ #include "convex_bodies/hpolytope.h" #include "preprocess/max_inscribed_ball.hpp" -#include "preprocess/analytic_center_ellipsoid.hpp" -#include "preprocess/volumetric_center_ellipsoid.hpp" +//#include "preprocess/analytic_center_ellipsoid.hpp" +//#include "preprocess/volumetric_center_ellipsoid.hpp" +#include "preprocess/barrier_center_ellipsoid.hpp" #include "generators/known_polytope_generators.h" #include "generators/h_polytopes_generator.h" @@ -130,10 +131,10 @@ void call_test_analytic_center() { P = skinny_random_hpoly(3, 15, pre_rounding, max_min_eig_ratio, 127); P.normalize(); - auto [Hessian, analytic_center, converged] = analytic_center_ellipsoid_linear_ineq(P.get_mat(), P.get_vec()); + auto [Hessian, analytic_center, converged] = barrier_center_ellipsoid_linear_ineq(P.get_mat(), P.get_vec()); SpMT Asp = P.get_mat().sparseView(); - auto [Hessian_sp, analytic_center2, converged2] = analytic_center_ellipsoid_linear_ineq(Asp, P.get_vec()); + auto [Hessian_sp, analytic_center2, converged2] = barrier_center_ellipsoid_linear_ineq(Asp, P.get_vec()); CHECK(P.is_in(Point(analytic_center)) == -1); CHECK(converged); @@ -166,26 +167,21 @@ void call_test_volumetric_center() { NT max_min_eig_ratio = NT(100); P = skinny_random_hpoly(3, 15, pre_rounding, max_min_eig_ratio, 127); P.normalize(); - std::cout<<"A:\n"<(P.get_mat(), P.get_vec()); + auto [Hessian, volumetric_center, converged] = barrier_center_ellipsoid_linear_ineq(P.get_mat(), P.get_vec()); SpMT Asp = P.get_mat().sparseView(); - - auto [Hessian_sp, analytic_center2, converged2] = volumetric_center_ellipsoid_linear_ineq(Asp, P.get_vec()); - std::cout<<"analytic_center: "<(Asp, P.get_vec()); + CHECK(P.is_in(Point(volumetric_center)) == -1); CHECK(converged); - CHECK(std::abs(analytic_center(0) + 4.75912) < 1e-04); - CHECK(std::abs(analytic_center(1) + 4.28762) < 1e-04); - CHECK(std::abs(analytic_center(2) - 7.54156) < 1e-04); + CHECK(std::abs(volumetric_center(0) + 1.49031) < 1e-04); + CHECK(std::abs(volumetric_center(1) + 1.51709) < 1e-04); + CHECK(std::abs(volumetric_center(2) - 2.49381) < 1e-04); - CHECK(P.is_in(Point(analytic_center2)) == -1); + CHECK(P.is_in(Point(volumetric_center2)) == -1); CHECK(converged2); - CHECK(std::abs(analytic_center(0) - analytic_center2(0)) < 1e-12); - CHECK(std::abs(analytic_center(1) - analytic_center2(1)) < 1e-12); - CHECK(std::abs(analytic_center(2) - analytic_center2(2)) < 1e-12); + CHECK(std::abs(volumetric_center(0) - volumetric_center2(0)) < 1e-12); + CHECK(std::abs(volumetric_center(1) - volumetric_center2(1)) < 1e-12); + CHECK(std::abs(volumetric_center(2) - volumetric_center2(2)) < 1e-12); CHECK((Hessian - Hessian_sp).norm() < 1e-12); } From a32319e893fc5e30ebe6c9b42696e7175e696911 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Sun, 30 Jun 2024 17:24:55 -0600 Subject: [PATCH 18/20] remove unused comments --- test/test_internal_points.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/test_internal_points.cpp b/test/test_internal_points.cpp index 4a6bd76ec..e1b7a05bb 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -17,8 +17,6 @@ #include "convex_bodies/hpolytope.h" #include "preprocess/max_inscribed_ball.hpp" -//#include "preprocess/analytic_center_ellipsoid.hpp" -//#include "preprocess/volumetric_center_ellipsoid.hpp" #include "preprocess/barrier_center_ellipsoid.hpp" #include "generators/known_polytope_generators.h" From 9d5a13f53d7097b598e31e47492bcb417e77fe0e Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Thu, 4 Jul 2024 23:33:18 -0600 Subject: [PATCH 19/20] resolve PR comments --- include/preprocess/barrier_center_ellipsoid.hpp | 6 +++--- include/preprocess/inscribed_ellipsoid_rounding.hpp | 2 +- test/test_internal_points.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/preprocess/barrier_center_ellipsoid.hpp b/include/preprocess/barrier_center_ellipsoid.hpp index cfbfebc27..ecab24d40 100644 --- a/include/preprocess/barrier_center_ellipsoid.hpp +++ b/include/preprocess/barrier_center_ellipsoid.hpp @@ -42,7 +42,7 @@ Note: Using MT as to deal with both dense and sparse matrices, MT_dense will be the type of result matrix */ -template +template std::tuple barrier_center_ellipsoid_linear_ineq(MT const& A, VT const& b, VT const& x0, unsigned int const max_iters = 500, NT const grad_err_tol = 1e-08, @@ -102,14 +102,14 @@ std::tuple barrier_center_ellipsoid_linear_ineq(MT const& A return std::make_tuple(MT_dense(H), x, converged); } -template +template std::tuple barrier_center_ellipsoid_linear_ineq(MT const& A, VT const& b, unsigned int const max_iters = 500, NT const grad_err_tol = 1e-08, NT const rel_pos_err_tol = 1e-12) { VT x0 = compute_feasible_point(A, b); - return barrier_center_ellipsoid_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); + return barrier_center_ellipsoid_linear_ineq(A, b, x0, max_iters, grad_err_tol, rel_pos_err_tol); } #endif // BARRIER_CENTER_ELLIPSOID_HPP diff --git a/include/preprocess/inscribed_ellipsoid_rounding.hpp b/include/preprocess/inscribed_ellipsoid_rounding.hpp index 720ff1f58..37468b9d9 100644 --- a/include/preprocess/inscribed_ellipsoid_rounding.hpp +++ b/include/preprocess/inscribed_ellipsoid_rounding.hpp @@ -28,7 +28,7 @@ compute_inscribed_ellipsoid(Custom_MT A, VT b, VT const& x0, } else if constexpr (ellipsoid_type == EllipsoidType::LOG_BARRIER || ellipsoid_type == EllipsoidType::VOLUMETRIC_BARRIER) { - return barrier_center_ellipsoid_linear_ineq(A, b, x0); + return barrier_center_ellipsoid_linear_ineq(A, b, x0); } else { std::runtime_error("Unknown rounding method."); diff --git a/test/test_internal_points.cpp b/test/test_internal_points.cpp index e1b7a05bb..50965128c 100644 --- a/test/test_internal_points.cpp +++ b/test/test_internal_points.cpp @@ -129,10 +129,10 @@ void call_test_analytic_center() { P = skinny_random_hpoly(3, 15, pre_rounding, max_min_eig_ratio, 127); P.normalize(); - auto [Hessian, analytic_center, converged] = barrier_center_ellipsoid_linear_ineq(P.get_mat(), P.get_vec()); + auto [Hessian, analytic_center, converged] = barrier_center_ellipsoid_linear_ineq(P.get_mat(), P.get_vec()); SpMT Asp = P.get_mat().sparseView(); - auto [Hessian_sp, analytic_center2, converged2] = barrier_center_ellipsoid_linear_ineq(Asp, P.get_vec()); + auto [Hessian_sp, analytic_center2, converged2] = barrier_center_ellipsoid_linear_ineq(Asp, P.get_vec()); CHECK(P.is_in(Point(analytic_center)) == -1); CHECK(converged); @@ -166,9 +166,9 @@ void call_test_volumetric_center() { P = skinny_random_hpoly(3, 15, pre_rounding, max_min_eig_ratio, 127); P.normalize(); - auto [Hessian, volumetric_center, converged] = barrier_center_ellipsoid_linear_ineq(P.get_mat(), P.get_vec()); + auto [Hessian, volumetric_center, converged] = barrier_center_ellipsoid_linear_ineq(P.get_mat(), P.get_vec()); SpMT Asp = P.get_mat().sparseView(); - auto [Hessian_sp, volumetric_center2, converged2] = barrier_center_ellipsoid_linear_ineq(Asp, P.get_vec()); + auto [Hessian_sp, volumetric_center2, converged2] = barrier_center_ellipsoid_linear_ineq(Asp, P.get_vec()); CHECK(P.is_in(Point(volumetric_center)) == -1); CHECK(converged); CHECK(std::abs(volumetric_center(0) + 1.49031) < 1e-04); From 259ddc8253bdbd191e49e97f8ee160ad4f86c3b7 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Sun, 7 Jul 2024 11:21:35 -0600 Subject: [PATCH 20/20] remove NT typename from max_step() --- include/preprocess/barrier_center_ellipsoid.hpp | 2 +- include/preprocess/rounding_util_functions.hpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/preprocess/barrier_center_ellipsoid.hpp b/include/preprocess/barrier_center_ellipsoid.hpp index ecab24d40..0ab8c0457 100644 --- a/include/preprocess/barrier_center_ellipsoid.hpp +++ b/include/preprocess/barrier_center_ellipsoid.hpp @@ -69,7 +69,7 @@ std::tuple barrier_center_ellipsoid_linear_ineq(MT const& A d.noalias() = - solve_vec(llt, H, grad); Ad.noalias() = A * d; // Compute the step length - step = std::min(max_step_multiplier * get_max_step(Ad, b_Ax), step_iter); + step = std::min(max_step_multiplier * get_max_step(Ad, b_Ax), step_iter); step_d.noalias() = step*d; x_prev = x; x += step_d; diff --git a/include/preprocess/rounding_util_functions.hpp b/include/preprocess/rounding_util_functions.hpp index 1ee859b25..6b94ace8b 100644 --- a/include/preprocess/rounding_util_functions.hpp +++ b/include/preprocess/rounding_util_functions.hpp @@ -31,9 +31,10 @@ struct AssertBarrierFalseType : std::false_type {}; template struct AssertFalseType : std::false_type {}; -template -NT get_max_step(VT const& Ad, VT const& b_Ax) +template +auto get_max_step(VT const& Ad, VT const& b_Ax) { + using NT = typename VT::Scalar; const int m = Ad.size(); NT max_element = std::numeric_limits::lowest(), max_element_temp; for (int i = 0; i < m; i++) {