Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Supervised MultiModal Integration Tool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Baptiste Bauvin
Supervised MultiModal Integration Tool
Commits
eb09b02f
Commit
eb09b02f
authored
6 years ago
by
Baptiste Bauvin
Browse files
Options
Downloads
Patches
Plain Diff
Corrected Qarboost
parent
0738a1da
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
multiview_platform/MonoMultiViewClassifiers/Monoview/Additions/QarBoostUtils.py
+25
-4
25 additions, 4 deletions
...oMultiViewClassifiers/Monoview/Additions/QarBoostUtils.py
with
25 additions
and
4 deletions
multiview_platform/MonoMultiViewClassifiers/Monoview/Additions/QarBoostUtils.py
+
25
−
4
View file @
eb09b02f
...
@@ -13,7 +13,9 @@ from .BoostUtils import StumpsClassifiersGenerator, sign, BaseBoost
...
@@ -13,7 +13,9 @@ from .BoostUtils import StumpsClassifiersGenerator, sign, BaseBoost
class
ColumnGenerationClassifierQar
(
BaseEstimator
,
ClassifierMixin
,
BaseBoost
):
class
ColumnGenerationClassifierQar
(
BaseEstimator
,
ClassifierMixin
,
BaseBoost
):
def
__init__
(
self
,
n_max_iterations
=
None
,
estimators_generator
=
None
,
dual_constraint_rhs
=
0
,
save_iteration_as_hyperparameter_each
=
None
,
random_state
=
42
,
self_complemented
=
True
,
twice_the_same
=
False
):
def
__init__
(
self
,
n_max_iterations
=
None
,
estimators_generator
=
None
,
dual_constraint_rhs
=
0
,
save_iteration_as_hyperparameter_each
=
None
,
random_state
=
42
,
self_complemented
=
True
,
twice_the_same
=
False
,
old_fashioned
=
False
):
super
(
ColumnGenerationClassifierQar
,
self
).
__init__
()
super
(
ColumnGenerationClassifierQar
,
self
).
__init__
()
self
.
n_max_iterations
=
n_max_iterations
self
.
n_max_iterations
=
n_max_iterations
self
.
estimators_generator
=
estimators_generator
self
.
estimators_generator
=
estimators_generator
...
@@ -23,6 +25,7 @@ class ColumnGenerationClassifierQar(BaseEstimator, ClassifierMixin, BaseBoost):
...
@@ -23,6 +25,7 @@ class ColumnGenerationClassifierQar(BaseEstimator, ClassifierMixin, BaseBoost):
self
.
self_complemented
=
self_complemented
self
.
self_complemented
=
self_complemented
self
.
twice_the_same
=
twice_the_same
self
.
twice_the_same
=
twice_the_same
self
.
train_time
=
0
self
.
train_time
=
0
self
.
old_fashioned
=
old_fashioned
def
fit
(
self
,
X
,
y
):
def
fit
(
self
,
X
,
y
):
start
=
time
.
time
()
start
=
time
.
time
()
...
@@ -143,11 +146,32 @@ class ColumnGenerationClassifierQar(BaseEstimator, ClassifierMixin, BaseBoost):
...
@@ -143,11 +146,32 @@ class ColumnGenerationClassifierQar(BaseEstimator, ClassifierMixin, BaseBoost):
def
_compute_epsilon
(
self
,):
def
_compute_epsilon
(
self
,):
"""
Updating the \epsilon varaible
"""
"""
Updating the \epsilon varaible
"""
if
self
.
old_fashioned
:
return
self
.
_compute_epsilon_old
()
ones_matrix
=
np
.
zeros
(
self
.
new_voter
.
shape
)
ones_matrix
[
self
.
new_voter
<
0
]
=
1
epsilon
=
(
1.0
/
self
.
n_total_examples
)
*
np
.
sum
(
self
.
example_weights
*
ones_matrix
,
axis
=
0
)
return
epsilon
def
_update_example_weights
(
self
,
y
):
if
self
.
old_fashioned
:
self
.
_update_example_weights
(
y
)
else
:
new_weights
=
self
.
example_weights
*
np
.
exp
(
-
self
.
q
*
y
.
reshape
((
self
.
n_total_examples
,
1
))
*
self
.
new_voter
)
self
.
example_weights
=
new_weights
/
np
.
sum
(
new_weights
)
def
_compute_epsilon_old
(
self
,):
"""
Updating the \epsilon varaible computed on the combination of the old vote and the new voter
"""
ones_matrix
=
np
.
zeros
(
self
.
weighted_sum
.
shape
)
ones_matrix
=
np
.
zeros
(
self
.
weighted_sum
.
shape
)
ones_matrix
[
self
.
weighted_sum
<
0
]
=
1
ones_matrix
[
self
.
weighted_sum
<
0
]
=
1
epsilon
=
(
1.0
/
self
.
n_total_examples
)
*
np
.
sum
(
self
.
example_weights
*
ones_matrix
,
axis
=
0
)
epsilon
=
(
1.0
/
self
.
n_total_examples
)
*
np
.
sum
(
self
.
example_weights
*
ones_matrix
,
axis
=
0
)
return
epsilon
return
epsilon
def
_update_example_weights_old
(
self
,
y
):
"""
computed on the combination of the old vote and the new voter
"""
new_weights
=
self
.
example_weights
*
np
.
exp
(
-
self
.
q
*
y
.
reshape
((
self
.
n_total_examples
,
1
))
*
self
.
weighted_sum
)
self
.
example_weights
=
new_weights
/
np
.
sum
(
new_weights
)
def
_find_best_margin
(
self
,
y_kernel_matrix
):
def
_find_best_margin
(
self
,
y_kernel_matrix
):
"""
Used only on the first iteration to select the voter with the largest margin
"""
"""
Used only on the first iteration to select the voter with the largest margin
"""
pseudo_h_values
=
ma
.
array
(
np
.
sum
(
y_kernel_matrix
,
axis
=
0
),
fill_value
=-
np
.
inf
)
pseudo_h_values
=
ma
.
array
(
np
.
sum
(
y_kernel_matrix
,
axis
=
0
),
fill_value
=-
np
.
inf
)
...
@@ -179,9 +203,6 @@ class ColumnGenerationClassifierQar(BaseEstimator, ClassifierMixin, BaseBoost):
...
@@ -179,9 +203,6 @@ class ColumnGenerationClassifierQar(BaseEstimator, ClassifierMixin, BaseBoost):
else
:
else
:
return
"
break
"
,
"
smthng
"
return
"
break
"
,
"
smthng
"
def
_update_example_weights
(
self
,
y
):
new_weights
=
self
.
example_weights
*
np
.
exp
(
-
self
.
q
*
y
.
reshape
((
self
.
n_total_examples
,
1
))
*
self
.
weighted_sum
)
self
.
example_weights
=
new_weights
/
np
.
sum
(
new_weights
)
def
_solve_two_weights_min_c
(
self
,
next_column
,
y
):
def
_solve_two_weights_min_c
(
self
,
next_column
,
y
):
"""
Here we solve the min C-bound problem for two voters and return the best 2-weights array
"""
Here we solve the min C-bound problem for two voters and return the best 2-weights array
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment