Commit 542d9920 authored by Davis King's avatar Davis King

Switched the sample_pair object to use double to store its distance

value instead of float.
parent cfb0d477
...@@ -29,7 +29,7 @@ namespace dlib ...@@ -29,7 +29,7 @@ namespace dlib
that has the biggest distance that has the biggest distance
!*/ !*/
{ {
float dist = begin->distance(); double dist = begin->distance();
iterator worst = begin; iterator worst = begin;
for (; begin != end; ++begin) for (; begin != end; ++begin)
{ {
...@@ -92,8 +92,8 @@ namespace dlib ...@@ -92,8 +92,8 @@ namespace dlib
const unsigned long idx2 = rnd.get_random_32bit_number()%samples.size(); const unsigned long idx2 = rnd.get_random_32bit_number()%samples.size();
if (idx1 != idx2) if (idx1 != idx2)
{ {
const float dist = dist_funct(samples[idx1], samples[idx2]); const double dist = dist_funct(samples[idx1], samples[idx2]);
if (dist < std::numeric_limits<float>::infinity()) if (dist < std::numeric_limits<double>::infinity())
{ {
edges.push_back(sample_pair(idx1, idx2, dist)); edges.push_back(sample_pair(idx1, idx2, dist));
} }
...@@ -140,7 +140,7 @@ namespace dlib ...@@ -140,7 +140,7 @@ namespace dlib
helper( helper(
unsigned long idx1, unsigned long idx1,
unsigned long idx2, unsigned long idx2,
float dist double dist
) : ) :
index1(idx1), index1(idx1),
index2(idx2), index2(idx2),
...@@ -149,7 +149,7 @@ namespace dlib ...@@ -149,7 +149,7 @@ namespace dlib
unsigned long index1; unsigned long index1;
unsigned long index2; unsigned long index2;
float distance; double distance;
}; };
inline bool order_by_index ( inline bool order_by_index (
...@@ -221,8 +221,8 @@ namespace dlib ...@@ -221,8 +221,8 @@ namespace dlib
const unsigned long idx2 = rnd.get_random_32bit_number()%samples.size(); const unsigned long idx2 = rnd.get_random_32bit_number()%samples.size();
if (idx1 != idx2) if (idx1 != idx2)
{ {
const float dist = dist_funct(samples[idx1], samples[idx2]); const double dist = dist_funct(samples[idx1], samples[idx2]);
if (dist < std::numeric_limits<float>::infinity()) if (dist < std::numeric_limits<double>::infinity())
{ {
edges.push_back(impl2::helper(idx1, idx2, dist)); edges.push_back(impl2::helper(idx1, idx2, dist));
edges.push_back(impl2::helper(idx2, idx1, dist)); edges.push_back(impl2::helper(idx2, idx1, dist));
...@@ -320,10 +320,10 @@ namespace dlib ...@@ -320,10 +320,10 @@ namespace dlib
// Initialize all the edges to an edge with an invalid index // Initialize all the edges to an edge with an invalid index
edges.resize(samples.size()*k, edges.resize(samples.size()*k,
sample_pair(samples.size(),samples.size(),std::numeric_limits<float>::infinity())); sample_pair(samples.size(),samples.size(),std::numeric_limits<double>::infinity()));
// Hold the length for the longest edge for each node. Initially they are all infinity. // Hold the length for the longest edge for each node. Initially they are all infinity.
std::vector<float> worst_dists(samples.size(), std::numeric_limits<float>::infinity()); std::vector<double> worst_dists(samples.size(), std::numeric_limits<double>::infinity());
std::vector<sample_pair>::iterator begin_i, end_i, begin_j, end_j, itr; std::vector<sample_pair>::iterator begin_i, end_i, begin_j, end_j, itr;
begin_i = edges.begin(); begin_i = edges.begin();
...@@ -343,7 +343,7 @@ namespace dlib ...@@ -343,7 +343,7 @@ namespace dlib
begin_j += k; begin_j += k;
end_j += k; end_j += k;
const float dist = dist_funct(samples[i], samples[j]); const double dist = dist_funct(samples[i], samples[j]);
if (dist < worst_dists[i]) if (dist < worst_dists[i])
{ {
...@@ -446,7 +446,7 @@ namespace dlib ...@@ -446,7 +446,7 @@ namespace dlib
> >
void remove_long_edges ( void remove_long_edges (
vector_type& pairs, vector_type& pairs,
float distance_threshold double distance_threshold
) )
{ {
vector_type temp; vector_type temp;
...@@ -470,7 +470,7 @@ namespace dlib ...@@ -470,7 +470,7 @@ namespace dlib
> >
void remove_short_edges ( void remove_short_edges (
vector_type& pairs, vector_type& pairs,
float distance_threshold double distance_threshold
) )
{ {
vector_type temp; vector_type temp;
......
...@@ -45,7 +45,7 @@ namespace dlib ...@@ -45,7 +45,7 @@ namespace dlib
- contains_duplicate_pairs(#out) == false - contains_duplicate_pairs(#out) == false
- for all valid i: - for all valid i:
- #out[i].distance() == dist_funct(samples[#out[i].index1()], samples[#out[i].index2()]) - #out[i].distance() == dist_funct(samples[#out[i].index1()], samples[#out[i].index2()])
- #out[i].distance() < std::numeric_limits<float>::infinity() - #out[i].distance() < std::numeric_limits<double>::infinity()
- random_seed is used to seed the random number generator used by this - random_seed is used to seed the random number generator used by this
function. function.
!*/ !*/
...@@ -88,7 +88,7 @@ namespace dlib ...@@ -88,7 +88,7 @@ namespace dlib
- contains_duplicate_pairs(#out) == false - contains_duplicate_pairs(#out) == false
- for all valid i: - for all valid i:
- #out[i].distance() == dist_funct(samples[#out[i].index1()], samples[#out[i].index2()]) - #out[i].distance() == dist_funct(samples[#out[i].index1()], samples[#out[i].index2()])
- #out[i].distance() < std::numeric_limits<float>::infinity() - #out[i].distance() < std::numeric_limits<double>::infinity()
- random_seed is used to seed the random number generator used by this - random_seed is used to seed the random number generator used by this
function. function.
!*/ !*/
...@@ -118,7 +118,7 @@ namespace dlib ...@@ -118,7 +118,7 @@ namespace dlib
be not connected at all. be not connected at all.
- for all valid i: - for all valid i:
- #out[i].distance() == dist_funct(samples[#out[i].index1()], samples[#out[i].index2()]) - #out[i].distance() == dist_funct(samples[#out[i].index1()], samples[#out[i].index2()])
- #out[i].distance() < std::numeric_limits<float>::infinity() - #out[i].distance() < std::numeric_limits<double>::infinity()
- contains_duplicate_pairs(#out) == false - contains_duplicate_pairs(#out) == false
!*/ !*/
...@@ -169,7 +169,7 @@ namespace dlib ...@@ -169,7 +169,7 @@ namespace dlib
> >
void remove_long_edges ( void remove_long_edges (
vector_type& pairs, vector_type& pairs,
float distance_threshold double distance_threshold
); );
/*! /*!
requires requires
...@@ -188,7 +188,7 @@ namespace dlib ...@@ -188,7 +188,7 @@ namespace dlib
> >
void remove_short_edges ( void remove_short_edges (
vector_type& pairs, vector_type& pairs,
float distance_threshold double distance_threshold
); );
/*! /*!
requires requires
......
...@@ -31,11 +31,11 @@ namespace dlib ...@@ -31,11 +31,11 @@ namespace dlib
struct neighbor struct neighbor
{ {
neighbor(unsigned long idx, float w):index(idx), weight(w) {} neighbor(unsigned long idx, double w):index(idx), weight(w) {}
neighbor():index(0), weight(0) {} neighbor():index(0), weight(0) {}
unsigned long index; unsigned long index;
float weight; double weight;
}; };
typedef std::vector<neighbor>::const_iterator const_iterator; typedef std::vector<neighbor>::const_iterator const_iterator;
...@@ -137,7 +137,7 @@ namespace dlib ...@@ -137,7 +137,7 @@ namespace dlib
// finally, put the edges into data // finally, put the edges into data
for (unsigned long i = 0; i < edges.size(); ++i) for (unsigned long i = 0; i < edges.size(); ++i)
{ {
const float weight = weight_funct(edges[i]); const double weight = weight_funct(edges[i]);
sum_edge_weights += weight; sum_edge_weights += weight;
// make sure requires clause is not broken // make sure requires clause is not broken
......
...@@ -20,13 +20,13 @@ namespace dlib ...@@ -20,13 +20,13 @@ namespace dlib
_index1(0), _index1(0),
_index2(0) _index2(0)
{ {
_distance = std::numeric_limits<float>::infinity(); _distance = std::numeric_limits<double>::infinity();
} }
sample_pair ( sample_pair (
const unsigned long idx1, const unsigned long idx1,
const unsigned long idx2, const unsigned long idx2,
const float dist const double dist
) )
{ {
_distance = dist; _distance = dist;
...@@ -48,13 +48,13 @@ namespace dlib ...@@ -48,13 +48,13 @@ namespace dlib
const unsigned long& index2 ( const unsigned long& index2 (
) const { return _index2; } ) const { return _index2; }
const float& distance ( const double& distance (
) const { return _distance; } ) const { return _distance; }
private: private:
unsigned long _index1; unsigned long _index1;
unsigned long _index2; unsigned long _index2;
float _distance; double _distance;
}; };
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -120,7 +120,7 @@ namespace dlib ...@@ -120,7 +120,7 @@ namespace dlib
try try
{ {
unsigned long idx1, idx2; unsigned long idx1, idx2;
float dist; double dist;
deserialize(idx1,in); deserialize(idx1,in);
deserialize(idx2,in); deserialize(idx2,in);
......
...@@ -24,7 +24,7 @@ namespace dlib ...@@ -24,7 +24,7 @@ namespace dlib
of representing a single edge in more than one way. That is, of representing a single edge in more than one way. That is,
sample_pair(i,j) == sample_pair(j,i) for any value of i and j. sample_pair(i,j) == sample_pair(j,i) for any value of i and j.
This object also contains a float which can be used for any purpose. This object also contains a double which can be used for any purpose.
!*/ !*/
public: public:
...@@ -34,13 +34,13 @@ namespace dlib ...@@ -34,13 +34,13 @@ namespace dlib
ensures ensures
- #index1() == 0 - #index1() == 0
- #index2() == 0 - #index2() == 0
- #distance() == std::numeric_limits<float>::infinity() - #distance() == std::numeric_limits<double>::infinity()
!*/ !*/
sample_pair ( sample_pair (
const unsigned long idx1, const unsigned long idx1,
const unsigned long idx2, const unsigned long idx2,
const float dist const double dist
); );
/*! /*!
ensures ensures
...@@ -63,7 +63,7 @@ namespace dlib ...@@ -63,7 +63,7 @@ namespace dlib
- returns the second index value stored in this object - returns the second index value stored in this object
!*/ !*/
const float& distance ( const double& distance (
) const; ) const;
/*! /*!
ensures ensures
......
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