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

Eigen implementation #29

Merged
merged 26 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7e26754
Changed class point to store coefficients to Eigen vector instead of …
panagiotisrep May 24, 2019
d945a40
fixed bug
panagiotisrep May 25, 2019
d0f2484
fix for quicker access to data
panagiotisrep Aug 7, 2019
7a7efdb
Eigen
panagiotisrep Feb 13, 2020
823b99b
Merge branch 'develop' into Eigen-Implementation
panagiotisrep Feb 14, 2020
04fecb8
Optimizations
panagiotisrep Feb 14, 2020
5a3a9d6
Optimizations
panagiotisrep Feb 14, 2020
09d33f3
Major
panagiotisrep Feb 15, 2020
43bc15a
Bug
panagiotisrep Feb 15, 2020
d589a1e
bug
panagiotisrep Feb 15, 2020
7559240
use cooling balls in test
panagiotisrep Feb 15, 2020
2c94313
edit initialization
panagiotisrep Feb 15, 2020
9ee96fc
merge changes from develop
panagiotisrep Feb 16, 2020
ef2627f
edit /test/CMakeLists.txt
panagiotisrep Feb 18, 2020
8cb4c30
Optimizations
panagiotisrep Feb 21, 2020
8f26bb3
merge
panagiotisrep Mar 13, 2020
b1b79db
leftovers from merge
panagiotisrep Mar 13, 2020
a4e44a2
cleanup - requested changes
panagiotisrep Mar 16, 2020
623521e
update copyrights
panagiotisrep Mar 16, 2020
f3fbec0
bug
panagiotisrep Mar 16, 2020
6edb93c
Merge branch 'develop' of https://github.com/GeomScale/volume_approxi…
panagiotisrep Mar 16, 2020
7b2794a
bug
panagiotisrep Mar 16, 2020
fc21da5
requested changes
panagiotisrep Mar 21, 2020
89655c3
use += *= operators with points
panagiotisrep Mar 23, 2020
09b8249
use += *= operators with points
panagiotisrep Mar 23, 2020
e2ab1c1
Merge branch 'develop' of https://github.com/GeomScale/volume_approxi…
panagiotisrep Mar 23, 2020
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
2 changes: 1 addition & 1 deletion R-proj/src/direct_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Rcpp::NumericMatrix direct_sampling(Rcpp::Nullable<Rcpp::List> body = R_NilValue
unsigned int jj = 0;

for (typename std::list<Point>::iterator rpit = randPoints.begin(); rpit!=randPoints.end(); rpit++, jj++) {
RetMat.col(jj) = Eigen::Map<VT>(&(*rpit).get_coeffs()[0], (*rpit).dimension());
RetMat.col(jj) = rpit->getCoefficients();
}
return Rcpp::wrap(RetMat);
}
19 changes: 12 additions & 7 deletions R-proj/src/sample_points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Rcpp::NumericMatrix sample_points(Rcpp::Nullable<Rcpp::Reference> P = R_NilValue
}
}


