Skip to content
Snippets Groups Projects
Commit 346cbaca authored by Baptiste Bauvin's avatar Baptiste Bauvin
Browse files

Added difficulty measure

parent 7dc49250
Branches
Tags
No related merge requests found
import numpy as np
from .. import diversity_utils
def genName(config):
return "DifficultyFusion"
def getBenchmark(benchmark, args=None):
benchmark["Multiview"]["DifficultyFusion"] = ["take_everything"]
return benchmark
def difficulty(classifiersDecisions, combination, foldsGroudTruth, foldsLen):
nbView, _, nbFolds, nbExamples = classifiersDecisions.shape
scores = np.zeros((nbView, nbFolds, nbExamples), dtype=int)
for viewIndex, classifierIndex in enumerate(combination):
scores[viewIndex] = np.logical_not(
np.logical_xor(classifiersDecisions[viewIndex, classifierIndex],
foldsGroudTruth)
)
difficulty_scores = np.sum(scores, axis=0)
difficulty_score = np.mean(
np.var(
np.array([
np.sum((difficulty_scores==viewIndex), axis=1)
for viewIndex in range(len(combination))])
, axis=0)
)
return difficulty_score
def getArgs(args, benchmark, views, viewsIndices, randomState, directory, resultsMonoview, classificationIndices):
return diversity_utils.getArgs(args, benchmark, views,
viewsIndices, randomState, directory,
resultsMonoview, classificationIndices,
difficulty, "DifficultyFusion")
def genParamsSets(classificationKWARGS, randomState, nIter=1):
return diversity_utils.genParamsSets(classificationKWARGS, randomState, nIter=nIter)
class DifficultyFusionClass(diversity_utils.DiversityFusionClass):
def __init__(self, randomState, NB_CORES=1, **kwargs):
diversity_utils.DiversityFusionClass.__init__(self, randomState, NB_CORES=1, **kwargs)
def getSpecificAnalysis(self, classificationKWARGS):
stringAnalysis = "Classifiers used for each view : "+ ', '.join(self.classifiersNames)+\
', with a difficulty of '+str(self.div_measure)
return stringAnalysis
\ No newline at end of file
from . import DifficultyFusionModule, analyzeResults
\ No newline at end of file
from ...Multiview import analyzeResults
# Author-Info
__author__ = "Baptiste Bauvin"
__status__ = "Prototype" # Production, Development, Prototype
def execute(classifier, trainLabels,
testLabels, DATASET,
classificationKWARGS, classificationIndices,
LABELS_DICTIONARY, views, nbCores, times,
name, KFolds,
hyperParamSearch, nIter, metrics,
viewsIndices, randomState, labels, classifierModule):
return analyzeResults.execute(classifier, trainLabels,
testLabels, DATASET,
classificationKWARGS, classificationIndices,
LABELS_DICTIONARY, views, nbCores, times,
name, KFolds,
hyperParamSearch, nIter, metrics,
viewsIndices, randomState, labels, classifierModule)
\ No newline at end of file
import unittest
import numpy as np
from ....MonoMultiViewClassifiers.MultiviewClassifiers.DifficultyFusion import DifficultyFusionModule
class Test_difficulty(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.classifiersDecisions = np.array([
[np.random.random_integers(0, 1, (2, 5)), [[0, 0, 1, 0, 1], [0, 1, 0, 1, 0]],
np.random.random_integers(0, 1, (2, 5)), np.random.random_integers(0, 1, (2, 5)),
np.random.random_integers(0, 1, (2, 5))],
[np.random.random_integers(0, 1, (2, 5)), np.random.random_integers(0, 1, (2, 5)),
np.random.random_integers(0, 1, (2, 5)), [[0, 0, 1, 1, 0], [0, 1, 0, 1, 0]],
np.random.random_integers(0, 1, (2, 5))],
[np.random.random_integers(0, 1, (2, 5)), np.random.random_integers(0, 1, (2, 5)),
np.random.random_integers(0, 1, (2, 5)), np.random.random_integers(0, 1, (2, 5)),
[[0, 1, 1, 1, 1], [0, 1, 0, 1, 0]]],
])
cls.combination = [1, 3, 4]
cls.foldsGroudTruth = np.array([[1, 1, 0, 0, 1], [0, 1, 0, 1, 0]])
cls.foldsLen = ""
def test_simple(cls):
difficulty_measure = DifficultyFusionModule.difficulty(cls.classifiersDecisions,
cls.combination,
cls.foldsGroudTruth,
cls.foldsLen)
cls.assertAlmostEqual(difficulty_measure, 0.11111111111)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment