@@ -53,6 +53,7 @@ struct Walk
53
53
typedef typename Polytope::PointType Point ;
54
54
typedef typename Point ::FT NT;
55
55
typedef typename Polytope::VT VT;
56
+ typedef typename Polytope::MT MT;
56
57
57
58
template <typename GenericPolytope>
58
59
Walk (GenericPolytope &P, Point const & p, NT const & a_i, RandomNumberGenerator &rng)
@@ -80,7 +81,7 @@ struct Walk
80
81
<
81
82
typename GenericPolytope
82
83
>
83
- inline void apply (GenericPolytope& P,
84
+ inline void apply (GenericPolytope const & P,
84
85
Point & p,
85
86
NT const & a_i,
86
87
unsigned int const & walk_length,
@@ -89,6 +90,9 @@ struct Walk
89
90
unsigned int n = P.dimension ();
90
91
NT T;
91
92
93
+ GenericPolytope P_normalized = P;
94
+ P_normalized.normalize ();
95
+
92
96
for (auto j=0u ; j<walk_length; ++j)
93
97
{
94
98
T = rng.sample_urdist () * _Len;
@@ -105,6 +109,7 @@ struct Walk
105
109
_lambda_prev = pbpair.first ;
106
110
T -= _lambda_prev;
107
111
update_position (_p, _v, _lambda_prev, _omega);
112
+ nudge_in (P_normalized, _p);
108
113
P.compute_reflection (_v, _p, pbpair.second );
109
114
it++;
110
115
}
@@ -120,7 +125,7 @@ struct Walk
120
125
<
121
126
typename GenericPolytope
122
127
>
123
- inline void get_starting_point (GenericPolytope& P,
128
+ inline void get_starting_point (GenericPolytope const & P,
124
129
Point const & center,
125
130
Point &q,
126
131
unsigned int const & walk_length,
@@ -141,7 +146,7 @@ struct Walk
141
146
<
142
147
typename GenericPolytope
143
148
>
144
- inline void parameters_burnin (GenericPolytope& P,
149
+ inline void parameters_burnin (GenericPolytope const & P,
145
150
Point const & center,
146
151
unsigned int const & num_points,
147
152
unsigned int const & walk_length,
@@ -191,7 +196,7 @@ private :
191
196
<
192
197
typename GenericPolytope
193
198
>
194
- inline void initialize (GenericPolytope& P,
199
+ inline void initialize (GenericPolytope const & P,
195
200
Point const & p,
196
201
NT const & a_i,
197
202
RandomNumberGenerator &rng)
@@ -204,6 +209,9 @@ private :
204
209
NT T = rng.sample_urdist () * _Len;
205
210
int it = 0 ;
206
211
212
+ GenericPolytope P_normalized = P;
213
+ P_normalized.normalize ();
214
+
207
215
while (it <= _rho)
208
216
{
209
217
auto pbpair
@@ -218,12 +226,50 @@ private :
218
226
}
219
227
_lambda_prev = pbpair.first ;
220
228
update_position (_p, _v, _lambda_prev, _omega);
229
+ nudge_in (P_normalized, _p);
221
230
T -= _lambda_prev;
222
231
P.compute_reflection (_v, _p, pbpair.second );
223
232
it++;
224
233
}
225
234
}
226
235
236
+ template
237
+ <
238
+ typename GenericPolytope
239
+ >
240
+ inline void nudge_in (GenericPolytope& P, Point & p, NT tol=NT(0 ))
241
+ {
242
+ MT A = P.get_mat ();
243
+ VT b = P.get_vec ();
244
+ int m = A.rows ();
245
+
246
+ VT b_Ax = b - A * p.getCoefficients ();
247
+ const NT* b_Ax_data = b_Ax.data ();
248
+
249
+ NT dist;
250
+
251
+ for (int i = 0 ; i < m; i++) {
252
+
253
+ dist = *b_Ax_data;
254
+
255
+ if (dist < NT (-tol)){
256
+ // Nudging correction
257
+ NT eps = -1e-7 ;
258
+
259
+ NT eps_1 = -dist;
260
+ // A.row is already normalized, no need to do it again
261
+ VT A_i = A.row (i);
262
+ NT eps_2 = eps_1 + eps;
263
+
264
+ // Nudge the point inside with respect to the normal its vector
265
+ Point shift (A_i);
266
+ shift.operator *=(eps_2);
267
+ p.operator +=(shift);
268
+ }
269
+ b_Ax_data++;
270
+ }
271
+ }
272
+
227
273
inline void update_position (Point &p, Point &v, NT const & T, NT const & omega)
228
274
{
229
275
NT next_p, next_v;
@@ -274,4 +320,3 @@ private :
274
320
275
321
276
322
#endif // RANDOM_WALKS_GAUSSIAN_HMC_WALK_HPP
277
-
0 commit comments