[Positioner] Add Measurement::nb_in_interval()
Refactor Measurement::similarity() thanks to this new function.
This commit is contained in:
parent
6a8d8ec3be
commit
54a387190f
|
@ -127,6 +127,9 @@ void Measurement::clear()
|
||||||
|
|
||||||
float Measurement::similarity(const Measurement &source) const
|
float Measurement::similarity(const Measurement &source) const
|
||||||
{
|
{
|
||||||
|
assert(! ss_list.empty()) ;
|
||||||
|
assert(! source.ss_list.empty()) ;
|
||||||
|
|
||||||
string algorithm(
|
string algorithm(
|
||||||
Configuration::string_value("positioning.ss-similarity")) ;
|
Configuration::string_value("positioning.ss-similarity")) ;
|
||||||
|
|
||||||
|
@ -134,24 +137,27 @@ float Measurement::similarity(const Measurement &source) const
|
||||||
return ss_square_distance(source) ;
|
return ss_square_distance(source) ;
|
||||||
|
|
||||||
if (algorithm == "interval")
|
if (algorithm == "interval")
|
||||||
{
|
return 1 / nb_in_interval(source, get_std_deviation()) ;
|
||||||
float std_dev = get_std_deviation() ;
|
|
||||||
|
|
||||||
// Count the number of SS of source that are within the interval
|
|
||||||
unsigned int nb_values = 0 ;
|
|
||||||
for (map<pkt_id_t, ss_t>::const_iterator ss =
|
|
||||||
source.ss_list.begin() ; ss != source.ss_list.end() ; ++ss)
|
|
||||||
if (PosUtil::is_in_interval(average_dbm, std_dev, ss->second))
|
|
||||||
++nb_values ;
|
|
||||||
|
|
||||||
return 1 / nb_values ;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw bad_configuration(
|
throw bad_configuration(
|
||||||
"Bad SS similarity algorithm name \""+ algorithm +"\"!") ;
|
"Bad SS similarity algorithm name \""+ algorithm +"\"!") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int Measurement::
|
||||||
|
nb_in_interval(const Measurement &source, float bound) const
|
||||||
|
{
|
||||||
|
unsigned int nb_values = 0 ;
|
||||||
|
|
||||||
|
for (map<pkt_id_t, ss_t>::const_iterator ss =
|
||||||
|
source.ss_list.begin() ; ss != source.ss_list.end() ; ++ss)
|
||||||
|
if (PosUtil::is_in_interval(average_dbm, bound, ss->second))
|
||||||
|
++nb_values ;
|
||||||
|
|
||||||
|
return nb_values ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Measurement::recalculate_average()
|
void Measurement::recalculate_average()
|
||||||
{
|
{
|
||||||
average_dbm = 0 ;
|
average_dbm = 0 ;
|
||||||
|
|
|
@ -44,6 +44,10 @@ protected:
|
||||||
void recalculate_average(void) ;
|
void recalculate_average(void) ;
|
||||||
/// Update the average and variance with a new SS
|
/// Update the average and variance with a new SS
|
||||||
void update_average(ss_t ss_dbm) ;
|
void update_average(ss_t ss_dbm) ;
|
||||||
|
/// \brief Counts the number of SS of source that are within the
|
||||||
|
/// interval [average_dbm-bound;average_dbm+bound]
|
||||||
|
unsigned int nb_in_interval(
|
||||||
|
const Measurement &source, float bound) const ;
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue