Skip to content

Commit

Permalink
Fix tests and issue #8 (#60)
Browse files Browse the repository at this point in the history
* modify c++ tests

* improve input variable names in R functions

* check for negative error parameter in both interfaces

* update Rd files
  • Loading branch information
TolisChal committed Feb 24, 2020
1 parent 801b2dc commit 1cba5c3
Show file tree
Hide file tree
Showing 25 changed files with 94 additions and 83 deletions.
12 changes: 6 additions & 6 deletions R-proj/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ rounding <- function(P, random_walk = NULL, walk_length = NULL, parameters = NUL

#' Sample points from a convex Polytope (H-polytope, V-polytope or a zonotope) or use direct methods for uniform sampling from the unit or the canonical or an arbitrary \eqn{d}-dimensional simplex and the boundary or the interior of a \eqn{d}-dimensional hypersphere
#'
#' Sample N points with uniform or multidimensional spherical gaussian -centered in an internal point- target distribution.
#' Sample n points with uniform or multidimensional spherical gaussian -centered in an internal point- target distribution.
#' The \eqn{d}-dimensional unit simplex is the set of points \eqn{\vec{x}\in \R^d}, s.t.: \eqn{\sum_i x_i\leq 1}, \eqn{x_i\geq 0}. The \eqn{d}-dimensional canonical simplex is the set of points \eqn{\vec{x}\in \R^d}, s.t.: \eqn{\sum_i x_i = 1}, \eqn{x_i\geq 0}.
#'
#' @param P A convex polytope. It is an object from class (a) Hpolytope or (b) Vpolytope or (c) Zonotope.
#' @param N The number of points that the function is going to sample from the convex polytope. The default value is \eqn{100}.
#' @param n The number of points that the function is going to sample from the convex polytope. The default value is \eqn{100}.
#' @param distribution Optional. A string that declares the target distribution: a) \code{'uniform'} for the uniform distribution or b) \code{'gaussian'} for the multidimensional spherical distribution. The default target distribution is uniform.
#' @param random_walk Optional. A string that declares the random walk method: a) \code{'CDHR'} for Coordinate Directions Hit-and-Run, b) \code{'RDHR'} for Random Directions Hit-and-Run, c) \code{'BaW'} for Ball Walk or d) \code{'BiW'} for Billiard walk. The default walk is \code{'BiW'} for the uniform distribution or \code{'CDHR'} for the Normal distribution.
#' @param walk_length Optional. The number of the steps for the random walk. The default value is \eqn{1} for \code{'BiW'} and \eqn{\lfloor 10 + d/10\rfloor} otherwise, where \eqn{d} is the dimension that the polytope lies.
Expand All @@ -182,7 +182,7 @@ rounding <- function(P, random_walk = NULL, walk_length = NULL, parameters = NUL
#' @references \cite{Art B. Owen,
#' \dQuote{Monte Carlo theory, methods and examples,} \emph{ Art Owen,} 2009.}
#'
#' @return A \eqn{d\times N} matrix that contains, column-wise, the sampled points from the convex polytope P.
#' @return A \eqn{d\times n} matrix that contains, column-wise, the sampled points from the convex polytope P.
#' @examples
#' # uniform distribution from the 3d unit cube in V-representation using ball walk
#' P = gen_cube(3, 'V')
Expand All @@ -200,10 +200,10 @@ rounding <- function(P, random_walk = NULL, walk_length = NULL, parameters = NUL
#' # 10000 uniform points from a 2-d arbitrary simplex
#' V = matrix(c(2,3,-1,7,0,0),ncol = 2, nrow = 3, byrow = TRUE)
#' P = Vpolytope$new(V)
#' points = sample_points(P, N = 10000, exact = TRUE)
#' points = sample_points(P, n = 10000, exact = TRUE)
#' @export
sample_points <- function(P = NULL, N = NULL, distribution = NULL, random_walk = NULL, walk_length = NULL, exact = NULL, body = NULL, parameters = NULL, InnerPoint = NULL) {
.Call(`_volesti_sample_points`, P, N, distribution, random_walk, walk_length, exact, body, parameters, InnerPoint)
sample_points <- function(P = NULL, n = NULL, distribution = NULL, random_walk = NULL, walk_length = NULL, exact = NULL, body = NULL, parameters = NULL, InnerPoint = NULL) {
.Call(`_volesti_sample_points`, P, n, distribution, random_walk, walk_length, exact, body, parameters, InnerPoint)
}

#' The main function for volume approximation of a convex Polytope (H-polytope, V-polytope or a zonotope)
Expand Down
8 changes: 4 additions & 4 deletions R-proj/R/gen_cross.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' This function can be used to generate the \eqn{d}-dimensional cross polytope in H- or V-representation.
#'
#' @param dimension The dimension of the cross polytope.
#' @param repr A string to declare the representation. It has to be \code{'H'} for H-representation or \code{'V'} for V-representation.
#' @param rep A string to declare the representation. It has to be \code{'H'} for H-representation or \code{'V'} for V-representation.
#'
#' @return A polytope class representing a cross polytope in H- or V-representation.
#' @examples
Expand All @@ -13,13 +13,13 @@
#' # generate a 15-dimension cross polytope in V-representation
#' P = gen_cross(15, 'V')
#' @export
gen_cross <- function(dimension, repr) {
gen_cross <- function(dimension, rep) {

kind_gen = 2
m_gen = 0
if (repr == "V") {
if (rep == "V") {
Vpoly_gen = TRUE
} else if (repr == "H") {
} else if (rep == "H") {
Vpoly_gen = FALSE
} else {
stop('Not a known representation.')
Expand Down
8 changes: 4 additions & 4 deletions R-proj/R/gen_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' This function can be used to generate the \eqn{d}-dimensional unit hypercube \eqn{[-1,1]^d} in H- or V-representation.
#'
#' @param dimension The dimension of the hypercube
#' @param repr A string to declare the representation. It has to be \code{'H'} for H-representation or \code{'V'} for V-representation.
#' @param rep A string to declare the representation. It has to be \code{'H'} for H-representation or \code{'V'} for V-representation.
#'
#' @return A polytope class representing the unit \eqn{d}-dimensional hypercube in H- or V-representation.
#' @examples
Expand All @@ -13,13 +13,13 @@
#' # generate a 15-dimension hypercube in V-representation
#' P = gen_cube(15, 'V')
#' @export
gen_cube <- function(dimension, repr) {
gen_cube <- function(dimension, rep) {

kind_gen = 1
m_gen = 0
if (repr == "V") {
if (rep == "V") {
Vpoly_gen = TRUE
} else if (repr == "H") {
} else if (rep == "H") {
Vpoly_gen = FALSE
} else {
stop('Not a known representation.')
Expand Down
6 changes: 3 additions & 3 deletions R-proj/R/gen_rand_hpoly.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
#' This function can be used to generate a \eqn{d}-dimensional polytope in H-representation with \eqn{m} facets. We pick \eqn{m} random hyperplanes tangent on the \eqn{d}-dimensional unit hypersphere as facets.
#'
#' @param dimension The dimension of the convex polytope.
#' @param m The number of the facets.
#' @param nfacets The number of the facets.
#'
#' @return A polytope class representing a H-polytope.
#' @examples
#' # generate a 10-dimensional polytope with 50 facets
#' P = gen_rand_hpoly(10, 50)
#' @export
gen_rand_hpoly <- function(dimension, m) {
gen_rand_hpoly <- function(dimension, nfacets) {

kind_gen = 6
Vpoly_gen = FALSE

Mat = poly_gen(kind_gen, Vpoly_gen, FALSE, dimension, m)
Mat = poly_gen(kind_gen, Vpoly_gen, FALSE, dimension, nfacets)

# first column is the vector b
b = Mat[,1]
Expand Down
6 changes: 3 additions & 3 deletions R-proj/R/gen_rand_vpoly.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#' This function can be used to generate a \eqn{d}-dimensional polytope in V-representation with \eqn{m} vertices. We pick \eqn{m} random points from the boundary of the \eqn{d}-dimensional unit hypersphere as vertices.
#'
#' @param dimension The dimension of the convex polytope.
#' @param n_vertices The number of the vertices.
#' @param nvertices The number of the vertices.
#' @param generator The body that the generator samples uniformly the vertices from: (a) 'cube' or (b) 'sphere'.
#'
#' @return A polytope class representing a V-polytope.
#' @examples
#' # generate a 10-dimensional polytope defined as the convex hull of 25 random vertices
#' P = gen_rand_vpoly(10, 25)
#' @export
gen_rand_vpoly <- function(dimension, n_vertices, generator = NULL) {
gen_rand_vpoly <- function(dimension, nvertices, generator = NULL) {

kind_gen = 4

Expand All @@ -23,7 +23,7 @@ gen_rand_vpoly <- function(dimension, n_vertices, generator = NULL) {
}
}

Mat = poly_gen(kind_gen, TRUE, FALSE, dimension, n_vertices)
Mat = poly_gen(kind_gen, TRUE, FALSE, dimension, nvertices)

# first column is the vector b
b = Mat[,1]
Expand Down
6 changes: 3 additions & 3 deletions R-proj/R/gen_rand_zonotope.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' This function can be used to generate a random \eqn{d}-dimensional zonotope defined by the Minkowski sum of \eqn{m} \eqn{d}-dimensional segments. We consider \eqn{m} random directions in \eqn{R^d} and for each direction we pick a random length in \eqn{[(,\sqrt{d}]} in order to define \eqn{m} segments.
#'
#' @param dimension The dimension of the zonotope.
#' @param n_segments The number of segments that generate the zonotope.
#' @param nsegments The number of segments that generate the zonotope.
#' @param generator The distribution to pick the length of each segment from \eqn{[0,100]}: (a) 'uniform', (b) 'gaussian' or (c) 'exponential'.
#'
#' @return A polytope class representing a zonotope.
Expand All @@ -12,7 +12,7 @@
#' # generate a 10-dimensional zonotope defined by the Minkowski sum of 20 segments
#' P = gen_rand_zonotope(10, 20)
#' @export
gen_rand_zonotope <- function(dimension, n_segments, generator = NULL) {
gen_rand_zonotope <- function(dimension, nsegments, generator = NULL) {

kind_gen = 1

Expand All @@ -26,7 +26,7 @@ gen_rand_zonotope <- function(dimension, n_segments, generator = NULL) {
}
}

Mat = poly_gen(kind_gen, FALSE, TRUE, dimension, n_segments)
Mat = poly_gen(kind_gen, FALSE, TRUE, dimension, nsegments)

# first column is the vector b
b = Mat[,1]
Expand Down
8 changes: 4 additions & 4 deletions R-proj/R/gen_simplex.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' This function can be used to generate the \eqn{d}-dimensional unit simplex in H- or V-representation.
#'
#' @param dimension The dimension of the unit simplex.
#' @param repr A string to declare the representation. It has to be \code{'H'} for H-representation or \code{'V'} for V-representation.
#' @param rep A string to declare the representation. It has to be \code{'H'} for H-representation or \code{'V'} for V-representation.
#'
#' @return A polytope class representing the \eqn{d}-dimensional unit simplex in H- or V-representation.
#' @examples
Expand All @@ -13,13 +13,13 @@
#' # generate a 20-dimensional simplex in V-representation
#' P = gen_simplex(20, 'V')
#' @export
gen_simplex <- function(dimension, repr) {
gen_simplex <- function(dimension, rep) {

kind_gen = 3
m_gen = 0
if (repr == "V") {
if (rep == "V") {
Vpoly_gen = TRUE
} else if (repr == "H") {
} else if (rep == "H") {
Vpoly_gen = FALSE
} else {
stop('Not a known representation.')
Expand Down
4 changes: 2 additions & 2 deletions R-proj/man/gen_cross.Rd

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

4 changes: 2 additions & 2 deletions R-proj/man/gen_cube.Rd

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

4 changes: 2 additions & 2 deletions R-proj/man/gen_rand_hpoly.Rd

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

4 changes: 2 additions & 2 deletions R-proj/man/gen_rand_vpoly.Rd

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

4 changes: 2 additions & 2 deletions R-proj/man/gen_rand_zonotope.Rd

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

4 changes: 2 additions & 2 deletions R-proj/man/gen_simplex.Rd

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

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

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

14 changes: 7 additions & 7 deletions R-proj/man/sample_points.Rd

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

3 changes: 2 additions & 1 deletion R-proj/man/volume.Rd

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

4 changes: 2 additions & 2 deletions R-proj/man/zonotope_approximation.Rd

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

Loading

0 comments on commit 1cba5c3

Please sign in to comment.