diff --git a/generator/feature_segments_checker/feature_segments_checker.cpp b/generator/feature_segments_checker/feature_segments_checker.cpp index 80a2e8541d..2eeb709b40 100644 --- a/generator/feature_segments_checker/feature_segments_checker.cpp +++ b/generator/feature_segments_checker/feature_segments_checker.cpp @@ -16,8 +16,9 @@ #include "base/logging.hpp" -#include "std/iostream.hpp" +#include "std/cmath.hpp" #include "std/fstream.hpp" +#include "std/iostream.hpp" #include "std/map.hpp" #include "std/set.hpp" #include "std/string.hpp" @@ -227,6 +228,24 @@ public: } } }; + +double CalculateEntropy(map const & diffFromLinear) +{ + uint32_t innerPointCount = 0; + for (auto const & f : diffFromLinear) + innerPointCount += f.second; + + if (innerPointCount == 0) + return 0.0; + + double entropy = 0; + for (auto const & f : diffFromLinear) + { + double const p = static_cast(f.second) / innerPointCount; + entropy += -p * log2(p); + } + return entropy; +} } // namespace int main(int argc, char ** argv) @@ -243,12 +262,6 @@ int main(int argc, char ** argv) Processor processor(manager); feature::ForEachFromDat(FLAGS_mwm_file_path, processor); - cout << endl << "Road feature count = " << processor.m_roadCount << endl; - cout << "Empty road feature count = " << processor.m_emptyRoadCount << endl; - cout << "Unique road points count = " << processor.m_uniqueRoadPoints.size() << endl; - cout << "All road point count = " << processor.m_roadPointCount << endl; - cout << "Not road feature count = " << processor.m_notRoadCount << endl; - PrintCont(processor.m_altitudeDiffs, "Altitude difference between start and end of features.", " feature(s) with altitude difference ", " meter(s)"); WriteCSV(processor.m_altitudeDiffs, "altitude_difference.csv"); @@ -270,5 +283,13 @@ int main(int argc, char ** argv) PrintCont(processor.m_diffFromLinear, "Altitude deviation of internal feature points from linear model.", " internal feature point(s) deviate from linear model with ", " meter(s)"); + + cout << endl << "Road feature count = " << processor.m_roadCount << endl; + cout << "Empty road feature count = " << processor.m_emptyRoadCount << endl; + cout << "Unique road points count = " << processor.m_uniqueRoadPoints.size() << endl; + cout << "All road point count = " << processor.m_roadPointCount << endl; + cout << "Not road feature count = " << processor.m_notRoadCount << endl; + cout << "Binary entropy for altitude deviation of internal feature points from linear model = " + << CalculateEntropy(processor.m_diffFromLinear) << endl; return 0; }