Skip to content

Commit 6dc3108

Browse files
committed
Complexity improvements and Polytope Normalization
1 parent c623e6f commit 6dc3108

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

include/convex_bodies/hpolytope.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,26 @@ class HPolytope {
290290
return -1;
291291
}
292292

293-
//Nudge the Point p inside the Polytope
294293
void nudge_in(Point& p, NT tol=NT(0)) const
295294
{
296295
int m = A.rows();
297296
const NT* b_data = b.data();
298297

299298
for (int i = 0; i < m; i++) {
300-
//Check if corresponding hyperplane is violated
301-
if (*b_data - A.row(i) * p.getCoefficients() < NT(-tol)){
302-
299+
300+
NT dist = *b_data - A.row(i) * p.getCoefficients();
301+
302+
if (dist < NT(-tol)){
303303
//Nudging correction
304304
NT eps = -1e-7;
305305

306-
NT eps_1 = -(*b_data - A.row(i) * p.getCoefficients());
307-
MT A_nor = A;
308-
A_nor.normalize();
306+
NT eps_1 = -dist;
307+
//A.row is already normalized, no need to do it again
308+
VT A_i = A.row(i);
309309
NT eps_2 = eps_1 + eps;
310310

311311
//Nudge the point inside with respect to the normal its vector
312-
Point shift(A_nor.row(i));
312+
Point shift(A_i);
313313
shift.operator*=(eps_2);
314314
p.operator+=(shift);
315315
}

include/random_walks/gaussian_hamiltonian_monte_carlo_exact_walk.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ struct Walk
8989
unsigned int n = P.dimension();
9090
NT T;
9191

92+
//normalize the Polyope
93+
P.normalize();
94+
9295
for (auto j=0u; j<walk_length; ++j)
9396
{
9497
T = rng.sample_urdist() * _Len;
@@ -105,8 +108,7 @@ struct Walk
105108
_lambda_prev = pbpair.first;
106109
T -= _lambda_prev;
107110
update_position(_p, _v, _lambda_prev, _omega);
108-
if(P.is_in(_p) != -1)
109-
P.nudge_in(_p);
111+
P.nudge_in(_p);
110112
P.compute_reflection(_v, _p, pbpair.second);
111113
it++;
112114
}
@@ -203,6 +205,9 @@ private :
203205
_p = p;
204206
_v = GetDirection<Point>::apply(n, rng, false);
205207

208+
//normalize the Polyope
209+
P.normalize();
210+
206211
NT T = rng.sample_urdist() * _Len;
207212
int it = 0;
208213

@@ -220,6 +225,7 @@ private :
220225
}
221226
_lambda_prev = pbpair.first;
222227
update_position(_p, _v, _lambda_prev, _omega);
228+
P.nudge_in(_p);
223229
T -= _lambda_prev;
224230
P.compute_reflection(_v, _p, pbpair.second);
225231
it++;

0 commit comments

Comments
 (0)