mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Added the forces_last_weight_to_1() option to the svm_c_linear_trainer.
This commit is contained in:
parent
96264d3339
commit
9ab59297b2
@ -352,6 +352,7 @@ namespace dlib
|
||||
eps = 0.001;
|
||||
max_iterations = 10000;
|
||||
learn_nonnegative_weights = false;
|
||||
last_weight_1 = false;
|
||||
}
|
||||
|
||||
explicit svm_c_linear_trainer (
|
||||
@ -372,6 +373,7 @@ namespace dlib
|
||||
eps = 0.001;
|
||||
max_iterations = 10000;
|
||||
learn_nonnegative_weights = false;
|
||||
last_weight_1 = false;
|
||||
}
|
||||
|
||||
void set_epsilon (
|
||||
@ -443,6 +445,19 @@ namespace dlib
|
||||
learn_nonnegative_weights = value;
|
||||
}
|
||||
|
||||
bool forces_last_weight_to_1 (
|
||||
) const
|
||||
{
|
||||
return last_weight_1;
|
||||
}
|
||||
|
||||
void force_last_weight_to_1 (
|
||||
bool should_last_weight_be_1
|
||||
)
|
||||
{
|
||||
last_weight_1 = should_last_weight_be_1;
|
||||
}
|
||||
|
||||
void set_c (
|
||||
scalar_type C
|
||||
)
|
||||
@ -555,16 +570,26 @@ namespace dlib
|
||||
typedef matrix<scalar_type,0,1> w_type;
|
||||
w_type w;
|
||||
|
||||
const unsigned long num_dims = max_index_plus_one(x);
|
||||
|
||||
unsigned long num_nonnegative = 0;
|
||||
if (learn_nonnegative_weights)
|
||||
{
|
||||
num_nonnegative = max_index_plus_one(x);
|
||||
num_nonnegative = num_dims;
|
||||
}
|
||||
|
||||
unsigned long force_weight_1_idx = std::numeric_limits<unsigned long>::max();
|
||||
if (last_weight_1)
|
||||
{
|
||||
force_weight_1_idx = num_dims-1;
|
||||
}
|
||||
|
||||
|
||||
svm_objective = solver(
|
||||
make_oca_problem_c_svm<w_type>(Cpos, Cneg, x, y, verbose, eps, max_iterations),
|
||||
w,
|
||||
num_nonnegative);
|
||||
num_nonnegative,
|
||||
force_weight_1_idx);
|
||||
|
||||
// put the solution into a decision function and then return it
|
||||
decision_function<kernel_type> df;
|
||||
@ -589,6 +614,7 @@ namespace dlib
|
||||
bool verbose;
|
||||
unsigned long max_iterations;
|
||||
bool learn_nonnegative_weights;
|
||||
bool last_weight_1;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
@ -53,6 +53,7 @@ namespace dlib
|
||||
- this object will not be verbose unless be_verbose() is called
|
||||
- #get_max_iterations() == 10000
|
||||
- #learns_nonnegative_weights() == false
|
||||
- #force_last_weight_to_1() == false
|
||||
!*/
|
||||
|
||||
explicit svm_c_linear_trainer (
|
||||
@ -71,6 +72,7 @@ namespace dlib
|
||||
- this object will not be verbose unless be_verbose() is called
|
||||
- #get_max_iterations() == 10000
|
||||
- #learns_nonnegative_weights() == false
|
||||
- #force_last_weight_to_1() == false
|
||||
!*/
|
||||
|
||||
void set_epsilon (
|
||||
@ -170,6 +172,25 @@ namespace dlib
|
||||
- #learns_nonnegative_weights() == value
|
||||
!*/
|
||||
|
||||
bool forces_last_weight_to_1 (
|
||||
) const;
|
||||
/*!
|
||||
ensures
|
||||
- returns true if this trainer has the constraint that the last weight in
|
||||
the learned parameter vector must be 1. This is the weight corresponding
|
||||
to the feature in the training vectors with the highest dimension.
|
||||
- Forcing the last weight to 1 also disables the bias and therefore the b
|
||||
field of the learned decision_function will be 0 when forces_last_weight_to_1() == true.
|
||||
!*/
|
||||
|
||||
void force_last_weight_to_1 (
|
||||
bool should_last_weight_be_1
|
||||
);
|
||||
/*!
|
||||
ensures
|
||||
- #forces_last_weight_to_1() == should_last_weight_be_1
|
||||
!*/
|
||||
|
||||
void set_c (
|
||||
scalar_type C
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user