Skip to content

Commit

Permalink
Estimate the logarithm of the polytope volume in CB algorithm (#157)
Browse files Browse the repository at this point in the history
* modify the cooling balls volume function to return both log_volume and volume estimated

* modify c++ tests

* update Rd files

* update R tests

* update c++ tests
  • Loading branch information
TolisChal authored May 4, 2021
1 parent 9fe4692 commit 0ce5001
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 126 deletions.
10 changes: 5 additions & 5 deletions R-proj/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ rotating <- function(P, T = NULL, seed = NULL) {
#' Internal rcpp function for the rounding of a convex polytope
#'
#' @param P A convex polytope (H- or V-representation or zonotope).
#' @param method Optional. The method to use for rounding, a) \code{'min_ellipsoid'} for the method based on mimimmum volume enclosing ellipsoid of a uniform sample from P, b) \code{'max_ellipsoid'} for the method based on maximum volume enclosed ellipsoid in P, (c) \code{'svd'} for the method based on svd decomposition. The default method is \code{'min_ellipsoid'} for all the representations.
#' @param method Optional. The method to use for rounding, a) \code{'min_ellipsoid'} for the method based on mimimmum volume enclosing ellipsoid of a uniform sample from P, b) \code{'max_ellipsoid'} for the method based on maximum volume enclosed ellipsoid in P, (c) \code{'isotropy'} for the method based on isotropy. The default method is \code{'min_ellipsoid'} for all the representations.
#' @param seed Optional. A fixed seed for the number generator.
#'
#' @keywords internal
Expand Down Expand Up @@ -410,7 +410,7 @@ loadSdpaFormatFile <- function(inputFile = NULL) {
.Call(`_volesti_loadSdpaFormatFile`, inputFile)
}

#' The main function for volume approximation of a convex Polytope (H-polytope, V-polytope, zonotope or intersection of two V-polytopes)
#' The main function for volume approximation of a convex Polytope (H-polytope, V-polytope, zonotope or intersection of two V-polytopes). It returns a list with two elements: (a) the logarithm of the estimated volume and (b) the estimated volume
#'
#' For the volume approximation can be used three algorithms. Either CoolingBodies (CB) or SequenceOfBalls (SOB) or CoolingGaussian (CG). An H-polytope with \eqn{m} facets is described by a \eqn{m\times d} matrix \eqn{A} and a \eqn{m}-dimensional vector \eqn{b}, s.t.: \eqn{P=\{x\ |\ Ax\leq b\} }. A V-polytope is defined as the convex hull of \eqn{m} \eqn{d}-dimensional points which correspond to the vertices of P. A zonotope is desrcibed by the Minkowski sum of \eqn{m} \eqn{d}-dimensional segments.
#'
Expand Down Expand Up @@ -439,15 +439,15 @@ loadSdpaFormatFile <- function(inputFile = NULL) {
#'
#' # calling SOB algorithm for a H-polytope (5d unit simplex)
#' HP = gen_cube(5,'H')
#' vol = volume(HP)
#' pair_vol = volume(HP)
#'
#' # calling CG algorithm for a V-polytope (3d simplex)
#' VP = gen_simplex(3,'V')
#' vol = volume(VP, settings = list("algorithm" = "CG"))
#' pair_vol = volume(VP, settings = list("algorithm" = "CG"))
#'
#' # calling CG algorithm for a 2-dimensional zonotope defined as the Minkowski sum of 4 segments
#' Z = gen_rand_zonotope(2, 4)
#' vol = volume(Z, settings = list("random_walk" = "RDHR", "walk_length" = 2))
#' pair_vol = volume(Z, settings = list("random_walk" = "RDHR", "walk_length" = 2))
#'
#' @export
volume <- function(P, settings = NULL, rounding = NULL, seed = NULL) {
Expand Down
2 changes: 1 addition & 1 deletion R-proj/R/round_polytope.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Given a convex H or V polytope or a zonotope as input this function brings the polytope in rounded position based on minimum volume enclosing ellipsoid of a pointset.
#'
#' @param P A convex polytope. It is an object from class (a) Hpolytope or (b) Vpolytope or (c) Zonotope.
#' @param method Optional. The method to use for rounding, a) \code{'mee'} for the method based on mimimmum volume enclosing ellipsoid of a dataset, b) \code{'mve'} for the method based on maximum volume enclosed ellipsoid, (c) \code{'svd'} for the method based on svd decomposition. The default method is \code{'mee'} for all the representations.
#' @param method Optional. The method to use for rounding, a) \code{'min_ellipsoid'} for the method based on mimimmum volume enclosing ellipsoid of a dataset, b) \code{'max_ellipsoid'} for the method based on maximum volume enclosed ellipsoid, (c) \code{'isotropy'} for the method based on svd decomposition. The default method is \code{'mee'} for all the representations.
#' @param seed Optional. A fixed seed for the number generator.
#'
#' @return A list with 4 elements: (a) a polytope of the same class as the input polytope class and (b) the element "T" which is the matrix of the inverse linear transformation that is applied on the input polytope, (c) the element "shift" which is the opposite vector of that which has shifted the input polytope, (d) the element "round_value" which is the determinant of the square matrix of the linear transformation that is applied on the input polytope.
Expand Down
2 changes: 1 addition & 1 deletion R-proj/man/round_polytope.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion R-proj/man/rounding.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions R-proj/man/volume.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions R-proj/src/rounding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::tuple<MT, VT, NT> apply_rounding(Polytope &P,
std::tuple<MT, VT, NT> round_res;
if (method_rcpp.compare(std::string("min_ellipsoid")) == 0) {
round_res = min_sampling_covering_ellipsoid_rounding<WalkType, MT, VT>(P, InnerBall, walkL, rng);
} else if (method_rcpp.compare(std::string("svd")) == 0) {
} else if (method_rcpp.compare(std::string("isotropy")) == 0) {
round_res = svd_rounding<WalkType, MT, VT>(P, InnerBall, walkL, rng);
} else {
throw Rcpp::exception("Unknown method!");
Expand All @@ -54,7 +54,7 @@ std::tuple<MT, VT, NT> apply_rounding(Polytope &P,
//' Internal rcpp function for the rounding of a convex polytope
//'
//' @param P A convex polytope (H- or V-representation or zonotope).
//' @param method Optional. The method to use for rounding, a) \code{'min_ellipsoid'} for the method based on mimimmum volume enclosing ellipsoid of a uniform sample from P, b) \code{'max_ellipsoid'} for the method based on maximum volume enclosed ellipsoid in P, (c) \code{'svd'} for the method based on svd decomposition. The default method is \code{'min_ellipsoid'} for all the representations.
//' @param method Optional. The method to use for rounding, a) \code{'min_ellipsoid'} for the method based on mimimmum volume enclosing ellipsoid of a uniform sample from P, b) \code{'max_ellipsoid'} for the method based on maximum volume enclosed ellipsoid in P, (c) \code{'isotropy'} for the method based on isotropy. The default method is \code{'min_ellipsoid'} for all the representations.
//' @param seed Optional. A fixed seed for the number generator.
//'
//' @keywords internal
Expand All @@ -76,7 +76,7 @@ Rcpp::List rounding (Rcpp::Reference P,
typedef Eigen::Matrix<NT,Eigen::Dynamic,Eigen::Dynamic> MT;

unsigned int n = P.field("dimension"), walkL = 2, type = P.field("type");
std::string method_rcpp = std::string("min_ellipsoid");
std::string method_rcpp = std::string("isotropy");
if(method.isNotNull()) {
method_rcpp = Rcpp::as<std::string>(method);
if (method_rcpp.compare(std::string("max_ellipsoid")) == 0 && type != 1) {
Expand Down
Loading

0 comments on commit 0ce5001

Please sign in to comment.