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
277b47ae
Commit
277b47ae
authored
Jan 03, 2013
by
Davis King
Browse files
Added the option to force the last weight to 1.
parent
59cd70c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
dlib/optimization/optimization_oca.h
dlib/optimization/optimization_oca.h
+21
-1
dlib/optimization/optimization_oca_abstract.h
dlib/optimization/optimization_oca_abstract.h
+11
-1
No files found.
dlib/optimization/optimization_oca.h
View file @
277b47ae
...
@@ -111,7 +111,8 @@ namespace dlib
...
@@ -111,7 +111,8 @@ namespace dlib
typename
matrix_type
::
type
operator
()
(
typename
matrix_type
::
type
operator
()
(
const
oca_problem
<
matrix_type
>&
problem
,
const
oca_problem
<
matrix_type
>&
problem
,
matrix_type
&
w
,
matrix_type
&
w
,
unsigned
long
num_nonnegative
=
0
unsigned
long
num_nonnegative
=
0
,
unsigned
long
force_weight_to_1
=
std
::
numeric_limits
<
unsigned
long
>::
max
()
)
const
)
const
{
{
const
unsigned
long
num_dims
=
problem
.
get_num_dimensions
();
const
unsigned
long
num_dims
=
problem
.
get_num_dimensions
();
...
@@ -176,7 +177,23 @@ namespace dlib
...
@@ -176,7 +177,23 @@ namespace dlib
// add the next cutting plane
// add the next cutting plane
scalar_type
cur_risk
;
scalar_type
cur_risk
;
if
(
force_weight_to_1
<
(
unsigned
long
)
w
.
size
())
w
(
force_weight_to_1
)
=
1
;
problem
.
get_risk
(
w
,
cur_risk
,
new_plane
);
problem
.
get_risk
(
w
,
cur_risk
,
new_plane
);
if
(
force_weight_to_1
<
(
unsigned
long
)
w
.
size
())
{
// We basically arrange for the w(force_weight_to_1) element and all
// subsequent elements of w to not be involved in the optimization at
// all. An easy way to do this is to just make sure the elements of w
// corresponding elements in the subgradient are always set to zero
// while we run the cutting plane algorithm. The only time
// w(force_weight_to_1) is 1 is when we pass it to the oca_problem.
set_rowm
(
w
,
range
(
force_weight_to_1
,
w
.
size
()
-
1
))
=
0
;
set_rowm
(
new_plane
,
range
(
force_weight_to_1
,
new_plane
.
size
()
-
1
))
=
0
;
}
if
(
planes
.
size
()
!=
0
)
if
(
planes
.
size
()
!=
0
)
planes
=
join_rows
(
planes
,
new_plane
);
planes
=
join_rows
(
planes
,
new_plane
);
else
else
...
@@ -263,6 +280,9 @@ namespace dlib
...
@@ -263,6 +280,9 @@ namespace dlib
++
counter
;
++
counter
;
}
}
if
(
force_weight_to_1
<
(
unsigned
long
)
w
.
size
())
w
(
force_weight_to_1
)
=
1
;
return
cur_obj
;
return
cur_obj
;
}
}
...
...
dlib/optimization/optimization_oca_abstract.h
View file @
277b47ae
...
@@ -154,7 +154,8 @@ namespace dlib
...
@@ -154,7 +154,8 @@ namespace dlib
typename
matrix_type
::
type
operator
()
(
typename
matrix_type
::
type
operator
()
(
const
oca_problem
<
matrix_type
>&
problem
,
const
oca_problem
<
matrix_type
>&
problem
,
matrix_type
&
w
,
matrix_type
&
w
,
unsigned
long
num_nonnegative
=
0
unsigned
long
num_nonnegative
=
0
,
unsigned
long
force_weight_to_1
=
std
::
numeric_limits
<
unsigned
long
>::
max
()
)
const
;
)
const
;
/*!
/*!
requires
requires
...
@@ -171,6 +172,15 @@ namespace dlib
...
@@ -171,6 +172,15 @@ namespace dlib
non-negative. This includes the copies of w passed to get_risk()
non-negative. This includes the copies of w passed to get_risk()
in the form of the current_solution vector as well as the final
in the form of the current_solution vector as well as the final
output of this function.
output of this function.
- if (force_weight_to_1 < problem.get_num_dimensions()) then
- The optimizer enforces the following constraints:
- #w(force_weight_to_1) == 1
- for all i > force_weight_to_1:
- #w(i) == 0
- That is, the element in the weight vector at the index indicated
by force_weight_to_1 will have a value of 1 upon completion of
this function, while all subsequent elements of w will have
values of 0.
!*/
!*/
void
set_subproblem_epsilon
(
void
set_subproblem_epsilon
(
...
...
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