Commit ccbdf520 authored by Davis King's avatar Davis King

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
parent 8cf7fad6
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "function_objects_abstract.h" #include "function_objects_abstract.h"
#include "../matrix.h" #include "../matrix.h"
#include <cmath> #include <cmath>
#include <limits>
namespace dlib namespace dlib
{ {
...@@ -14,13 +15,34 @@ namespace dlib ...@@ -14,13 +15,34 @@ namespace dlib
struct squared_euclidean_distance 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> template <typename sample_type>
double operator() ( double operator() (
const sample_type& a, const sample_type& a,
const sample_type& b const sample_type& b
) const ) 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();
} }
}; };
......
...@@ -16,9 +16,30 @@ namespace dlib ...@@ -16,9 +16,30 @@ namespace dlib
/*! /*!
WHAT THIS OBJECT REPRESENTS WHAT THIS OBJECT REPRESENTS
This is a simple function object that computes squared euclidean distance 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> template <typename sample_type>
double operator() ( double operator() (
const sample_type& a, const sample_type& a,
...@@ -28,7 +49,11 @@ namespace dlib ...@@ -28,7 +49,11 @@ namespace dlib
requires requires
- sample_type should be a kind of dlib::matrix - sample_type should be a kind of dlib::matrix
ensures 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()
!*/ !*/
}; };
......
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