if (Rcpp::as<Rcpp::List>(random_walk).containsElementNamed("nburns")) {
nburns = Rcpp::as<int>(Rcpp::as<Rcpp::List>(random_walk)["nburns"]);
if (nburns < 0) {
Expand Down Expand Up @@ -233,7 +234,8 @@ Rcpp::NumericMatrix sample_points(Rcpp::Nullable<Rcpp::Reference> P = R_NilValue
HP.normalize();
if (gaussian) {
StartingPoint = StartingPoint - mode;
HP.shift(Eigen::Map<VT>(&mode.get_coeffs()[0], mode.dimension()));
HP.shift(mode.getCoefficients());

}
break;
}
Expand All @@ -252,7 +254,7 @@ Rcpp::NumericMatrix sample_points(Rcpp::Nullable<Rcpp::Reference> P = R_NilValue
if (billiard && diam < 0.0) VP.comp_diam(diam);
if (gaussian) {
StartingPoint = StartingPoint - mode;
VP.shift(Eigen::Map<VT>(&mode.get_coeffs()[0], mode.dimension()));
VP.shift(mode.getCoefficients());
}
break;
}
Expand All @@ -271,7 +273,7 @@ Rcpp::NumericMatrix sample_points(Rcpp::Nullable<Rcpp::Reference> P = R_NilValue
if (billiard && diam < 0.0) ZP.comp_diam(diam);
if (gaussian) {
StartingPoint = StartingPoint - mode;
ZP.shift(Eigen::Map<VT>(&mode.get_coeffs()[0], mode.dimension()));
ZP.shift(mode.getCoefficients());
}
break;
}
Expand All @@ -296,7 +298,7 @@ Rcpp::NumericMatrix sample_points(Rcpp::Nullable<Rcpp::Reference> P = R_NilValue
}
if (gaussian) {
StartingPoint = StartingPoint - mode;
VPcVP.shift(Eigen::Map<VT>(&mode.get_coeffs()[0], mode.dimension()));
VPcVP.shift(mode.getCoefficients());
}
break;
}
Expand Down Expand Up @@ -342,14 +344,17 @@ Rcpp::NumericMatrix sample_points(Rcpp::Nullable<Rcpp::Reference> P = R_NilValue
MT RetMat(dim, numpoints);
unsigned int jj = 0;


for (typename std::list<Point>::iterator rpit = randPoints.begin(); rpit!=randPoints.end(); rpit++, jj++) {
if (gaussian) {
RetMat.col(jj) = Eigen::Map<VT>(&(*rpit).get_coeffs()[0], (*rpit).dimension()) +
Eigen::Map<VT>(&mode.get_coeffs()[0], mode.dimension());

RetMat.col(jj) = rpit->getCoefficients() + mode.getCoefficients();

} else {
RetMat.col(jj) = Eigen::Map<VT>(&(*rpit).get_coeffs()[0], (*rpit).dimension());
RetMat.col(jj) = (*rpit).getCoefficients();
}
}

return Rcpp::wrap(RetMat);

}
7 changes: 5 additions & 2 deletions include/annealing/gaussian_annealing.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ void get_annealing_schedule(Polytope &P, const NT &radius, const NT &ratio, cons

Point p_prev=p;

std::vector<NT> lamdas(P.num_of_hyperplanes(), NT(0));
typedef Eigen::Matrix<NT,Eigen::Dynamic,1> VT;
VT lamdas;
lamdas.setZero(P.num_of_hyperplanes());

while (true) {

if (var.ball_walk) {
Expand All @@ -206,7 +209,7 @@ void get_annealing_schedule(Polytope &P, const NT &radius, const NT &ratio, cons

curr_fn = 0;
curr_its = 0;
std::fill(lamdas.begin(), lamdas.end(), NT(0));
lamdas.setConstant(NT(0));
steps = totalSteps;

if (var.cdhr_walk){
Expand Down
2 changes: 1 addition & 1 deletion include/annealing/hpoly_annealing.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void comp_diam_hpoly_zono_inter(ZonoHP &ZHP, const MT &G, const MT &AG, const VT
typename std::list<Point>::iterator rpit=randPoints.begin();
NT max_norm = 0.0, iter_norm;
for ( ; rpit!=randPoints.end(); rpit++) {
iter_norm = (G*Eigen::Map<VT>(&(*rpit).get_coeffs()[0], (*rpit).dimension())).norm();
iter_norm = (G*rpit->getCoefficients()).norm();
if (iter_norm > max_norm) max_norm = iter_norm;
}
diams_inter.push_back(2.0 * max_norm);
Expand Down
13 changes: 11 additions & 2 deletions include/annealing/ratio_estimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ NT esti_ratio(PolyBall1 &Pb1, PolyBall2 &Pb2, const NT &ratio, const NT &error,
bool print = var.verbose;
NT min_val = std::numeric_limits<NT>::lowest(), max_val = std::numeric_limits<NT>::max(), val, lambda;
size_t totCount = Ntot, countIn = Ntot * ratio;
std::vector<NT> last_W(W), lamdas(Pb1.num_of_hyperplanes()), Av(Pb1.num_of_hyperplanes());
std::vector<NT> last_W(W);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since last_W size does not change why not using std::array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think std::array is a fixed size array and cannot allocate memory dynamically; we don't know W, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks

typedef Eigen::Matrix<NT,Eigen::Dynamic,1> VT;
VT lamdas, Av;
lamdas.setZero(Pb1.num_of_hyperplanes());
Av.setZero(Pb1.num_of_hyperplanes());

std::list<Point> randPoints;
typename std::vector<NT>::iterator minmaxIt;
typename std::list<Point>::iterator rpit;
Expand Down Expand Up @@ -90,7 +95,11 @@ NT esti_ratio_interval(PolyBall1 &Pb1, PolyBall2 &Pb2, const NT &ratio, const NT

int n = var.n, index = 0, iter = 1;
bool print = var.verbose;
std::vector<NT> last_W(W), lamdas(Pb1.num_of_hyperplanes()), Av(Pb1.num_of_hyperplanes());
std::vector<NT> last_W(W);
typedef Eigen::Matrix<NT,Eigen::Dynamic,1> VT;
VT lamdas, Av;
Av.setZero(Pb1.num_of_hyperplanes());
lamdas.setZero(Pb1.num_of_hyperplanes());
NT val, sum_sq=0.0, sum=0.0, lambda;
size_t totCount = Ntot, countIn = Ntot * ratio;
//std::cout<<"countIn = "<<countIn<<", totCount = "<<totCount<<std::endl;
Expand Down
Loading