Commit 9aecb4c4 authored by Davis King's avatar Davis King

Added the ability to learn non-negative weight vectors to the structural_assignment_trainer

object.
parent ac4598ae
...@@ -55,6 +55,16 @@ namespace dlib ...@@ -55,6 +55,16 @@ namespace dlib
return num_threads; return num_threads;
} }
bool learns_nonnegative_weights (
) const { return learn_nonnegative_weights; }
void set_learns_nonnegative_weights (
bool value
)
{
learn_nonnegative_weights = value;
}
void set_epsilon ( void set_epsilon (
double eps_ double eps_
) )
...@@ -183,7 +193,13 @@ namespace dlib ...@@ -183,7 +193,13 @@ namespace dlib
matrix<double,0,1> weights; matrix<double,0,1> weights;
solver(prob, weights); unsigned long num_nonnegative = 0;
if (learn_nonnegative_weights)
{
num_nonnegative = fe.num_features();
}
solver(prob, weights, num_nonnegative);
return assignment_function<feature_extractor>(weights,fe,force_assignment); return assignment_function<feature_extractor>(weights,fe,force_assignment);
...@@ -192,6 +208,7 @@ namespace dlib ...@@ -192,6 +208,7 @@ namespace dlib
private: private:
bool learn_nonnegative_weights;
bool force_assignment; bool force_assignment;
double C; double C;
oca solver; oca solver;
...@@ -208,6 +225,7 @@ namespace dlib ...@@ -208,6 +225,7 @@ namespace dlib
eps = 0.1; eps = 0.1;
num_threads = 2; num_threads = 2;
max_cache_size = 40; max_cache_size = 40;
learn_nonnegative_weights = false;
} }
feature_extractor fe; feature_extractor fe;
......
...@@ -52,6 +52,7 @@ namespace dlib ...@@ -52,6 +52,7 @@ namespace dlib
- #get_max_cache_size() == 40 - #get_max_cache_size() == 40
- #get_feature_extractor() == a default initialized feature_extractor - #get_feature_extractor() == a default initialized feature_extractor
- #forces_assignment() == false - #forces_assignment() == false
- #learns_nonnegative_weights() == false
!*/ !*/
explicit structural_assignment_trainer ( explicit structural_assignment_trainer (
...@@ -66,6 +67,7 @@ namespace dlib ...@@ -66,6 +67,7 @@ namespace dlib
- #get_max_cache_size() == 40 - #get_max_cache_size() == 40
- #get_feature_extractor() == fe - #get_feature_extractor() == fe
- #forces_assignment() == false - #forces_assignment() == false
- #learns_nonnegative_weights() == false
!*/ !*/
const feature_extractor& get_feature_extractor ( const feature_extractor& get_feature_extractor (
...@@ -162,6 +164,23 @@ namespace dlib ...@@ -162,6 +164,23 @@ namespace dlib
- returns a copy of the optimizer used to solve the structural SVM problem. - returns a copy of the optimizer used to solve the structural SVM problem.
!*/ !*/
bool learns_nonnegative_weights (
) const;
/*!
ensures
- The output of training is a weight vector that defines the behavior of an
assignment_function object. If learns_nonnegative_weights() == true then
the resulting weight vector will always have non-negative entries.
!*/
void set_learns_nonnegative_weights (
bool value
);
/*!
ensures
- #learns_nonnegative_weights() == value
!*/
void set_c ( void set_c (
double C double C
); );
......
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