@@ -580,17 +580,23 @@ class HPolytope {
580580 NT inner_prev = params.inner_vi_ak ;
581581 NT* Av_data = Av.data ();
582582
583+ // Updating Av due to the change in direction caused by the previous reflection
583584 // Av += (-2.0 * inner_prev) * AA.col(params.facet_prev)
584585
585586 for (Eigen::SparseMatrix<double >::InnerIterator it (AA, params.facet_prev ); it; ++it) {
586587
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
587590
591+ // Before updating Av(row)
588592 // val(row) = (b(row) - Ar(row)) / Av(row) + params.moved_dist
589593 // (val(row) - params.moved_dist) = (b(row) - Ar(row)) / Av(row)
590594 // (val(row) - params.moved_dist) * Av(row) = b(row) - Ar(row)
595+ // b(row) - Ar(row) = (val(row) - params.moved_dist) * Av(row)
591596
592597 *(Av_data + it.row ()) += (-2.0 * inner_prev) * it.value ();
593598
599+ // After updating Av(row)
594600 // b(row) - Ar(row) = (old_val(row) - params.moved_dist) * old_Av(row)
595601 // new_val(row) = (b(row) - Ar(row) ) / new_Av(row) + params.moved_dist
596602 // new_val(row) = ((old_val(row) - params.moved_dist) * old_Av(row)) / new_Av(row) + params.moved_dist
@@ -608,8 +614,12 @@ class HPolytope {
608614 distances_set.change_val (it.row (), val, params.moved_dist );
609615 }
610616
617+ // Finding the distance to the closest facet and its row
611618 std::pair<NT, int > ans = distances_set.get_min ();
619+
620+ // Subtract params.moved_dist to obtain the actual distance to the facet
612621 ans.first -= params.moved_dist ;
622+
613623 params.inner_vi_ak = *(Av_data + ans.second );
614624 params.facet_prev = ans.second ;
615625
@@ -1002,24 +1012,24 @@ class HPolytope {
10021012 return total;
10031013 }
10041014
1015+ // Updates the velocity vector v and the position vector p after a reflection
10051016 template <typename update_parameters>
10061017 void compute_reflection (Point &v, Point const &, update_parameters const & params) const {
10071018 Point a ((-2.0 * params.inner_vi_ak ) * A.row (params.facet_prev ));
10081019 v += a;
10091020 }
10101021
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
10141024 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+ }
10231033 }
10241034
10251035 // function to compute reflection for GaBW random walk
0 commit comments