Skip to content

Commit c623e6f

Browse files
committed
Position Nudging after Position Update
1 parent 9114f37 commit c623e6f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/convex_bodies/hpolytope.h

+27
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,33 @@ class HPolytope {
290290
return -1;
291291
}
292292

293+
//Nudge the Point p inside the Polytope
294+
void nudge_in(Point& p, NT tol=NT(0)) const
295+
{
296+
int m = A.rows();
297+
const NT* b_data = b.data();
298+
299+
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+
303+
//Nudging correction
304+
NT eps = -1e-7;
305+
306+
NT eps_1 = -(*b_data - A.row(i) * p.getCoefficients());
307+
MT A_nor = A;
308+
A_nor.normalize();
309+
NT eps_2 = eps_1 + eps;
310+
311+
//Nudge the point inside with respect to the normal its vector
312+
Point shift(A_nor.row(i));
313+
shift.operator*=(eps_2);
314+
p.operator+=(shift);
315+
}
316+
b_data++;
317+
}
318+
}
319+
293320
// compute intersection point of ray starting from r and pointing to v
294321
// with polytope discribed by A and b
295322
std::pair<NT,NT> line_intersect(Point const& r, Point const& v) const

include/random_walks/gaussian_hamiltonian_monte_carlo_exact_walk.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ struct Walk
105105
_lambda_prev = pbpair.first;
106106
T -= _lambda_prev;
107107
update_position(_p, _v, _lambda_prev, _omega);
108+
if(P.is_in(_p) != -1)
109+
P.nudge_in(_p);
108110
P.compute_reflection(_v, _p, pbpair.second);
109111
it++;
110112
}

0 commit comments

Comments
 (0)