Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
9ab59297
Commit
9ab59297
authored
Jan 04, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the forces_last_weight_to_1() option to the svm_c_linear_trainer.
parent
96264d33
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
2 deletions
+49
-2
svm_c_linear_trainer.h
dlib/svm/svm_c_linear_trainer.h
+28
-2
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
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
;
};
// ----------------------------------------------------------------------------------------
...
...
dlib/svm/svm_c_linear_trainer_abstract.h
View file @
9ab59297
...
...
@@ -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
);
...
...
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