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
b445ddbd
Commit
b445ddbd
authored
Jan 03, 2013
by
Davis King
Browse files
Switched this code to use the oca object's ability to force a weight to 1
instead of rolling its own implementation.
parent
277b47ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
20 deletions
+13
-20
dlib/svm/svm_rank_trainer.h
dlib/svm/svm_rank_trainer.h
+13
-20
No files found.
dlib/svm/svm_rank_trainer.h
View file @
b445ddbd
...
@@ -37,15 +37,13 @@ namespace dlib
...
@@ -37,15 +37,13 @@ namespace dlib
const
std
::
vector
<
ranking_pair
<
sample_type
>
>&
samples_
,
const
std
::
vector
<
ranking_pair
<
sample_type
>
>&
samples_
,
const
bool
be_verbose_
,
const
bool
be_verbose_
,
const
scalar_type
eps_
,
const
scalar_type
eps_
,
const
unsigned
long
max_iter
,
const
unsigned
long
max_iter
const
bool
last_weight_1_
)
:
)
:
samples
(
samples_
),
samples
(
samples_
),
C
(
C_
),
C
(
C_
),
be_verbose
(
be_verbose_
),
be_verbose
(
be_verbose_
),
eps
(
eps_
),
eps
(
eps_
),
max_iterations
(
max_iter
),
max_iterations
(
max_iter
)
last_weight_1
(
last_weight_1_
)
{
{
}
}
...
@@ -113,8 +111,6 @@ namespace dlib
...
@@ -113,8 +111,6 @@ namespace dlib
// rank flips. So a risk of 0.1 would mean that rank flips happen < 10% of the
// rank flips. So a risk of 0.1 would mean that rank flips happen < 10% of the
// time.
// time.
if
(
last_weight_1
)
w
(
w
.
size
()
-
1
)
=
1
;
std
::
vector
<
double
>
rel_scores
;
std
::
vector
<
double
>
rel_scores
;
std
::
vector
<
double
>
nonrel_scores
;
std
::
vector
<
double
>
nonrel_scores
;
...
@@ -163,12 +159,6 @@ namespace dlib
...
@@ -163,12 +159,6 @@ namespace dlib
risk
*=
scale
;
risk
*=
scale
;
subgradient
=
scale
*
subgradient
;
subgradient
=
scale
*
subgradient
;
if
(
last_weight_1
)
{
w
(
w
.
size
()
-
1
)
=
0
;
subgradient
(
w
.
size
()
-
1
)
=
0
;
}
}
}
private:
private:
...
@@ -183,7 +173,6 @@ namespace dlib
...
@@ -183,7 +173,6 @@ namespace dlib
const
bool
be_verbose
;
const
bool
be_verbose
;
const
scalar_type
eps
;
const
scalar_type
eps
;
const
unsigned
long
max_iterations
;
const
unsigned
long
max_iterations
;
const
bool
last_weight_1
;
};
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
@@ -198,12 +187,11 @@ namespace dlib
...
@@ -198,12 +187,11 @@ namespace dlib
const
std
::
vector
<
ranking_pair
<
sample_type
>
>&
samples
,
const
std
::
vector
<
ranking_pair
<
sample_type
>
>&
samples
,
const
bool
be_verbose
,
const
bool
be_verbose
,
const
scalar_type
eps
,
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
>
(
return
oca_problem_ranking_svm
<
matrix_type
,
sample_type
>
(
C
,
samples
,
be_verbose
,
eps
,
max_iterations
,
last_weight_1
);
C
,
samples
,
be_verbose
,
eps
,
max_iterations
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
@@ -385,12 +373,17 @@ namespace dlib
...
@@ -385,12 +373,17 @@ namespace dlib
num_nonnegative
=
num_dims
;
num_nonnegative
=
num_dims
;
}
}
solver
(
make_oca_problem_ranking_svm
<
w_type
>
(
C
,
samples
,
verbose
,
eps
,
max_iterations
,
last_weight_1
),
unsigned
long
force_weight_1_idx
=
std
::
numeric_limits
<
unsigned
long
>::
max
();
if
(
last_weight_1
)
{
force_weight_1_idx
=
num_dims
-
1
;
}
solver
(
make_oca_problem_ranking_svm
<
w_type
>
(
C
,
samples
,
verbose
,
eps
,
max_iterations
),
w
,
w
,
num_nonnegative
);
num_nonnegative
,
force_weight_1_idx
);
if
(
last_weight_1
)
w
(
w
.
size
()
-
1
)
=
1
;
// 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
;
...
...
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