Added the ability to threshold out length's outside a certain range into

the squared_euclidean_distance object.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403656
This commit is contained in:
Davis King 2010-05-30 19:22:38 +00:00
parent 8cf7fad6cc
commit ccbdf520b7
2 changed files with 50 additions and 3 deletions

View File

@ -6,6 +6,7 @@
#include "function_objects_abstract.h"
#include "../matrix.h"
#include <cmath>
#include <limits>
namespace dlib
{
@ -14,13 +15,34 @@ namespace dlib
struct squared_euclidean_distance
{
squared_euclidean_distance (
) :
lower(0),
upper(std::numeric_limits<double>::infinity())
{}
squared_euclidean_distance (
const double l,
const double u
) :
lower(l),
upper(u)
{}
const double lower;
const double upper;
template <typename sample_type>
double operator() (
const sample_type& a,
const sample_type& b
) const
{
return length_squared(a-b);
const double len = length_squared(a-b);
if (lower <= len && len <= upper)
return len;
else
return std::numeric_limits<double>::infinity();
}
};

View File

@ -16,9 +16,30 @@ namespace dlib
/*!
WHAT THIS OBJECT REPRESENTS
This is a simple function object that computes squared euclidean distance
between two dlib::matrix objects.
between two dlib::matrix objects.
!*/
squared_euclidean_distance (
);
/*!
ensures
- #lower == 0
- #upper == std::numeric_limits<double>::infinity()
!*/
squared_euclidean_distance (
const double l,
const double u
);
/*!
ensures
- #lower == l
- #upper == u
!*/
const double lower;
const double upper;
template <typename sample_type>
double operator() (
const sample_type& a,
@ -28,7 +49,11 @@ namespace dlib
requires
- sample_type should be a kind of dlib::matrix
ensures
- returns length_squared(a-b);
- let LEN = length_squared(a-b)
- if (lower <= LEN <= upper) then
- returns LEN
- else
- returns std::numeric_limits<double>::infinity()
!*/
};