Skip to content

Commit 93d051b

Browse files
authored
Merge branch 'GeomScale:develop' into feature/tuning
2 parents e2275aa + de6fc6f commit 93d051b

25 files changed

+1149
-184
lines changed

examples/correlation_matrices/sampler.cpp

+13-27
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,6 @@ void write_to_file(std::string filename, std::vector<PointType> const& randPoint
9292
std::cout.rdbuf(coutbuf);
9393
}
9494

95-
bool is_correlation_matrix(const MT& matrix, const double tol = 1e-8){
96-
//check if all the diagonal elements are ones
97-
for(int i=0 ; i<matrix.rows() ; i++)
98-
{
99-
if(std::abs(matrix(i, i)-1.0) > tol)
100-
{
101-
return false;
102-
}
103-
}
104-
105-
//check if the matrix is positive semidefinite
106-
using NT = double;
107-
using MatrixType = Eigen::Matrix<NT, Eigen::Dynamic, Eigen::Dynamic>;
108-
EigenvaluesProblems<NT, MatrixType, Eigen::Matrix<NT, Eigen::Dynamic, 1>> solver;
109-
110-
if(solver.isPositiveSemidefinite(matrix))
111-
{
112-
return true;
113-
}
114-
return false;
115-
}
116-
11795
template<typename WalkType>
11896
void correlation_matrix_uniform_sampling(const unsigned int n, const unsigned int num_points, std::string walkname){
11997

@@ -140,26 +118,34 @@ void correlation_matrix_uniform_sampling_MT(const unsigned int n, const unsigned
140118
std::cout << walkname << " samples uniformly "<< num_points << " correlation matrices of size " << n << " with matrix PointType" << std::endl;
141119
std::chrono::steady_clock::time_point start, end;
142120
double time;
143-
std::vector<PointMT> randPoints;
121+
std::list<MT> randCorMatrices;
144122
unsigned int walkL = 1;
145123

146124
start = std::chrono::steady_clock::now();
147125

148-
uniform_correlation_sampling_MT<WalkType, PointMT, RNGType>(n, randPoints, walkL, num_points, 0);
126+
uniform_correlation_sampling_MT<WalkType, PointMT, RNGType>(n, randCorMatrices, walkL, num_points, 0);
149127

150128
end = std::chrono::steady_clock::now();
151129
time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
152130
std::cout << "Elapsed time : " << time << " (ms)" << std::endl;
153131

154132
int valid_points = 0;
155133
EigenvaluesProblems<NT, MT, Eigen::Matrix<NT, Eigen::Dynamic, 1>> solver;
156-
for(const auto& points : randPoints){
157-
if(solver.is_correlation_matrix(points.mat)){
134+
for(const auto& matrix : randCorMatrices){
135+
if(solver.is_correlation_matrix(matrix)){
158136
valid_points++;
159-
}
137+
}
160138
}
139+
161140
std::cout << "Number of valid points = " << valid_points << std::endl;
162141

142+
std::vector<PointMT> randPoints;
143+
for(const auto &mat : randCorMatrices){
144+
PointMT p;
145+
p.mat = mat;
146+
randPoints.push_back(p);
147+
}
148+
163149
write_to_file<PointMT>(walkname + "_matrices_MT" + std::to_string(n) + ".txt", randPoints);
164150
}
165151

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# VolEsti (volume computation and sampling library)
2+
3+
# Copyright (c) 2012-2024 Vissarion Fisikopoulos
4+
# Copyright (c) 2018-2024 Apostolos Chalkis
5+
# Copyright (c) 2024 Vladimir Necula
6+
7+
# Contributed and/or modified by Vladimir Necula, as part of Google Summer of
8+
# Code 2024 program.
9+
10+
# Licensed under GNU LGPL.3, see LICENCE file
11+
12+
project( VolEsti )
13+
14+
15+
CMAKE_MINIMUM_REQUIRED(VERSION 3.11)
16+
17+
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
18+
19+
# Locate Intel MKL root (in case it is enabled)
20+
if (APPLE)
21+
set(MKLROOT /opt/intel/oneapi/mkl/latest)
22+
elseif(UNIX)
23+
#set(MKLROOT /opt/intel/oneapi/mkl/latest)
24+
set(MKLROOT $ENV{HOME}/intel/mkl)
25+
endif()
26+
27+
if(COMMAND cmake_policy)
28+
cmake_policy(SET CMP0003 NEW)
29+
endif(COMMAND cmake_policy)
30+
31+
32+
option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON)
33+
option(BUILTIN_EIGEN "Use eigen from ../../external" OFF)
34+
option(USE_MKL "Use MKL library to build eigen" OFF)
35+
36+
37+
if(DISABLE_NLP_ORACLES)
38+
add_definitions(-DDISABLE_NLP_ORACLES)
39+
else()
40+
find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib)
41+
find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib)
42+
find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu)
43+
find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib)
44+
find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu)
45+
find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu)
46+
47+
if (NOT IFOPT)
48+
49+
message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.")
50+
51+
elseif (NOT GMP)
52+
53+
message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.")
54+
55+
elseif (NOT MPSOLVE)
56+
57+
message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.")
58+
59+
elseif (NOT FFTW3)
60+
61+
message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.")
62+
63+
else()
64+
message(STATUS "Library ifopt found: ${IFOPT}")
65+
message(STATUS "Library gmp found: ${GMP}")
66+
message(STATUS "Library mpsolve found: ${MPSOLVE}")
67+
message(STATUS "Library fftw3 found:" ${FFTW3})
68+
69+
endif(NOT IFOPT)
70+
71+
endif(DISABLE_NLP_ORACLES)
72+
73+
include("../../external/cmake-files/Eigen.cmake")
74+
GetEigen()
75+
76+
include("../../external/cmake-files/Boost.cmake")
77+
GetBoost()
78+
79+
include("../../external/cmake-files/LPSolve.cmake")
80+
GetLPSolve()
81+
82+
include("../../external/cmake-files/QD.cmake")
83+
GetQD()
84+
85+
# Find lpsolve library
86+
find_library(LP_SOLVE NAMES liblpsolve55.so PATHS /usr/lib/lp_solve)
87+
88+
if (NOT LP_SOLVE)
89+
message(FATAL_ERROR "This program requires the lp_solve library, and will not be compiled.")
90+
else ()
91+
message(STATUS "Library lp_solve found: ${LP_SOLVE}")
92+
93+
set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
94+
95+
if (USE_MKL)
96+
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)
97+
find_library(GFORTRAN NAME libgfortran.dylib PATHS /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10)
98+
find_library(LAPACK NAME liblapack.dylib PATHS /usr/lib)
99+
find_library(OPENMP NAME libiomp5.dylib PATHS /opt/intel/oneapi/compiler/2021.1.1/mac/compiler/lib)
100+
101+
include_directories (BEFORE ${MKLROOT}/include)
102+
set(PROJECT_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES})
103+
set(MKL_LINK "-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl")
104+
add_definitions(-DEIGEN_USE_MKL_ALL)
105+
else()
106+
set(MKL_LINK "")
107+
endif(USE_MKL)
108+
109+
include_directories (BEFORE ../../external)
110+
include_directories (BEFORE ../../external/minimum_ellipsoid)
111+
include_directories (BEFORE ../../include/)
112+
113+
# for Eigen
114+
if (${CMAKE_VERSION} VERSION_LESS "3.12.0")
115+
add_compile_options(-D "EIGEN_NO_DEBUG")
116+
else ()
117+
add_compile_definitions("EIGEN_NO_DEBUG")
118+
endif ()
119+
120+
121+
add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard
122+
set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING")
123+
add_definitions(${CMAKE_CXX_FLAGS} "-O3 -DTIME_KEEPING" ${ADDITIONAL_FLAGS}) # optimization of the compiler
124+
#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl")
125+
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm")
126+
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl")
127+
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR")
128+
129+
add_executable(volume_example volume_example.cpp)
130+
target_link_libraries(volume_example QD_LIB ${MKL_LINK} ${LP_SOLVE})
131+
132+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// VolEsti (volume computation and sampling library)
2+
3+
// Copyright (c) 2012-2024 Vissarion Fisikopoulos
4+
// Copyright (c) 2018-2024 Apostolos Chalkis
5+
// Copyright (c) 2024 Vladimir Necula
6+
7+
// Contributed and/or modified by Vladimir Necula, as part of Google Summer of
8+
// Code 2024 program.
9+
10+
// Licensed under GNU LGPL.3, see LICENCE file
11+
12+
#include "generators/known_polytope_generators.h"
13+
#include "random_walks/random_walks.hpp"
14+
#include "volume/volume_cooling_gaussians_crhmc.hpp"
15+
16+
#include <iostream>
17+
#include <fstream>
18+
#include "misc/misc.h"
19+
20+
typedef double NT;
21+
typedef Cartesian<NT> Kernel;
22+
typedef typename Kernel::Point Point;
23+
typedef BoostRandomNumberGenerator<boost::mt11213b, double> RandomNumberGenerator;
24+
typedef HPolytope<Point> HPOLYTOPE;
25+
26+
void calculateAndVerifyVolume(HPOLYTOPE& polytope) {
27+
int walk_len = 10;
28+
NT e = 0.1;
29+
30+
RandomNumberGenerator rng(polytope.dimension());
31+
32+
NT volume = volume_cooling_gaussians<HPOLYTOPE, RandomNumberGenerator>(polytope, rng, e, walk_len);
33+
34+
std::cout << "Volume " << volume << std::endl;
35+
}
36+
37+
int main() {
38+
39+
HPOLYTOPE simplex = generate_simplex<HPOLYTOPE>(2, false);
40+
std::cout << std::endl << "Simplex: " << std::endl;
41+
simplex.print();
42+
calculateAndVerifyVolume(simplex);
43+
44+
HPOLYTOPE cube = generate_cube<HPOLYTOPE>(3, false);
45+
std::cout << std::endl << "Cube: " << std::endl;
46+
cube.print();
47+
calculateAndVerifyVolume(cube);
48+
49+
HPOLYTOPE cross = generate_cross<HPOLYTOPE>(3, false);
50+
std::cout << std::endl << "Cross: " << std::endl;
51+
cross.print();
52+
calculateAndVerifyVolume(cross);
53+
54+
HPOLYTOPE birkhoff = generate_birkhoff<HPOLYTOPE>(3);
55+
std::cout << std::endl << "Birkhoff: " << std::endl;
56+
birkhoff.print();
57+
calculateAndVerifyVolume(birkhoff);
58+
59+
return 0;
60+
}

