From 153d4c0ea654fa6acdb4a6127545874e8b53dd82 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 6 Mar 2012 12:27:15 +0100 Subject: [PATCH] [Positioner] Add similarity method "interval2" --- owlps-positioner/cfg/owlps-positioner.conf | 7 +++++++ owlps-positioner/src/measurement.cc | 22 ++++++++++++++++++++++ owlps-positioner/src/userinterface.cc | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/owlps-positioner/cfg/owlps-positioner.conf b/owlps-positioner/cfg/owlps-positioner.conf index c663a07..c82bf6f 100644 --- a/owlps-positioner/cfg/owlps-positioner.conf +++ b/owlps-positioner/cfg/owlps-positioner.conf @@ -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 diff --git a/owlps-positioner/src/measurement.cc b/owlps-positioner/src/measurement.cc index 8f882a6..f39bf10 100644 --- a/owlps-positioner/src/measurement.cc +++ b/owlps-positioner/src/measurement.cc @@ -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 +"\"!") ; diff --git a/owlps-positioner/src/userinterface.cc b/owlps-positioner/src/userinterface.cc index c74ace8..32b78bb 100644 --- a/owlps-positioner/src/userinterface.cc +++ b/owlps-positioner/src/userinterface.cc @@ -242,7 +242,7 @@ void UserInterface::fill_positioning_options() ("positioning.ss-similarity", po::value()->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()->default_value(false), "Generate reference points from the (auto)calibration requests"