[Positioner] "similarity" instead of "distance"
Standardise the use of the term "similarity" instead of "(ss_square_)distance" in the functions' and variables' names.
This commit is contained in:
parent
596c72b7a8
commit
1704ebc6b1
|
@ -71,24 +71,21 @@ void PosUtil::complete_with_dummy_measurements(
|
|||
|
||||
/**
|
||||
* Both lists must have the same size and contain the same keys:
|
||||
* you should call complete_with_dummy_measurements() before
|
||||
* compute_ss_square_distance().
|
||||
* you should call complete_with_dummy_measurements() before this
|
||||
* function.
|
||||
*
|
||||
* The distance between the two lists is computed by averaging the
|
||||
* square distances between the elements of both lists, two by two.
|
||||
* Therefore, it is not really an averaged square distance; you cannot
|
||||
* divide it to obtain an euclidean distance. To do that, one would
|
||||
* have to create a ss_distance() function that average the distances
|
||||
* between the elements of the lists instead of the square distance.
|
||||
* The similarity between the two lists is computed by averaging the
|
||||
* similarities between the elements of both lists, two by two, calling
|
||||
* Measurement::similarity().
|
||||
*/
|
||||
float PosUtil::ss_square_distance(
|
||||
float PosUtil::similarity(
|
||||
unordered_map<string, Measurement> &measurements1,
|
||||
unordered_map<string, Measurement> &measurements2)
|
||||
{
|
||||
assert(! measurements1.empty()) ;
|
||||
assert(measurements1.size() == measurements2.size()) ;
|
||||
|
||||
float distance = 0 ;
|
||||
float similarity = 0 ;
|
||||
|
||||
for (unordered_map<string, Measurement>::const_iterator i1 =
|
||||
measurements1.begin() ; i1 != measurements1.end() ; ++i1)
|
||||
|
@ -96,10 +93,10 @@ float PosUtil::ss_square_distance(
|
|||
unordered_map<string, Measurement>::const_iterator i2 =
|
||||
measurements2.find(i1->first) ;
|
||||
assert(i2 != measurements2.end()) ;
|
||||
distance += i1->second.similarity(i2->second) ;
|
||||
similarity += i1->second.similarity(i2->second) ;
|
||||
}
|
||||
|
||||
return distance / measurements1.size() ;
|
||||
return similarity / measurements1.size() ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ public:
|
|||
static void complete_with_dummy_measurements(
|
||||
std::tr1::unordered_map<std::string, Measurement> &measurements1,
|
||||
std::tr1::unordered_map<std::string, Measurement> &measurements2) ;
|
||||
/// Computes the distance between two Measurement lists
|
||||
static float ss_square_distance(
|
||||
/// Computes the similarity of two Measurement lists
|
||||
static float similarity(
|
||||
std::tr1::unordered_map<std::string, Measurement> &measurements1,
|
||||
std::tr1::unordered_map<std::string, Measurement> &measurements2) ;
|
||||
//@}
|
||||
|
|
|
@ -181,24 +181,25 @@ delete_request:
|
|||
|
||||
|
||||
/**
|
||||
* Before to compute the distance, all the measurements containted in
|
||||
* Before to compute the similarity, all the measurements containted in
|
||||
* #requests are put together, as if it was one big request.
|
||||
*
|
||||
* Note: to compute the distance between two requests, one should use
|
||||
* Request::ss_square_distance().
|
||||
* Note: to compute the similarity between two requests, one should use
|
||||
* Request::similarity().
|
||||
*/
|
||||
float ReferencePoint::ss_square_distance(const Request &source) const
|
||||
float ReferencePoint::similarity(const Request &source) const
|
||||
{
|
||||
assert(! requests.empty()) ;
|
||||
|
||||
unordered_map<string, Measurement>
|
||||
source_measurements(source.get_measurements()),
|
||||
all_measurements(get_all_measurements()) ;
|
||||
source_measurements(source.get_measurements()) ;
|
||||
unordered_map<string, Measurement>
|
||||
all_measurements(get_all_measurements()) ;
|
||||
|
||||
PosUtil::complete_with_dummy_measurements(
|
||||
all_measurements, source_measurements) ;
|
||||
|
||||
return PosUtil::ss_square_distance(
|
||||
return PosUtil::similarity(
|
||||
all_measurements, source_measurements) ;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,8 +73,8 @@ public:
|
|||
|
||||
/** @name Operations */
|
||||
//@{
|
||||
/// Computes the distance between the ReferencePoint and a Request
|
||||
float ss_square_distance(const Request &source) const ;
|
||||
/// Computes the similarity of the ReferencePoint and a Request
|
||||
float similarity(const Request &source) const ;
|
||||
/// Computes the Friis index for the given AccessPoint
|
||||
float friis_index_for_ap(const std::string &ap_mac) const ;
|
||||
/// Computes the Friis indexes sum for the given AccessPoint
|
||||
|
|
|
@ -90,16 +90,17 @@ void Request::clear()
|
|||
/* *** Operations *** */
|
||||
|
||||
|
||||
float Request::ss_square_distance(const Request &source) const
|
||||
float Request::similarity(const Request &source) const
|
||||
{
|
||||
unordered_map<string, Measurement>
|
||||
source_measurements(source.measurements),
|
||||
my_measurements(measurements) ;
|
||||
source_measurements(source.measurements) ;
|
||||
unordered_map<string, Measurement>
|
||||
my_measurements(measurements) ;
|
||||
|
||||
PosUtil::complete_with_dummy_measurements(
|
||||
my_measurements, source_measurements) ;
|
||||
|
||||
return PosUtil::ss_square_distance(
|
||||
return PosUtil::similarity(
|
||||
my_measurements, source_measurements) ;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,8 +105,8 @@ public:
|
|||
|
||||
/** @name Operations */
|
||||
//@{
|
||||
/// Computes the distance between two Request
|
||||
float ss_square_distance(const Request &source) const ;
|
||||
/// Computes the similarity of two Request
|
||||
float similarity(const Request &source) const ;
|
||||
//@}
|
||||
|
||||
/** @name Operators */
|
||||
|
|
|
@ -406,7 +406,7 @@ closest_reference_point(const Request &request)
|
|||
ignore_aps = false ;
|
||||
}
|
||||
|
||||
float distance = i->ss_square_distance(request) ;
|
||||
float similarity = i->similarity(request) ;
|
||||
unordered_set<ReferencePoint>::const_iterator closest = i ;
|
||||
|
||||
for (++i ; i != reference_points.end() ; ++i)
|
||||
|
@ -414,10 +414,10 @@ closest_reference_point(const Request &request)
|
|||
if (ignore_aps && is_ap_coordinate(*i))
|
||||
continue ;
|
||||
|
||||
float tmp_distance = i->ss_square_distance(request) ;
|
||||
if (tmp_distance < distance)
|
||||
float tmp_similarity = i->similarity(request) ;
|
||||
if (tmp_similarity < similarity)
|
||||
{
|
||||
distance = tmp_distance ;
|
||||
similarity = tmp_similarity ;
|
||||
closest = i ;
|
||||
}
|
||||
}
|
||||
|
@ -794,7 +794,7 @@ closest_calibration_request(const Request &request)
|
|||
}
|
||||
}
|
||||
|
||||
float distance = i->ss_square_distance(request) ;
|
||||
float similarity = i->similarity(request) ;
|
||||
unordered_set<CalibrationRequest>::const_iterator closest = i ;
|
||||
|
||||
for (++i ; i != calibration_requests.end() ; ++i)
|
||||
|
@ -802,10 +802,10 @@ closest_calibration_request(const Request &request)
|
|||
if (ignore_aps && is_ap_coordinate(*i->get_reference_point()))
|
||||
continue ;
|
||||
|
||||
float tmp_distance = i->ss_square_distance(request) ;
|
||||
if (tmp_distance < distance)
|
||||
float tmp_similarity = i->similarity(request) ;
|
||||
if (tmp_similarity < similarity)
|
||||
{
|
||||
distance = tmp_distance ;
|
||||
similarity = tmp_similarity ;
|
||||
closest = i ;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue