Commit df250a8f authored by Davis King's avatar Davis King

Made the max iteration limit user settable.

parent 05e75ae3
...@@ -153,14 +153,15 @@ namespace dlib ...@@ -153,14 +153,15 @@ namespace dlib
custom_stop_strategy( custom_stop_strategy(
double C_, double C_,
double eps_, double eps_,
bool be_verbose_ bool be_verbose_,
unsigned long max_iter_
) )
{ {
_C = C_; _C = C_;
_cur_iter = 0; _cur_iter = 0;
_gradient_thresh = eps_; _gradient_thresh = eps_;
_max_iter = 1000; _max_iter = max_iter_;
_verbose = be_verbose_; _verbose = be_verbose_;
} }
...@@ -217,6 +218,7 @@ namespace dlib ...@@ -217,6 +218,7 @@ namespace dlib
verbose = false; verbose = false;
eps = 0.1; eps = 0.1;
C = 1; C = 1;
max_iter = 5000;
} }
void be_verbose( void be_verbose(
...@@ -259,6 +261,19 @@ namespace dlib ...@@ -259,6 +261,19 @@ namespace dlib
C = C_; C = C_;
} }
void set_max_iterations (
unsigned long max_iterations
)
{
max_iter = max_iterations;
}
unsigned long get_max_iterations (
) const
{
return max_iter;
}
double get_c ( double get_c (
) const ) const
{ {
...@@ -388,7 +403,7 @@ namespace dlib ...@@ -388,7 +403,7 @@ namespace dlib
// Now run the main part of the algorithm // Now run the main part of the algorithm
matrix<double,0,0,mem_manager_type> Aminus; matrix<double,0,0,mem_manager_type> Aminus;
find_max_box_constrained(lbfgs_search_strategy(10), find_max_box_constrained(lbfgs_search_strategy(10),
custom_stop_strategy(C, eps, verbose), custom_stop_strategy(C, eps, verbose, max_iter),
objective(data, Aminus), objective(data, Aminus),
derivative(num_triples, data, Aminus), derivative(num_triples, data, Aminus),
u, 0, C/num_triples); u, 0, C/num_triples);
...@@ -476,6 +491,7 @@ namespace dlib ...@@ -476,6 +491,7 @@ namespace dlib
bool verbose; bool verbose;
double eps; double eps;
double C; double C;
unsigned long max_iter;
// This is just a temporary variable that doesn't contribute to the // This is just a temporary variable that doesn't contribute to the
// state of this object. // state of this object.
...@@ -500,6 +516,7 @@ namespace dlib ...@@ -500,6 +516,7 @@ namespace dlib
serialize(item.verbose, out); serialize(item.verbose, out);
serialize(item.eps, out); serialize(item.eps, out);
serialize(item.C, out); serialize(item.C, out);
serialize(item.max_iter, out);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -522,6 +539,7 @@ namespace dlib ...@@ -522,6 +539,7 @@ namespace dlib
deserialize(item.verbose, in); deserialize(item.verbose, in);
deserialize(item.eps, in); deserialize(item.eps, in);
deserialize(item.C, in); deserialize(item.C, in);
deserialize(item.max_iter, in);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -66,6 +66,7 @@ namespace dlib ...@@ -66,6 +66,7 @@ namespace dlib
- means().size() == 0 - means().size() == 0
- get_epsilon() == 0.1 - get_epsilon() == 0.1
- get_c() == 1 - get_c() == 1
- get_max_iterations() == 5000
- This object is not verbose - This object is not verbose
WHAT THIS OBJECT REPRESENTS WHAT THIS OBJECT REPRESENTS
...@@ -159,6 +160,25 @@ namespace dlib ...@@ -159,6 +160,25 @@ namespace dlib
smaller values of C may encourage better generalization. smaller values of C may encourage better generalization.
!*/ !*/
void set_max_iterations (
unsigned long max_iterations
);
/*!
ensures
- #get_max_iterations() == max_iterations
!*/
unsigned long get_max_iterations (
) const;
/*!
ensures
- The train() routine uses an iterative numerical solver to find the best
distance metric. This function returns the maximum allowable number of
iterations it will use before terminating. Note that typically the
solver terminates prior to the max iteration count limit due to the error
dropping below get_epsilon().
!*/
void train ( void train (
const std::vector<frobmetric_training_sample<matrix_type> >& samples const std::vector<frobmetric_training_sample<matrix_type> >& samples
); );
......
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