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
b4279045
Commit
b4279045
authored
Dec 20, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the option to force the last weight element to be 1 to the
svm_rank_trainer.
parent
0bf8683c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
5 deletions
+50
-5
svm_rank_trainer.h
dlib/svm/svm_rank_trainer.h
+31
-5
svm_rank_trainer_abstract.h
dlib/svm/svm_rank_trainer_abstract.h
+19
-0
No files found.
dlib/svm/svm_rank_trainer.h
View file @
b4279045
...
...
@@ -37,13 +37,15 @@ namespace dlib
const
std
::
vector
<
ranking_pair
<
sample_type
>
>&
samples_
,
const
bool
be_verbose_
,
const
scalar_type
eps_
,
const
unsigned
long
max_iter
const
unsigned
long
max_iter
,
const
bool
last_weight_1_
)
:
samples
(
samples_
),
C
(
C_
),
be_verbose
(
be_verbose_
),
eps
(
eps_
),
max_iterations
(
max_iter
)
max_iterations
(
max_iter
),
last_weight_1
(
last_weight_1_
)
{
}
...
...
@@ -111,6 +113,9 @@ namespace dlib
// rank flips. So a risk of 0.1 would mean that rank flips happen < 10% of the
// time.
if
(
last_weight_1
)
w
(
w
.
size
()
-
1
)
=
1
;
std
::
vector
<
double
>
rel_scores
;
std
::
vector
<
double
>
nonrel_scores
;
std
::
vector
<
unsigned
long
>
rel_counts
;
...
...
@@ -158,6 +163,9 @@ namespace dlib
risk
*=
scale
;
subgradient
=
scale
*
subgradient
;
if
(
last_weight_1
)
subgradient
(
w
.
size
()
-
1
)
=
0
;
}
private
:
...
...
@@ -172,6 +180,7 @@ namespace dlib
const
bool
be_verbose
;
const
scalar_type
eps
;
const
unsigned
long
max_iterations
;
const
bool
last_weight_1
;
};
// ----------------------------------------------------------------------------------------
...
...
@@ -186,11 +195,12 @@ namespace dlib
const
std
::
vector
<
ranking_pair
<
sample_type
>
>&
samples
,
const
bool
be_verbose
,
const
scalar_type
eps
,
const
unsigned
long
max_iterations
const
unsigned
long
max_iterations
,
const
bool
last_weight_1
)
{
return
oca_problem_ranking_svm
<
matrix_type
,
sample_type
>
(
C
,
samples
,
be_verbose
,
eps
,
max_iterations
);
C
,
samples
,
be_verbose
,
eps
,
max_iterations
,
last_weight_1
);
}
// ----------------------------------------------------------------------------------------
...
...
@@ -222,6 +232,7 @@ namespace dlib
eps
=
0
.
001
;
max_iterations
=
10000
;
learn_nonnegative_weights
=
false
;
last_weight_1
=
false
;
}
explicit
svm_rank_trainer
(
...
...
@@ -241,6 +252,7 @@ namespace dlib
eps
=
0
.
001
;
max_iterations
=
10000
;
learn_nonnegative_weights
=
false
;
last_weight_1
=
false
;
}
void
set_epsilon
(
...
...
@@ -283,6 +295,19 @@ namespace dlib
verbose
=
false
;
}
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_oca
(
const
oca
&
item
)
...
...
@@ -357,7 +382,7 @@ namespace dlib
num_nonnegative
=
num_dims
;
}
solver
(
make_oca_problem_ranking_svm
<
w_type
>
(
C
,
samples
,
verbose
,
eps
,
max_iterations
),
solver
(
make_oca_problem_ranking_svm
<
w_type
>
(
C
,
samples
,
verbose
,
eps
,
max_iterations
,
last_weight_1
),
w
,
num_nonnegative
);
...
...
@@ -390,6 +415,7 @@ namespace dlib
bool
verbose
;
unsigned
long
max_iterations
;
bool
learn_nonnegative_weights
;
bool
last_weight_1
;
};
// ----------------------------------------------------------------------------------------
...
...
dlib/svm/svm_rank_trainer_abstract.h
View file @
b4279045
...
...
@@ -57,6 +57,7 @@ namespace dlib
- this object will not be verbose unless be_verbose() is called
- #get_max_iterations() == 10000
- #learns_nonnegative_weights() == false
- #forces_last_weight_to_1() == false
!*/
explicit
svm_rank_trainer
(
...
...
@@ -74,6 +75,7 @@ namespace dlib
- this object will not be verbose unless be_verbose() is called
- #get_max_iterations() == 10000
- #learns_nonnegative_weights() == false
- #forces_last_weight_to_1() == false
!*/
void
set_epsilon
(
...
...
@@ -129,6 +131,23 @@ namespace dlib
- this object will not print anything to standard out
!*/
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.
!*/
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_oca
(
const
oca
&
item
);
...
...
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