Added the compute_mean_squared_distance() function.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403419
This commit is contained in:
Davis King 2010-01-29 00:30:30 +00:00
parent 35377a88e3
commit 0350895dc7
2 changed files with 40 additions and 0 deletions

View File

@ -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();
}
// ----------------------------------------------------------------------------------------
}

View File

@ -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.
!*/
// ----------------------------------------------------------------------------------------
}