Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cran interface #81

Merged
merged 4 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions R-proj/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @param sigma Optional. The \eqn{d\times d} symmetric positive semidefine matrix that describes the family of concentric ellipsoids centered at the origin.
#' @param m The number of the slices for the copula. The default value is 100.
#' @param n The number of points to sample. The default value is \eqn{5\cdot 10^5}.
#' @param seed Optional. A fixed seed for the number generator.
#'
#' @references \cite{L. Cales, A. Chalkis, I.Z. Emiris, V. Fisikopoulos,
#' \dQuote{Practical volume computation of structured convex bodies, and an application to modeling portfolio dependencies and financial crises,} \emph{Proc. of Symposium on Computational Geometry, Budapest, Hungary,} 2018.}
Expand All @@ -31,8 +32,8 @@
#' cop = copula(r1 = h, sigma = E, m = 10, n = 100000)
#'
#' @export
copula <- function(r1 = NULL, r2 = NULL, sigma = NULL, m = NULL, n = NULL) {
.Call(`_volesti_copula`, r1, r2, sigma, m, n)
copula <- function(r1 = NULL, r2 = NULL, sigma = NULL, m = NULL, n = NULL, seed = NULL) {
.Call(`_volesti_copula`, r1, r2, sigma, m, n, seed)
}

#' Sample perfect uniformly distributed points from well known convex bodies: (a) the unit simplex, (b) the canonical simplex, (c) the boundary of a hypersphere or (d) the interior of a hypersphere.
Expand Down
5 changes: 3 additions & 2 deletions R-proj/R/compute_indicators.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#' @param n Optional. The number of points to sample. The default value is \eqn{5\cdot 10^5}.
#' @param nwarning Optional. The number of consecutive indicators larger than 1 required to declare a warning period. The default value is 60.
#' @param ncrisis Optional. The number of consecutive indicators larger than 1 required to declare a crisis period. The default value is 100.
#' @param seed Optional. A fixed seed for the number generator.
#'
#' @references \cite{L. Cales, A. Chalkis, I.Z. Emiris, V. Fisikopoulos,
#' \dQuote{Practical volume computation of structured convex bodies, and an application to modeling portfolio dependencies and financial crises,} \emph{Proc. of Symposium on Computational Geometry, Budapest, Hungary,} 2018.}
#'
#' @return A list that contains the indicators and the corresponding vector that label each time period with respect to the market state: a) normal, b) crisis, c) warning.
#'
#' @export
compute_indicators <- function(returns, win_length = NULL, m = NULL, n = NULL, nwarning = NULL, ncrisis = NULL) {
compute_indicators <- function(returns, win_length = NULL, m = NULL, n = NULL, nwarning = NULL, ncrisis = NULL, seed = NULL) {

if (is.null(win_length)) win_length = 60
if (is.null(m)) m = 100
Expand All @@ -43,7 +44,7 @@ compute_indicators <- function(returns, win_length = NULL, m = NULL, n = NULL, n
compRet[j] = compRet[j] - 1
}

cop = copula(r1 = compRet, sigma = E, m = m, n = n)
cop = copula(r1 = compRet, sigma = E, m = m, n = n, seed = seed)
blue_mass = 0
red_mass = 0

Expand Down
4 changes: 2 additions & 2 deletions R-proj/R/round_polytope.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#' Z = gen_rand_zonotope(2,6)
#' ListZono = round_polytope(Z)
#' @export
round_polytope <- function(P){
round_polytope <- function(P, seed = NULL){

ret_list = rounding(P)
ret_list = rounding(P, seed)

#get the matrix that describes the polytope
Mat = ret_list$Mat
Expand Down
4 changes: 3 additions & 1 deletion R-proj/man/compute_indicators.Rd

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

5 changes: 4 additions & 1 deletion R-proj/man/copula.Rd

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

4 changes: 3 additions & 1 deletion R-proj/man/direct_sampling.Rd

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

4 changes: 3 additions & 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.

4 changes: 3 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.

4 changes: 3 additions & 1 deletion R-proj/man/sample_points.Rd

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

4 changes: 3 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: 3 additions & 1 deletion R-proj/man/zono_approx.Rd

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

19 changes: 5 additions & 14 deletions R-proj/man/zonotope_approximation.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/src/Makevars
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PKG_CPPFLAGS=-I../../external/boost -I../../external/LPsolve_src/run_headers -I../../external/minimum_ellipsoid -I../../include -I../../include/volume -I../../include/generators -I../../include/samplers -I../../include/annealing -I../../include/convex_bodies -I../../include/lp_oracles -I../../include/misc
PKG_CPPFLAGS=-I../../external/boost -I../../external/LPsolve_src/run_headers -I../../external/minimum_ellipsoid -I../../include
PKG_CXXFLAGS= -lm -ldl -Wno-ignored-attributes -DBOOST_NO_AUTO_PTR
CXX_STD = CXX11

Expand Down
2 changes: 1 addition & 1 deletion R-proj/src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PKG_CPPFLAGS=-I../../external/boost -I../../external/LPsolve_src/run_headers -I../../external/minimum_ellipsoid -I../../include -I../../include/volume -I../../include/generators -I../../include/samplers -I../../include/annealing -I../../include/convex_bodies -I../../include/lp_oracles -I../../include/misc
PKG_CPPFLAGS=-I../../external/boost -I../../external/LPsolve_src/run_headers -I../../external/minimum_ellipsoid -I../../include
PKG_CXXFLAGS= -lm -ldl -Wno-ignored-attributes -DBOOST_NO_AUTO_PTR
CXX_STD = CXX11

Expand Down
12 changes: 8 additions & 4 deletions R-proj/src/copula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <Rcpp.h>
#include <RcppEigen.h>
#include <chrono>
#include "ellipsoids.h"
#include "convex_bodies/ellipsoids.h"
#include "cartesian_geom/cartesian_kernel.h"
#include <boost/random.hpp>
#include <boost/random/uniform_int.hpp>
Expand All @@ -26,6 +26,7 @@
//' @param sigma Optional. The \eqn{d\times d} symmetric positive semidefine matrix that describes the family of concentric ellipsoids centered at the origin.
//' @param m The number of the slices for the copula. The default value is 100.
//' @param n The number of points to sample. The default value is \eqn{5\cdot 10^5}.
//' @param seed Optional. A fixed seed for the number generator.
//'
//' @references \cite{L. Cales, A. Chalkis, I.Z. Emiris, V. Fisikopoulos,
//' \dQuote{Practical volume computation of structured convex bodies, and an application to modeling portfolio dependencies and financial crises,} \emph{Proc. of Symposium on Computational Geometry, Budapest, Hungary,} 2018.}
Expand All @@ -52,7 +53,8 @@ Rcpp::NumericMatrix copula (Rcpp::Nullable<Rcpp::NumericVector> r1 = R_NilValue,
Rcpp::Nullable<Rcpp::NumericVector> r2 = R_NilValue,
Rcpp::Nullable<Rcpp::NumericMatrix> sigma = R_NilValue,
Rcpp::Nullable<unsigned int> m = R_NilValue,
Rcpp::Nullable<unsigned int> n = R_NilValue){
Rcpp::Nullable<unsigned int> n = R_NilValue,
Rcpp::Nullable<double> seed = R_NilValue){

typedef double NT;
typedef Cartesian<NT> Kernel;
Expand All @@ -71,6 +73,8 @@ Rcpp::NumericMatrix copula (Rcpp::Nullable<Rcpp::NumericVector> r1 = R_NilValue,
numpoints = Rcpp::as<unsigned int>(n);
}

double seed3 = (!seed.isNotNull()) ? std::numeric_limits<double>::signaling_NaN() : Rcpp::as<double>(seed);

Rcpp::NumericMatrix copula(num_slices, num_slices);
std::vector<std::vector<NT> > StdCopula;
unsigned int dim = Rcpp::as<std::vector<NT> >(r1).size(), i, j;
Expand All @@ -85,7 +89,7 @@ Rcpp::NumericMatrix copula (Rcpp::Nullable<Rcpp::NumericVector> r1 = R_NilValue,
if (r2.isNotNull()) {

std::vector <NT> hyp2 = Rcpp::as < std::vector < NT > > (r2);
StdCopula = twoParHypFam<Point, RNGType>(dim, numpoints, num_slices, hyp1, hyp2);
StdCopula = twoParHypFam<Point, RNGType>(dim, numpoints, num_slices, hyp1, hyp2, seed3);

} else if (sigma.isNotNull()) {

Expand All @@ -97,7 +101,7 @@ Rcpp::NumericMatrix copula (Rcpp::Nullable<Rcpp::NumericVector> r1 = R_NilValue,
}
}
CopEll Ell(Gin);
StdCopula = hypfam_ellfam<Point, RNGType >(dim, numpoints, num_slices, hyp1, Ell);
StdCopula = hypfam_ellfam<Point, RNGType >(dim, numpoints, num_slices, hyp1, Ell, seed3);
} else {

throw Rcpp::exception("Wrong inputs");
Expand Down
1 change: 0 additions & 1 deletion R-proj/src/direct_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ Rcpp::NumericMatrix direct_sampling(Rcpp::Nullable<Rcpp::List> body = R_NilValue

if (seed.isNotNull()) {
unsigned seed2 = std::chrono::system_clock::now().time_since_epoch().count();
std::cout<<"seed = "<<seed2<<std::endl;
rng.set_seed(seed2);
}
double seed3 = (!seed.isNotNull()) ? std::numeric_limits<double>::signaling_NaN() : Rcpp::as<double>(seed);
Expand Down
18 changes: 6 additions & 12 deletions R-proj/src/rounding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,27 @@ Rcpp::List rounding (Rcpp::Reference P, Rcpp::Nullable<double> seed = R_NilValue
switch (type) {
case 1: {
if (cdhr) {
round_res = round_polytope<CDHRWalk, MT, VT>(HP, InnerBall, walkL,
rng);
round_res = round_polytope<CDHRWalk, MT, VT>(HP, InnerBall, walkL, rng);
} else {
round_res = round_polytope<BilliardWalk, MT, VT>(HP, InnerBall, walkL,
rng);
round_res = round_polytope<BilliardWalk, MT, VT>(HP, InnerBall, walkL, rng);
}
Mat = extractMatPoly(HP);
break;
}
case 2: {
if (cdhr) {
round_res = round_polytope<CDHRWalk, MT, VT>(VP, InnerBall, walkL,
rng);
round_res = round_polytope<CDHRWalk, MT, VT>(VP, InnerBall, walkL, rng);
} else {
round_res = round_polytope<BilliardWalk, MT, VT>(VP, InnerBall, walkL,
rng);
round_res = round_polytope<BilliardWalk, MT, VT>(VP, InnerBall, walkL, rng);
}
Mat = extractMatPoly(VP);
break;
}
case 3: {
if (cdhr) {
round_res = round_polytope<CDHRWalk, MT, VT>(ZP, InnerBall, walkL,
rng);
round_res = round_polytope<CDHRWalk, MT, VT>(ZP, InnerBall, walkL, rng);
} else {
round_res = round_polytope<BilliardWalk, MT, VT>(ZP, InnerBall, walkL,
rng);
round_res = round_polytope<BilliardWalk, MT, VT>(ZP, InnerBall, walkL, rng);
}
Mat = extractMatPoly(ZP);
break;
Expand Down
10 changes: 5 additions & 5 deletions R-proj/src/volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include <boost/random/normal_distribution.hpp>
#include <boost/random/uniform_real_distribution.hpp>
#include "random_walks/random_walks.hpp"
#include "volume_cooling_gaussians.hpp"
#include "volume_sequence_of_balls.hpp"
#include "volume_cooling_gaussians.hpp"
#include "volume_cooling_balls.hpp"
#include "volume_cooling_hpoly.hpp"
#include "volume/volume_cooling_gaussians.hpp"
#include "volume/volume_sequence_of_balls.hpp"
#include "volume/volume_cooling_gaussians.hpp"
#include "volume/volume_cooling_balls.hpp"
#include "volume/volume_cooling_hpoly.hpp"


template <typename Polytope, typename RNGType, typename NT>
Expand Down
Loading