From 0637215b85a16ef431f7d90ad11ace0c5150b702 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Mon, 9 Feb 2015 00:19:42 +0100 Subject: [PATCH] Skip computing viterbi if viterbi of previous state is lower than lower bound This causes a speedup of 300%. --- routing_algorithms/map_matching.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/routing_algorithms/map_matching.hpp b/routing_algorithms/map_matching.hpp index e52fd225a..a512e307a 100644 --- a/routing_algorithms/map_matching.hpp +++ b/routing_algorithms/map_matching.hpp @@ -377,9 +377,15 @@ template class MapMatching final for (auto s_prime = 0u; s_prime < current_viterbi.size(); ++s_prime) { + double new_value = prev_viterbi[s]; + if (current_viterbi[s_prime] > new_value) + continue; // how likely is candidate s_prime at time t to be emitted? const double emission_pr = log_emission_probability(timestamp_list[t][s_prime].second); + new_value += emission_pr; + if (current_viterbi[s_prime] > new_value) + continue; // get distance diff between loc1/2 and locs/s_prime const auto d_t = get_distance_difference(prev_coordinate, @@ -387,9 +393,8 @@ template class MapMatching final prev_unbroken_timestamps_list[s].first, current_timestamps_list[s_prime].first); - // plug probabilities together const double transition_pr = log_transition_probability(d_t, beta); - const double new_value = prev_viterbi[s] + emission_pr + transition_pr; + new_value += transition_pr; JSON::Array _debug_element = makeJSONArray( makeJSONSafe(prev_viterbi[s]),