Commit b7d81290 authored by Davis King's avatar Davis King

Added the ability to learn only non-negative weights to the svm_c_linear_trainer.

parent 2f562b03
......@@ -352,6 +352,7 @@ namespace dlib
verbose = false;
eps = 0.001;
max_iterations = 10000;
learn_nonnegative_weights = false;
}
explicit svm_c_linear_trainer (
......@@ -371,6 +372,7 @@ namespace dlib
verbose = false;
eps = 0.001;
max_iterations = 10000;
learn_nonnegative_weights = false;
}
void set_epsilon (
......@@ -432,6 +434,16 @@ namespace dlib
return kernel_type();
}
bool learns_nonnegative_weights (
) const { return learn_nonnegative_weights; }
void set_learns_nonnegative_weights (
bool value
)
{
learn_nonnegative_weights = value;
}
void set_c (
scalar_type C
)
......@@ -544,9 +556,16 @@ namespace dlib
typedef matrix<scalar_type,0,1> w_type;
w_type w;
unsigned long num_nonnegative = 0;
if (learn_nonnegative_weights)
{
num_nonnegative = max_index_plus_one(x);
}
svm_objective = solver(
make_oca_problem_c_svm<w_type>(Cpos, Cneg, x, y, verbose, eps, max_iterations),
w);
w,
num_nonnegative);
// put the solution into a decision function and then return it
decision_function<kernel_type> df;
......@@ -570,6 +589,7 @@ namespace dlib
scalar_type eps;
bool verbose;
unsigned long max_iterations;
bool learn_nonnegative_weights;
};
// ----------------------------------------------------------------------------------------
......
......@@ -52,6 +52,7 @@ namespace dlib
- #get_epsilon() == 0.001
- this object will not be verbose unless be_verbose() is called
- #get_max_iterations() == 10000
- #learns_nonnegative_weights() == false
!*/
explicit svm_c_linear_trainer (
......@@ -69,6 +70,7 @@ namespace dlib
- #get_epsilon() == 0.001
- this object will not be verbose unless be_verbose() is called
- #get_max_iterations() == 10000
- #learns_nonnegative_weights() == false
!*/
void set_epsilon (
......@@ -145,6 +147,27 @@ namespace dlib
returns kernel_type()
!*/
bool learns_nonnegative_weights (
) const;
/*!
ensures
- The output of training is a weight vector and a bias value. These
two things define the resulting decision function. That is, the
decision function simply takes the dot product between the learned
weight vector and a test sample, then subtracts the bias value.
Therefore, if learns_nonnegative_weights() == true then the resulting
learned weight vector will always have non-negative entries. The
bias value may still be negative though.
!*/
void set_learns_nonnegative_weights (
bool value
);
/*!
ensures
- #learns_nonnegative_weights() == value
!*/
void set_c (
scalar_type 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