[Positioner] Add similarity method "interval2"

This commit is contained in:
Matteo Cypriani 2012-03-06 12:27:15 +01:00
parent 54a387190f
commit 153d4c0ea6
3 changed files with 30 additions and 1 deletions

View File

@ -103,6 +103,13 @@ csv-file = /tmp/owlps-positioner.log
# packets in the measurement I are computed; the closest reference
# measurement R is the one with the highest number of packets in
# the interval [Im-Is, Im+Is].
# - interval2: Derived of the previous one, this algorithm
# computes the percent of packets in both the intervals
# [Im-0.674×Is, Im+0.674×Is] and [Im-Is, Im+Is].
# Assuming a normal distribution, we should find approximately
# 50% of the packets in the first interval, and 68% in the second
# interval. The closest R is the one for which the percents of
# the two intervals are the closest to these theoretical scores.
# The default is "mean".
#ss-similarity = mean

View File

@ -138,6 +138,28 @@ float Measurement::similarity(const Measurement &source) const
if (algorithm == "interval")
return 1 / nb_in_interval(source, get_std_deviation()) ;
/* Note: this score ranges from 0 (excluded) to 1 (obviously). */
if (algorithm == "interval2")
{
float std_dev = get_std_deviation() ;
float interval1 = nb_in_interval(source, 0.674 * std_dev) ;
float interval2 = nb_in_interval(source, std_dev) ;
/* Explanation: with a normal distribution, we normally have:
* - 68% of the values within the interval
* [mean-std.dev.;mean+std.dev.], and
* - 50% of the value within the interval
* [mean-.674*std.dev.;mean+.674*std.dev.] */
float percent1 = interval1 * 100 / source.get_nb_ss() ;
float percent2 = interval2 * 100 / source.get_nb_ss() ;
return (percent1 - 50) * (percent1 - 50) +
(percent2 - 68) * (percent2 - 68) ;
/* Note: this distance (score) ranges from 0 (with
* percent1==50 and percent2==68) to 7124 (with percent1
* and percent2==0). */
}
throw bad_configuration(
"Bad SS similarity algorithm name \""+ algorithm +"\"!") ;

View File

@ -242,7 +242,7 @@ void UserInterface::fill_positioning_options()
("positioning.ss-similarity",
po::value<string>()->default_value(DEFAULT_SS_SIMILARITY),
"Algorithm to calculate the similarity, in the signal strength space,"
" between two measurements. Allowed: mean, interval.")
" between two measurements. Allowed: mean, interval, interval2.")
("positioning.generate-reference-points",
po::value<bool>()->default_value(false),
"Generate reference points from the (auto)calibration requests"