@@ -580,17 +580,23 @@ class HPolytope {
580
580
NT inner_prev = params.inner_vi_ak ;
581
581
NT* Av_data = Av.data ();
582
582
583
+ // Updating Av due to the change in direction caused by the previous reflection
583
584
// Av += (-2.0 * inner_prev) * AA.col(params.facet_prev)
584
585
585
586
for (Eigen::SparseMatrix<double >::InnerIterator it (AA, params.facet_prev ); it; ++it) {
586
587
588
+ // val(row) - params.moved_dist = The distance until we would hit the facet given by row
589
+ // all those values are stored inside distances_set for quick retrieval of the minimum
587
590
591
+ // Before updating Av(row)
588
592
// val(row) = (b(row) - Ar(row)) / Av(row) + params.moved_dist
589
593
// (val(row) - params.moved_dist) = (b(row) - Ar(row)) / Av(row)
590
594
// (val(row) - params.moved_dist) * Av(row) = b(row) - Ar(row)
595
+ // b(row) - Ar(row) = (val(row) - params.moved_dist) * Av(row)
591
596
592
597
*(Av_data + it.row ()) += (-2.0 * inner_prev) * it.value ();
593
598
599
+ // After updating Av(row)
594
600
// b(row) - Ar(row) = (old_val(row) - params.moved_dist) * old_Av(row)
595
601
// new_val(row) = (b(row) - Ar(row) ) / new_Av(row) + params.moved_dist
596
602
// new_val(row) = ((old_val(row) - params.moved_dist) * old_Av(row)) / new_Av(row) + params.moved_dist
@@ -608,8 +614,12 @@ class HPolytope {
608
614
distances_set.change_val (it.row (), val, params.moved_dist );
609
615
}
610
616
617
+ // Finding the distance to the closest facet and its row
611
618
std::pair<NT, int > ans = distances_set.get_min ();
619
+
620
+ // Subtract params.moved_dist to obtain the actual distance to the facet
612
621
ans.first -= params.moved_dist ;
622
+
613
623
params.inner_vi_ak = *(Av_data + ans.second );
614
624
params.facet_prev = ans.second ;
615
625
@@ -1002,24 +1012,24 @@ class HPolytope {
1002
1012
return total;
1003
1013
}
1004
1014
1015
+ // Updates the velocity vector v and the position vector p after a reflection
1005
1016
template <typename update_parameters>
1006
1017
void compute_reflection (Point &v, Point const &, update_parameters const & params) const {
1007
1018
Point a ((-2.0 * params.inner_vi_ak ) * A.row (params.facet_prev ));
1008
1019
v += a;
1009
1020
}
1010
1021
1011
- // updates the velocity vector v and the position vector p after a reflection
1012
- // the real value of p is given by p + moved_dist * v
1013
- // MT must be sparse, in RowMajor format
1022
+ // Only to be called when MT is in RowMajor format
1023
+ // The real value of p is given by p + params.moved_dist * v
1014
1024
template <typename update_parameters>
1015
- auto compute_reflection (Point &v, Point &p, update_parameters const & params) const
1016
- -> std::enable_if_t<std::is_same_v<MT, Eigen::SparseMatrix<NT, Eigen::RowMajor>> && !std::is_same_v<update_parameters, int>, void> {
1017
- NT* v_data = v.pointerToData ();
1018
- NT* p_data = p.pointerToData ();
1019
- for (Eigen::SparseMatrix<double , Eigen::RowMajor>::InnerIterator it (A, params.facet_prev ); it; ++it) {
1020
- *(v_data + it.col ()) += (-2.0 * params.inner_vi_ak ) * it.value ();
1021
- *(p_data + it.col ()) -= (-2.0 * params.inner_vi_ak * params.moved_dist ) * it.value ();
1022
- }
1025
+ auto compute_reflection_abw_sparse (Point &v, Point &p, update_parameters const & params) const
1026
+ {
1027
+ NT* v_data = v.pointerToData ();
1028
+ NT* p_data = p.pointerToData ();
1029
+ for (Eigen::SparseMatrix<double , Eigen::RowMajor>::InnerIterator it (A, params.facet_prev ); it; ++it) {
1030
+ *(v_data + it.col ()) += (-2.0 * params.inner_vi_ak ) * it.value ();
1031
+ *(p_data + it.col ()) -= (-2.0 * params.inner_vi_ak * params.moved_dist ) * it.value ();
1032
+ }
1023
1033
}
1024
1034
1025
1035
// function to compute reflection for GaBW random walk
0 commit comments