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
b7d81290
Commit
b7d81290
authored
May 19, 2012
by
Davis King
Browse files
Added the ability to learn only non-negative weights to the svm_c_linear_trainer.
parent
2f562b03
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
1 deletion
+44
-1
dlib/svm/svm_c_linear_trainer.h
dlib/svm/svm_c_linear_trainer.h
+21
-1
dlib/svm/svm_c_linear_trainer_abstract.h
dlib/svm/svm_c_linear_trainer_abstract.h
+23
-0
No files found.
dlib/svm/svm_c_linear_trainer.h
View file @
b7d81290
...
@@ -352,6 +352,7 @@ namespace dlib
...
@@ -352,6 +352,7 @@ namespace dlib
verbose
=
false
;
verbose
=
false
;
eps
=
0.001
;
eps
=
0.001
;
max_iterations
=
10000
;
max_iterations
=
10000
;
learn_nonnegative_weights
=
false
;
}
}
explicit
svm_c_linear_trainer
(
explicit
svm_c_linear_trainer
(
...
@@ -371,6 +372,7 @@ namespace dlib
...
@@ -371,6 +372,7 @@ namespace dlib
verbose
=
false
;
verbose
=
false
;
eps
=
0.001
;
eps
=
0.001
;
max_iterations
=
10000
;
max_iterations
=
10000
;
learn_nonnegative_weights
=
false
;
}
}
void
set_epsilon
(
void
set_epsilon
(
...
@@ -432,6 +434,16 @@ namespace dlib
...
@@ -432,6 +434,16 @@ namespace dlib
return
kernel_type
();
return
kernel_type
();
}
}
bool
learns_nonnegative_weights
(
)
const
{
return
learn_nonnegative_weights
;
}
void
set_learns_nonnegative_weights
(
bool
value
)
{
learn_nonnegative_weights
=
value
;
}
void
set_c
(
void
set_c
(
scalar_type
C
scalar_type
C
)
)
...
@@ -544,9 +556,16 @@ namespace dlib
...
@@ -544,9 +556,16 @@ namespace dlib
typedef
matrix
<
scalar_type
,
0
,
1
>
w_type
;
typedef
matrix
<
scalar_type
,
0
,
1
>
w_type
;
w_type
w
;
w_type
w
;
unsigned
long
num_nonnegative
=
0
;
if
(
learn_nonnegative_weights
)
{
num_nonnegative
=
max_index_plus_one
(
x
);
}
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
);
// 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
;
...
@@ -570,6 +589,7 @@ namespace dlib
...
@@ -570,6 +589,7 @@ namespace dlib
scalar_type
eps
;
scalar_type
eps
;
bool
verbose
;
bool
verbose
;
unsigned
long
max_iterations
;
unsigned
long
max_iterations
;
bool
learn_nonnegative_weights
;
};
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/svm/svm_c_linear_trainer_abstract.h
View file @
b7d81290
...
@@ -52,6 +52,7 @@ namespace dlib
...
@@ -52,6 +52,7 @@ namespace dlib
- #get_epsilon() == 0.001
- #get_epsilon() == 0.001
- 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
!*/
!*/
explicit
svm_c_linear_trainer
(
explicit
svm_c_linear_trainer
(
...
@@ -69,6 +70,7 @@ namespace dlib
...
@@ -69,6 +70,7 @@ namespace dlib
- #get_epsilon() == 0.001
- #get_epsilon() == 0.001
- 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
!*/
!*/
void
set_epsilon
(
void
set_epsilon
(
...
@@ -145,6 +147,27 @@ namespace dlib
...
@@ -145,6 +147,27 @@ namespace dlib
returns kernel_type()
returns kernel_type()
!*/
!*/
bool
learns_nonnegative_weights
(
)
const
;
/*!
ensures
- The output of training is a weight vector and a bias value. These
two things define the resulting decision function. That is, the
decision function simply takes the dot product between the learned
weight vector and a test sample, then subtracts the bias value.
Therefore, if learns_nonnegative_weights() == true then the resulting
learned weight vector will always have non-negative entries. The
bias value may still be negative though.
!*/
void
set_learns_nonnegative_weights
(
bool
value
);
/*!
ensures
- #learns_nonnegative_weights() == value
!*/
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