2016-02-20 22:27:26 -05:00
|
|
|
#ifndef ENGINE_MAP_MATCHING_CONFIDENCE_HPP
|
|
|
|
#define ENGINE_MAP_MATCHING_CONFIDENCE_HPP
|
|
|
|
|
|
|
|
#include "engine/map_matching/bayes_classifier.hpp"
|
2024-05-30 13:40:56 -04:00
|
|
|
#include <boost/assert.hpp>
|
2016-02-20 22:27:26 -05:00
|
|
|
#include <cmath>
|
|
|
|
|
2022-12-11 04:10:26 -05:00
|
|
|
namespace osrm::engine::map_matching
|
2016-02-20 22:27:26 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
struct MatchingConfidence
|
|
|
|
{
|
2016-03-03 08:26:13 -05:00
|
|
|
private:
|
2016-02-20 22:27:26 -05:00
|
|
|
using ClassifierT = BayesClassifier<LaplaceDistribution, LaplaceDistribution, double>;
|
|
|
|
using TraceClassification = ClassifierT::ClassificationT;
|
|
|
|
|
2016-03-03 08:26:13 -05:00
|
|
|
public:
|
2016-02-20 22:27:26 -05:00
|
|
|
MatchingConfidence()
|
|
|
|
: // the values were derived from fitting a laplace distribution
|
|
|
|
// to the values of manually classified traces
|
|
|
|
classifier(map_matching::LaplaceDistribution(0.005986, 0.016646),
|
|
|
|
map_matching::LaplaceDistribution(0.054385, 0.458432),
|
|
|
|
0.696774) // valid apriori probability
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
double operator()(const float trace_length, const float matched_length) const
|
|
|
|
{
|
|
|
|
const double distance_feature = -std::log(trace_length) + std::log(matched_length);
|
|
|
|
|
|
|
|
// matched to the same point
|
|
|
|
if (!std::isfinite(distance_feature))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto label_with_confidence = classifier.classify(distance_feature);
|
|
|
|
if (label_with_confidence.first == ClassifierT::ClassLabel::POSITIVE)
|
|
|
|
{
|
|
|
|
return label_with_confidence.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_ASSERT(label_with_confidence.first == ClassifierT::ClassLabel::NEGATIVE);
|
|
|
|
return 1 - label_with_confidence.second;
|
|
|
|
}
|
|
|
|
|
2016-03-03 08:26:13 -05:00
|
|
|
private:
|
2016-02-20 22:27:26 -05:00
|
|
|
ClassifierT classifier;
|
|
|
|
};
|
2022-12-20 12:00:11 -05:00
|
|
|
} // namespace osrm::engine::map_matching
|
2016-02-20 22:27:26 -05:00
|
|
|
|
|
|
|
#endif
|