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
bd9a80e9
Commit
bd9a80e9
authored
9 years ago
by
Baptiste Bauvin
Browse files
Options
Downloads
Patches
Plain Diff
Some bug correction
parent
2f357080
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Raw Code/Fusion/EarlyFusion.py
+0
-1
0 additions, 1 deletion
Raw Code/Fusion/EarlyFusion.py
Raw Code/Fusion/LateFusion.py
+27
-26
27 additions, 26 deletions
Raw Code/Fusion/LateFusion.py
with
27 additions
and
27 deletions
Raw Code/Fusion/EarlyFusion.py
+
0
−
1
View file @
bd9a80e9
...
...
@@ -2,7 +2,6 @@
# -*- encoding: utf-8
import
numpy
as
np
from
sklearn.ensemble
import
VotingClassifier
# TODO :
# Linear Weighted Fusion
...
...
This diff is collapsed.
Click to expand it.
Raw Code/Fusion/LateFusion.py
+
27
−
26
View file @
bd9a80e9
...
...
@@ -10,31 +10,34 @@ from sklearn.svm import SVC
# able to compute a score for each class in each mono-view classification
#
d
ecisions : (nbExample * nbFeature * NB_CLASS) array with the OVO/OVA scores for each
#
monoViewD
ecisions : (nbExample * nbFeature * NB_CLASS) array with the OVO/OVA scores for each
# example, feature and each class
# weights : (nbFeature) array with the weights for each feature
def
weightedLinear
(
d
ecisions
,
weights
):
def
weightedLinear
(
monoViewD
ecisions
,
weights
):
# Normalize weights ?
# weights = weights/float(max(weights))
fusedExamples
=
np
.
array
([
sum
(
np
.
array
([
featureScores
*
weight
for
weight
,
featureScores
\
in
zip
(
weights
,
exampleDecisions
)]))
for
exampleDecisions
in
d
ecisions
])
in
zip
(
weights
,
exampleDecisions
)]))
for
exampleDecisions
in
monoViewD
ecisions
])
# print fused
return
np
.
array
([
np
.
argmax
(
fusedExample
)
for
fusedExample
in
fusedExamples
])
# The SVMClassifier is here used to find the right weights for linearfusion
def
SVMForLinearFusionTrain
(
d
ecisions
,
labels
):
def
SVMForLinearFusionTrain
(
monoViewD
ecisions
,
labels
):
SVMClassifier
=
SVC
()
SVMClassifier
.
fit
(
d
ecisions
,
labels
)
SVMClassifier
.
fit
(
monoViewD
ecisions
,
labels
)
return
SVMClassifier
def
SVMForLinearFusionFuse
(
decisions
,
SVMClassifier
):
labels
=
SVMClassifier
.
predict
(
decisions
)
def
SVMForLinearFusionFuse
(
monoViewDecisions
,
SVMClassifier
):
labels
=
SVMClassifier
.
predict
(
monoViewDecisions
)
return
labels
...
...
@@ -42,11 +45,11 @@ def SVMForLinearFusionFuse(decisions, SVMClassifier):
# For majority voting, we have a problem : we have 5 fetures and 101 classes
# on Calthech, so if each feature votes for one class, we can't find a good
# result
def
majorityVoting
(
d
ecisions
,
NB_CLASS
):
nbExample
=
len
(
d
ecisions
)
votes
=
np
.
array
([
np
.
zeros
(
NB_CLASS
)
for
example
in
d
ecisions
])
def
majorityVoting
(
monoViewD
ecisions
,
NB_CLASS
):
nbExample
=
len
(
monoViewD
ecisions
)
votes
=
np
.
array
([
np
.
zeros
(
NB_CLASS
)
for
example
in
monoViewD
ecisions
])
for
exampleIndice
in
range
(
nbExample
):
for
featureClassification
in
d
ecisions
[
exampleIndice
]:
for
featureClassification
in
monoViewD
ecisions
[
exampleIndice
]:
votes
[
exampleIndice
,
featureClassification
]
+=
1
nbMaximum
=
len
(
np
.
where
(
votes
[
exampleIndice
]
==
max
(
votes
[
exampleIndice
]))[
0
])
try
:
...
...
@@ -54,14 +57,12 @@ def majorityVoting(decisions, NB_CLASS):
except
:
print
"
Majority voting can
'
t decide, each classifier has voted for a different class
"
raise
# Can be upgraded by restarting a new classification process if
# there are multiple maximums ?:
# while nbMaximum>1:
# relearn with only the classes that have a maximum number of vote
# votes = revote
# nbMaximum = len(np.where(votes==max(votes))[0])
return
np
.
array
([
np
.
argmax
(
exampleVotes
)
for
exampleVotes
in
votes
])
...
...
@@ -76,30 +77,30 @@ if __name__ == '__main__':
LABELS
=
np
.
array
([
TRUE_CLASS
for
i
in
range
(
DATASET_LENGTH
)])
LABELS
[
0
]
=
0
d
ecisionsEasy
=
np
.
array
([
np
.
array
([
np
.
zeros
(
NB_CLASS
)
for
i
in
range
(
nbFeature
)])
for
example
in
range
(
DATASET_LENGTH
)])
for
exampleDecisions
in
d
ecisionsEasy
:
monoViewD
ecisionsEasy
=
np
.
array
([
np
.
array
([
np
.
zeros
(
NB_CLASS
)
for
i
in
range
(
nbFeature
)])
for
example
in
range
(
DATASET_LENGTH
)])
for
exampleDecisions
in
monoViewD
ecisionsEasy
:
for
decision
in
exampleDecisions
:
decision
[
TRUE_CLASS
]
=
12
# print
d
ecisionsEasy
# print
monoViewD
ecisionsEasy
d
ecisionsHard
=
np
.
array
([
np
.
array
([
np
.
zeros
(
NB_CLASS
)
for
i
in
range
(
nbFeature
)])
for
example
in
range
(
DATASET_LENGTH
)])
for
exampleDecisions
in
d
ecisionsHard
:
monoViewD
ecisionsHard
=
np
.
array
([
np
.
array
([
np
.
zeros
(
NB_CLASS
)
for
i
in
range
(
nbFeature
)])
for
example
in
range
(
DATASET_LENGTH
)])
for
exampleDecisions
in
monoViewD
ecisionsHard
:
for
decision
in
exampleDecisions
:
decision
[
TRUE_CLASS
]
=
12
exampleDecisions
[
nbFeature
-
2
]
=
np
.
zeros
(
NB_CLASS
)
+
1400
exampleDecisions
[
nbFeature
-
2
][
TRUE_CLASS
]
-=
110
d
ecisionsMajority
=
np
.
array
([
np
.
array
([
TRUE_CLASS
,
TRUE_CLASS
,
TRUE_CLASS
,
1
,
5
])
for
example
in
range
(
DATASET_LENGTH
)])
d
ecisionsMajorityFail
=
np
.
array
([
np
.
array
([
1
,
2
,
3
,
4
,
5
])
for
example
in
range
(
DATASET_LENGTH
)])
monoViewD
ecisionsMajority
=
np
.
array
([
np
.
array
([
TRUE_CLASS
,
TRUE_CLASS
,
TRUE_CLASS
,
1
,
5
])
for
example
in
range
(
DATASET_LENGTH
)])
monoViewD
ecisionsMajorityFail
=
np
.
array
([
np
.
array
([
1
,
2
,
3
,
4
,
5
])
for
example
in
range
(
DATASET_LENGTH
)])
weights
=
np
.
random
.
rand
(
nbFeature
)
weights
[
nbFeature
-
2
]
=
2
SVMClassifier
=
SVMForLinearFusionTrain
(
d
ecisionsMajority
,
LABELS
)
SVMClassifier
=
SVMForLinearFusionTrain
(
monoViewD
ecisionsMajority
,
LABELS
)
print
weightedLinear
(
d
ecisionsEasy
,
weights
)
print
weightedLinear
(
d
ecisionsHard
,
weights
)
print
SVMForLinearFusionFuse
(
d
ecisionsMajority
,
SVMClassifier
)
print
majorityVoting
(
d
ecisionsMajority
,
NB_CLASS
)
print
majorityVoting
(
d
ecisionsMajorityFail
,
NB_CLASS
)
print
weightedLinear
(
monoViewD
ecisionsEasy
,
weights
)
print
weightedLinear
(
monoViewD
ecisionsHard
,
weights
)
print
SVMForLinearFusionFuse
(
monoViewD
ecisionsMajority
,
SVMClassifier
)
print
majorityVoting
(
monoViewD
ecisionsMajority
,
NB_CLASS
)
print
majorityVoting
(
monoViewD
ecisionsMajorityFail
,
NB_CLASS
)
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