examples/sampling-hpolytope-with-billiard-walks/sampler.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "sampling/random_point_generators.hpp"
88
#include "random_walks/random_walks.hpp"
99
#include "preprocess/max_inscribed_ellipsoid.hpp"
10+
#include "preprocess/inscribed_ellipsoid_rounding.hpp"
1011
#include "convex_bodies/ellipsoid.h"
1112
#include "convex_bodies/hpolytope.h"
1213

@@ -69,23 +70,18 @@ void sample_using_gaussian_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned i
6970
Point q(HP.dimension()); // origin
7071

7172
// ----------- Get inscribed ellipsoid --------------------------------
72-
typedef Ellipsoid<Point> EllipsoidType;
7373
unsigned int max_iter = 150;
7474
NT tol = std::pow(10, -6.0), reg = std::pow(10, -4.0);
7575
VT x0 = q.getCoefficients();
76-
MT E;
7776
VT center;
7877
bool converged;
79-
std::tie(E, center, converged) = max_inscribed_ellipsoid<MT>(HP.get_mat(),
80-
HP.get_vec(), x0, max_iter, tol, reg);
81-
82-
if (!converged) // not converged
83-
throw std::runtime_error("max_inscribed_ellipsoid not converged");
84-
85-
EllipsoidType inscribed_ellipsoid(E);
78+
std::tuple<MT, VT, NT> ellipsoid = compute_inscribed_ellipsoid<MT, EllipsoidType::VOLUMETRIC_BARRIER>
79+
(HP.get_mat(), HP.get_vec(), x0, max_iter, tol, reg);
80+
81+
const MT E = get<0>(ellipsoid);
8682
// --------------------------------------------------------------------
8783

88-
Generator::apply(HP, q, inscribed_ellipsoid, num_points, walk_len,
84+
Generator::apply(HP, q, E, num_points, walk_len,
8985
randPoints, push_back_policy, rng);
9086
write_to_file(filename, randPoints);
9187
}

include/convex_bodies/ballintersectconvex.h

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ class BallIntersectPolytope {
5050
return P.get_vec();
5151
}
5252

53+
bool is_normalized () {
54+
return true;
55+
}
56+
57+
void normalize() {}
58+
5359
int is_in(PointType const& p) const
5460
{
5561
if (B.is_in(p)==-1)

include/convex_bodies/correlation_matrices/correlation_spectrahedron.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ class CorrelationSpectrahedron : public Spectrahedron<Point>{
261261
MT get_mat() const {
262262
return MT::Identity(this->d, this->d);
263263
}
264+
265+
bool is_normalized () {
266+
return true;
267+
}
268+
269+
void normalize() {}
264270
};
265271

266272
#endif //VOLESTI_CONVEX_BODIES_CORRELATION_MATRICES_VOLESTI_CORRELATION_SPECTRAHEDRON_HPP

0 commit comments

Comments
 (0)