Skip to content

Commit

Permalink
rounding and volume_cg unit tests for sparse hpoly
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaperju committed Jul 27, 2024
1 parent bf93e1f commit 08c0f66
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ test/Testing/Temporary/CTestCostData.txt
build/
.vscode
.DS_Store
.cache
8 changes: 4 additions & 4 deletions include/convex_bodies/hpolytope.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class HPolytope {
for (unsigned int i = 1; i < Pin.size(); i++) {
b(i - 1) = Pin[i][0];
for (unsigned int j = 1; j < _d + 1; j++) {
A(i - 1, j - 1) = -Pin[i][j];
A.coeffRef(i - 1, j - 1) = -Pin[i][j];
}
}
has_ball = false;
Expand Down Expand Up @@ -645,12 +645,12 @@ class HPolytope {

int m = num_of_hyperplanes();

lamdas.noalias() += A.col(rand_coord_prev)
* (r_prev[rand_coord_prev] - r[rand_coord_prev]);
lamdas.noalias() += (DenseMT)(A.col(rand_coord_prev)
* (r_prev[rand_coord_prev] - r[rand_coord_prev]));
NT* data = lamdas.data();

for (int i = 0; i < m; i++) {
NT a = A(i, rand_coord);
NT a = A.coeff(i, rand_coord);

if (a == NT(0)) {
//std::cout<<"div0"<<std::endl;
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ 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_test(NAME volume_cg_hpolytope_sparse_simplex COMMAND volume_cg_hpolytope -tc=sparse_simplex)

add_executable (volume_cg_vpolytope volume_cg_vpolytope.cpp $<TARGET_OBJECTS:test_main>)
add_test(NAME volume_cg_vpolytope_cube COMMAND volume_cg_vpolytope -tc=cube)
Expand Down Expand Up @@ -305,6 +306,8 @@ add_test(NAME round_volumetric_barrier_test
COMMAND rounding_test -tc=round_volumetric_barrier_test)
add_test(NAME round_vaidya_barrier_test
COMMAND rounding_test -tc=round_vaidya_barrier_test)
add_test(NAME round_sparse_test
COMMAND rounding_test -tc=round_sparse)



Expand Down
46 changes: 41 additions & 5 deletions test/rounding_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void rounding_min_ellipsoid_test(Polytope &HP,
{
typedef typename Polytope::PointType Point;
typedef typename Point::FT NT;
typedef typename Polytope::MT MT;
typedef typename Polytope::DenseMT MT;
typedef typename Polytope::VT VT;

int d = HP.dimension();
Expand Down Expand Up @@ -102,7 +102,7 @@ void rounding_max_ellipsoid_test(Polytope &HP,
{
typedef typename Polytope::PointType Point;
typedef typename Point::FT NT;
typedef typename Polytope::MT MT;
typedef typename Polytope::DenseMT MT;
typedef typename Polytope::VT VT;

int d = HP.dimension();
Expand Down Expand Up @@ -178,7 +178,7 @@ void rounding_log_barrier_test(Polytope &HP,
{
typedef typename Polytope::PointType Point;
typedef typename Point::FT NT;
typedef typename Polytope::MT MT;
typedef typename Polytope::DenseMT MT;
typedef typename Polytope::VT VT;

int d = HP.dimension();
Expand Down Expand Up @@ -208,7 +208,7 @@ void rounding_volumetric_barrier_test(Polytope &HP,
{
typedef typename Polytope::PointType Point;
typedef typename Point::FT NT;
typedef typename Polytope::MT MT;
typedef typename Polytope::DenseMT MT;
typedef typename Polytope::VT VT;

int d = HP.dimension();
Expand Down Expand Up @@ -238,7 +238,7 @@ void rounding_vaidya_barrier_test(Polytope &HP,
{
typedef typename Polytope::PointType Point;
typedef typename Point::FT NT;
typedef typename Polytope::MT MT;
typedef typename Polytope::DenseMT MT;
typedef typename Polytope::VT VT;

int d = HP.dimension();
Expand Down Expand Up @@ -381,6 +381,39 @@ void call_test_svd() {
rounding_svd_test(P, 0, 3070.64, 3188.25, 3140.6, 3200.0);
}

template <typename NT>
void call_test_sparse() {
typedef Cartesian <NT> Kernel;
typedef typename Kernel::Point Point;
typedef HPolytope <Point, Eigen::SparseMatrix<NT>> Hpolytope;
Hpolytope P;

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

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

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

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

std::cout << "\n--- Testing min ellipsoid rounding of sparse H-skinny_cube10" << std::endl;
P = generate_skinny_cube<Hpolytope>(10);
rounding_min_ellipsoid_test(P, 0, 122550, 108426, 105003.0, 102400.0);

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



TEST_CASE("round_min_ellipsoid") {
call_test_min_ellipsoid<double>();
Expand Down Expand Up @@ -410,3 +443,6 @@ TEST_CASE("round_svd") {
call_test_svd<double>();
}

TEST_CASE("round_sparse") {
call_test_sparse<double>();
}
30 changes: 30 additions & 0 deletions test/volume_cg_hpolytope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,32 @@ void call_test_skinny_cube() {
//test_volume(P, 104857600, 104857600.0);
}

template <typename NT>
void call_test_sparse_simplex() {
typedef Cartesian<NT> Kernel;
typedef typename Kernel::Point Point;

typedef HPolytope<Point, Eigen::SparseMatrix<NT>> Hpolytope;
Hpolytope SP;

std::cout << "--- Testing volume of sparse H-simplex10" << std::endl;
SP = generate_simplex<Hpolytope>(10, false);
test_volume(SP,
2.14048 * std::pow(10,-7),
2.70598 * std::pow(10,-7),
2.53893e-07,
1.0 / factorial(10.0));

std::cout << "--- Testing volume of sparse H-simplex20" << std::endl;
SP = generate_simplex<Hpolytope>(20, false);
test_volume(SP,
2.00646 * std::pow(10,-21),
4.16845 * std::pow(10,-19),
5.0348e-19,
1.0 / factorial(20.0));
}



TEST_CASE("cube") {
call_test_cube<double>();
Expand All @@ -276,3 +302,7 @@ TEST_CASE("simplex") {
TEST_CASE("skinny_cube") {
call_test_skinny_cube<double>();
}

TEST_CASE("sparse_simplex") {
call_test_sparse_simplex<double>();
}

0 comments on commit 08c0f66

Please sign in to comment.