Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
9ab59297
Commit
9ab59297
authored
Jan 03, 2013
by
Davis King
Browse files
Added the forces_last_weight_to_1() option to the svm_c_linear_trainer.
parent
96264d33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
2 deletions
+49
-2
dlib/svm/svm_c_linear_trainer.h
dlib/svm/svm_c_linear_trainer.h
+28
-2
dlib/svm/svm_c_linear_trainer_abstract.h
dlib/svm/svm_c_linear_trainer_abstract.h
+21
-0
No files found.
dlib/svm/svm_c_linear_trainer.h
View file @
9ab59297
...
@@ -352,6 +352,7 @@ namespace dlib
...
@@ -352,6 +352,7 @@ namespace dlib
eps
=
0.001
;
eps
=
0.001
;
max_iterations
=
10000
;
max_iterations
=
10000
;
learn_nonnegative_weights
=
false
;
learn_nonnegative_weights
=
false
;
last_weight_1
=
false
;
}
}
explicit
svm_c_linear_trainer
(
explicit
svm_c_linear_trainer
(
...
@@ -372,6 +373,7 @@ namespace dlib
...
@@ -372,6 +373,7 @@ namespace dlib
eps
=
0.001
;
eps
=
0.001
;
max_iterations
=
10000
;
max_iterations
=
10000
;
learn_nonnegative_weights
=
false
;
learn_nonnegative_weights
=
false
;
last_weight_1
=
false
;
}
}
void
set_epsilon
(
void
set_epsilon
(
...
@@ -443,6 +445,19 @@ namespace dlib
...
@@ -443,6 +445,19 @@ namespace dlib
learn_nonnegative_weights
=
value
;
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
(
void
set_c
(
scalar_type
C
scalar_type
C
)
)
...
@@ -555,16 +570,26 @@ namespace dlib
...
@@ -555,16 +570,26 @@ namespace dlib
typedef
matrix
<
scalar_type
,
0
,
1
>
w_type
;
typedef
matrix
<
scalar_type
,
0
,
1
>
w_type
;
w_type
w
;
w_type
w
;
const
unsigned
long
num_dims
=
max_index_plus_one
(
x
);
unsigned
long
num_nonnegative
=
0
;
unsigned
long
num_nonnegative
=
0
;
if
(
learn_nonnegative_weights
)
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
(
svm_objective
=
solver
(
make_oca_problem_c_svm
<
w_type
>
(
Cpos
,
Cneg
,
x
,
y
,
verbose
,
eps
,
max_iterations
),
make_oca_problem_c_svm
<
w_type
>
(
Cpos
,
Cneg
,
x
,
y
,
verbose
,
eps
,
max_iterations
),
w
,
w
,
num_nonnegative
);
num_nonnegative
,
force_weight_1_idx
);
// put the solution into a decision function and then return it
// put the solution into a decision function and then return it
decision_function
<
kernel_type
>
df
;
decision_function
<
kernel_type
>
df
;
...
@@ -589,6 +614,7 @@ namespace dlib
...
@@ -589,6 +614,7 @@ namespace dlib
bool
verbose
;
bool
verbose
;
unsigned
long
max_iterations
;
unsigned
long
max_iterations
;
bool
learn_nonnegative_weights
;
bool
learn_nonnegative_weights
;
bool
last_weight_1
;
};
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/svm/svm_c_linear_trainer_abstract.h
View file @
9ab59297
...
@@ -53,6 +53,7 @@ namespace dlib
...
@@ -53,6 +53,7 @@ namespace dlib
- this object will not be verbose unless be_verbose() is called
- this object will not be verbose unless be_verbose() is called
- #get_max_iterations() == 10000
- #get_max_iterations() == 10000
- #learns_nonnegative_weights() == false
- #learns_nonnegative_weights() == false
- #force_last_weight_to_1() == false
!*/
!*/
explicit
svm_c_linear_trainer
(
explicit
svm_c_linear_trainer
(
...
@@ -71,6 +72,7 @@ namespace dlib
...
@@ -71,6 +72,7 @@ namespace dlib
- this object will not be verbose unless be_verbose() is called
- this object will not be verbose unless be_verbose() is called
- #get_max_iterations() == 10000
- #get_max_iterations() == 10000
- #learns_nonnegative_weights() == false
- #learns_nonnegative_weights() == false
- #force_last_weight_to_1() == false
!*/
!*/
void
set_epsilon
(
void
set_epsilon
(
...
@@ -170,6 +172,25 @@ namespace dlib
...
@@ -170,6 +172,25 @@ namespace dlib
- #learns_nonnegative_weights() == value
- #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
(
void
set_c
(
scalar_type
C
scalar_type
C
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment