Mark suspicious transitions

This commit is contained in:
Patrick Niklaus 2015-03-17 01:00:04 +01:00
parent 61dca4a35e
commit a372ade7ce
3 changed files with 15 additions and 3 deletions

View File

@ -80,6 +80,7 @@ template <class CandidateLists> struct HiddenMarkovModel
std::vector<std::vector<std::pair<unsigned, unsigned>>> parents;
std::vector<std::vector<float>> path_lengths;
std::vector<std::vector<bool>> pruned;
std::vector<std::vector<bool>> suspicious;
std::vector<bool> breakage;
const CandidateLists &candidates_list;
@ -95,6 +96,7 @@ template <class CandidateLists> struct HiddenMarkovModel
viterbi.emplace_back(l.size());
parents.emplace_back(l.size());
path_lengths.emplace_back(l.size());
suspicious.emplace_back(l.size());
pruned.emplace_back(l.size());
}
@ -111,6 +113,7 @@ template <class CandidateLists> struct HiddenMarkovModel
std::fill(viterbi[t].begin(), viterbi[t].end(), osrm::matching::IMPOSSIBLE_LOG_PROB);
std::fill(parents[t].begin(), parents[t].end(), std::make_pair(0u, 0u));
std::fill(path_lengths[t].begin(), path_lengths[t].end(), 0);
std::fill(suspicious[t].begin(), suspicious[t].end(), true);
std::fill(pruned[t].begin(), pruned[t].end(), true);
}
std::fill(breakage.begin() + initial_timestamp, breakage.end(), true);
@ -129,6 +132,7 @@ template <class CandidateLists> struct HiddenMarkovModel
parents[initial_timestamp][s] = std::make_pair(initial_timestamp, s);
pruned[initial_timestamp][s] =
viterbi[initial_timestamp][s] < osrm::matching::MINIMAL_LOG_PROB;
suspicious[initial_timestamp][s] = false;
breakage[initial_timestamp] =
breakage[initial_timestamp] && pruned[initial_timestamp][s];

View File

@ -62,6 +62,9 @@ using SubMatchingList = std::vector<SubMatching>;
constexpr static const unsigned MAX_BROKEN_STATES = 6;
constexpr static const unsigned MAX_BROKEN_TIME = 60;
constexpr static const unsigned MAX_DISTANCE_DELTA = 500;
constexpr static const unsigned SUSPICIOUS_DISTANCE_DELTA = 100;
constexpr static const double default_beta = 10.0;
constexpr static const double default_sigma_z = 4.07;
}
@ -168,6 +171,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
auto &current_viterbi = model.viterbi[t];
auto &current_pruned = model.pruned[t];
auto &current_suspicious = model.suspicious[t];
auto &current_parents = model.parents[t];
auto &current_lengths = model.path_lengths[t];
const auto &current_timestamps_list = candidates_list[t];
@ -214,7 +218,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
const auto d_t = std::abs(network_distance - great_circle_distance);
// very low probability transition -> prune
if (d_t > 500)
if (d_t > osrm::matching::MAX_DISTANCE_DELTA)
{
continue;
}
@ -232,6 +236,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
current_parents[s_prime] = std::make_pair(prev_unbroken_timestamp, s);
current_lengths[s_prime] = network_distance;
current_pruned[s_prime] = false;
current_suspicious[s_prime] = d_t > osrm::matching::SUSPICIOUS_DISTANCE_DELTA;
model.breakage[t] = false;
}
}
@ -255,7 +260,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
}
}
matching_debug.set_viterbi(model.viterbi, model.pruned);
matching_debug.set_viterbi(model.viterbi, model.pruned, model.suspicious);
if (!prev_unbroken_timestamps.empty())
{

View File

@ -103,7 +103,8 @@ struct MatchingDebugInfo
}
void set_viterbi(const std::vector<std::vector<double>> &viterbi,
const std::vector<std::vector<bool>> &pruned)
const std::vector<std::vector<bool>> &pruned,
const std::vector<std::vector<bool>> &suspicious)
{
// json logger not enabled
if (!logger)
@ -119,6 +120,8 @@ struct MatchingDebugInfo
osrm::json::clamp_float(viterbi[t][s_prime]);
osrm::json::get(*object, "states", t, s_prime, "pruned") =
static_cast<unsigned>(pruned[t][s_prime]);
osrm::json::get(*object, "states", t, s_prime, "suspicious") =
static_cast<unsigned>(suspicious[t][s_prime]);
}
}
}