Commit 0350895d authored by Davis King's avatar Davis King

Added the compute_mean_squared_distance() function.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403419
parent 35377a88
......@@ -9,6 +9,7 @@
#include "feature_ranking_abstract.h"
#include "kcentroid.h"
#include "../optimization.h"
#include "../statistics.h"
#include <iostream>
namespace dlib
......@@ -448,6 +449,28 @@ namespace dlib
true);
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename alloc
>
double compute_mean_squared_distance (
const std::vector<T,alloc>& samples
)
{
running_stats<double> rs;
for (unsigned long i = 0; i < samples.size(); ++i)
{
for (unsigned long j = i+1; j < samples.size(); ++j)
{
rs.add(length_squared(samples[i] - samples[j]));
}
}
return rs.mean();
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -107,6 +107,23 @@ namespace dlib
standard out during its processing.
!*/
// ----------------------------------------------------------------------------------------
template <
typename T,
typename alloc
>
double compute_mean_squared_distance (
const std::vector<T,alloc>& samples
);
/*!
requires
- for all valid i: is_vector(samples[i]) == true
ensures
- computes the average value of the squares of all the pairwise
distances between every element of samples.
!*/
// ----------------------------------------------------------------------------------------
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment