Commit 0c2cb034 authored by Davis King's avatar Davis King

Added all missing asserts for the manifold_regularization code. Also

removed unnecessary requirement that distances be non-negative for the
graph creation tools.  All that really matters is that edge weights
are non-negative.  A user can use that distance float for whatever they
want as long as the above remains true.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403632
parent 81205791
......@@ -62,6 +62,18 @@ namespace dlib
std::vector<sample_pair, alloc>& out
)
{
// make sure requires clause is not broken
DLIB_ASSERT(samples.size() > 1 &&
0 < percent && percent <= 1 &&
num > 0,
"\t void find_percent_shortest_edges_randomly()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t samples.size(): " << samples.size()
<< "\n\t percent: " << percent
<< "\n\t num: " << num
);
std::vector<sample_pair, alloc> edges;
edges.reserve(num);
......@@ -116,6 +128,14 @@ namespace dlib
std::vector<sample_pair, alloc>& out
)
{
// make sure requires clause is not broken
DLIB_ASSERT(samples.size() > k && k > 0,
"\t void find_k_nearest_neighbors()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t samples.size(): " << samples.size()
<< "\n\t k: " << k
);
using namespace impl;
std::vector<sample_pair> edges;
......
......@@ -33,7 +33,7 @@ namespace dlib
- num > 0
- random_seed must be convertible to a string by dlib::cast_to_string()
- dist_funct(samples[i], samples[j]) must be a valid expression that evaluates
to a floating point number >= 0
to a floating point number
ensures
- This function randomly samples the space of pairs of integers between
0 and samples.size()-1 inclusive. For each of these pairs, (i,j), a
......@@ -68,7 +68,7 @@ namespace dlib
- samples.size() > k
- k > 0
- dist_funct(samples[i], samples[j]) must be a valid expression that evaluates
to a floating point number >= 0
to a floating point number
ensures
- #out == a set of sample_pair objects that represent all the k nearest
neighbors in samples according to the given distance function dist_funct.
......
......@@ -136,6 +136,14 @@ namespace dlib
for (unsigned long i = 0; i < edges.size(); ++i)
{
const float weight = weight_funct(edges[i]);
// make sure requires clause is not broken
DLIB_ASSERT(weight >= 0,
"\t void linear_manifold_regularizer::build()"
<< "\n\t You supplied a weight_funct() that generated a negative weight."
<< "\n\t weight: " << weight
);
*mutable_blocks[edges[i].index1()]++ = neighbor(edges[i].index2(), weight);
*mutable_blocks[edges[i].index2()]++ = neighbor(edges[i].index1(), weight);
}
......@@ -192,6 +200,19 @@ namespace dlib
const weight_function_type& weight_funct
)
{
// make sure requires clause is not broken
DLIB_ASSERT(edges.size() > 0 &&
contains_duplicate_pairs(edges) == false &&
max_index_value_plus_one(edges) <= samples.size(),
"\t void linear_manifold_regularizer::build()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t edges.size(): " << edges.size()
<< "\n\t samples.size(): " << samples.size()
<< "\n\t contains_duplicate_pairs(edges): " << contains_duplicate_pairs(edges)
<< "\n\t max_index_value_plus_one(edges): " << max_index_value_plus_one(edges)
);
impl::undirected_adjacency_list graph;
graph.build(edges, weight_funct);
......@@ -207,6 +228,13 @@ namespace dlib
scalar_type intrinsic_regularization_strength
) const
{
// make sure requires clause is not broken
DLIB_ASSERT(intrinsic_regularization_strength >= 0,
"\t matrix linear_manifold_regularizer::get_transformation_matrix()"
<< "\n\t This value must not be negative"
<< "\n\t intrinsic_regularization_strength: " << intrinsic_regularization_strength
);
if (dimensionality() == 0)
return general_matrix();
......
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