-
Notifications
You must be signed in to change notification settings - Fork 123
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
Improvements in rounding and rotating R functions #76
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,13 +27,15 @@ | |
//' | ||
//' @param P A convex polytope (H-, V-polytope or a zonotope). | ||
//' @param T Optional. A rotation matrix. | ||
//' @param seed Optional. A fixed seed for the random linear map generator. | ||
//' | ||
//' @section warning: | ||
//' Do not use this function. | ||
//' | ||
//' @return A matrix that describes the rotated polytope | ||
// [[Rcpp::export]] | ||
Rcpp::NumericMatrix rotating (Rcpp::Reference P, Rcpp::Nullable<Rcpp::NumericMatrix> T = R_NilValue){ | ||
Rcpp::NumericMatrix rotating (Rcpp::Reference P, Rcpp::Nullable<Rcpp::NumericMatrix> T = R_NilValue, | ||
Rcpp::Nullable<double> seed = R_NilValue){ | ||
|
||
typedef double NT; | ||
typedef Cartesian<NT> Kernel; | ||
|
@@ -51,6 +53,8 @@ Rcpp::NumericMatrix rotating (Rcpp::Reference P, Rcpp::Nullable<Rcpp::NumericMat | |
unsigned int n = P.field("dimension"); | ||
int type = P.field("type"); | ||
|
||
double seed2 = (!seed.isNotNull()) ? std::numeric_limits<double>::signaling_NaN() : Rcpp::as<double>(seed); | ||
|
||
switch (type) { | ||
case 1: { | ||
// Hpolytope | ||
|
@@ -60,7 +64,7 @@ Rcpp::NumericMatrix rotating (Rcpp::Reference P, Rcpp::Nullable<Rcpp::NumericMat | |
TransorfMat = Rcpp::as<MT>(T); | ||
HP.linear_transformIt(TransorfMat.inverse()); | ||
} else { | ||
TransorfMat = rotating < MT > (HP); | ||
TransorfMat = rotating < MT > (HP, seed2); | ||
} | ||
Mat = extractMatPoly(HP); | ||
break; | ||
|
@@ -73,7 +77,7 @@ Rcpp::NumericMatrix rotating (Rcpp::Reference P, Rcpp::Nullable<Rcpp::NumericMat | |
TransorfMat = Rcpp::as<MT>(T); | ||
VP.linear_transformIt(TransorfMat.inverse()); | ||
} else { | ||
TransorfMat = rotating < MT > (VP); | ||
TransorfMat = rotating < MT > (VP, seed2); | ||
} | ||
Mat = extractMatPoly(VP); | ||
break; | ||
|
@@ -86,13 +90,14 @@ Rcpp::NumericMatrix rotating (Rcpp::Reference P, Rcpp::Nullable<Rcpp::NumericMat | |
TransorfMat = Rcpp::as<MT>(T); | ||
ZP.linear_transformIt(TransorfMat.inverse()); | ||
} else { | ||
TransorfMat = rotating < MT > (ZP); | ||
TransorfMat = rotating < MT > (ZP, seed2); | ||
} | ||
Mat = extractMatPoly(ZP); | ||
break; | ||
} | ||
case 4: { | ||
Vpolytope VP1; | ||
throw Rcpp::exception("volesti does not support rotation for this representation currently."); | ||
/*Vpolytope VP1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this piece of code going to be used in the future? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this part. |
||
Vpolytope VP2; | ||
InterVP VPcVP; | ||
VP1.init(n, Rcpp::as<MT>(P.field("V1")), VT::Ones(Rcpp::as<MT>(P.field("V1")).rows())); | ||
|
@@ -102,8 +107,8 @@ Rcpp::NumericMatrix rotating (Rcpp::Reference P, Rcpp::Nullable<Rcpp::NumericMat | |
TransorfMat = Rcpp::as<MT>(T); | ||
VPcVP.linear_transformIt(TransorfMat.inverse()); | ||
} else { | ||
TransorfMat = rotating < MT > (VPcVP); | ||
} | ||
TransorfMat = rotating < MT > (VPcVP, seed2); | ||
}*/ | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,19 @@ | |
|
||
|
||
template <typename MT, typename Polytope> | ||
MT rotating(Polytope &P){ | ||
MT rotating(Polytope &P, double seed = std::numeric_limits<double>::signaling_NaN()){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, why not two overloads? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. overloaded |
||
|
||
typedef boost::mt19937 RNGType; | ||
//typedef typename Polytope::MT MT; | ||
|
||
unsigned rng_seed = std::chrono::system_clock::now().time_since_epoch().count(); | ||
RNGType rng(rng_seed); | ||
if (!std::isnan(seed)) { | ||
unsigned rng_seed = seed; | ||
rng.seed(rng_seed); | ||
} | ||
boost::random::uniform_real_distribution<> urdist(-1.0, 1.0); | ||
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); | ||
RNGType rng(seed); | ||
//unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
//RNGType rng(seed); | ||
unsigned int n = P.dimension(); | ||
|
||
// pick a random rotation | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not creating two overloads of
rotating
, one with fixed seed and one without ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the same code structure for polytope generators as well.