diff --git a/multiview_platform/MonoMultiViewClassifiers/ExecClassif.py b/multiview_platform/MonoMultiViewClassifiers/ExecClassif.py index 8c73ab9aadb2c8da300010435788e8d82bcc7ef7..fb3c7605d8938b7bc27c439cdc484f8ec35206c0 100644 --- a/multiview_platform/MonoMultiViewClassifiers/ExecClassif.py +++ b/multiview_platform/MonoMultiViewClassifiers/ExecClassif.py @@ -558,12 +558,7 @@ def execBenchmark(nbCores, statsIter, nbMulticlass, for arguments in benchmarkArgumentsDictionaries: results += [execOneBenchmarkMonoCore(DATASET=DATASET, **arguments)] logging.debug("Done:\t Executing all the needed biclass benchmarks") - if nbCores > 1: - logging.debug("Start:\t Deleting " + str( - nbCores) + " temporary datasets for multiprocessing") - args = benchmarkArgumentsDictionaries[0]["args"] - datasetFiles = delete(args.pathF, args.name, nbCores) - logging.debug("Start:\t Deleting datasets for multiprocessing") + # Do everything with flagging nbExamples = len(classificationIndices[0][0]) + len( classificationIndices[0][1]) @@ -573,10 +568,7 @@ def execBenchmark(nbCores, statsIter, nbMulticlass, multiclassGroundTruth, metrics, classificationIndices, directories, directory, labelsDictionary, nbExamples, nbLabels) logging.debug("Done:\t Analyzing predictions") - filename = DATASET.filename - DATASET.close() - if "_temp_" in filename: - os.remove(filename) + delete(benchmarkArgumentsDictionaries, nbCores, DATASET) return results_mean_stds diff --git a/multiview_platform/MonoMultiViewClassifiers/utils/GetMultiviewDb.py b/multiview_platform/MonoMultiViewClassifiers/utils/GetMultiviewDb.py index 52a9c21c4adc9a9094d5362fdb60edbbe2c308b1..c0e1a6b0e30d30d70cb6108c6f5a146e935a9d2a 100644 --- a/multiview_platform/MonoMultiViewClassifiers/utils/GetMultiviewDb.py +++ b/multiview_platform/MonoMultiViewClassifiers/utils/GetMultiviewDb.py @@ -1,5 +1,6 @@ import errno import os +import logging import h5py import numpy as np @@ -58,10 +59,20 @@ def datasetsAlreadyExist(pathF, name, nbCores): return allDatasetExist -def deleteHDF5(pathF, name, nbCores): +def deleteHDF5(benchmarkArgumentsDictionaries, nbCores, DATASET): """Used to delete temporary copies at the end of the benchmark""" - for coreIndex in range(nbCores): - os.remove(pathF + name + str(coreIndex) + ".hdf5") + if nbCores > 1: + logging.debug("Start:\t Deleting " + str( + nbCores) + " temporary datasets for multiprocessing") + args = benchmarkArgumentsDictionaries[0]["args"] + logging.debug("Start:\t Deleting datasets for multiprocessing") + + for coreIndex in range(nbCores): + os.remove(args.pathF + args.name + str(coreIndex) + ".hdf5") + filename = DATASET.filename + DATASET.close() + if "_temp_" in filename: + os.remove(filename) def makeMeNoisy(viewData, randomState, percentage=15): @@ -484,11 +495,11 @@ def getClassicDBcsv(views, pathF, nameDB, NB_CLASS, askedLabelsNames, metaDataGrp.attrs["nbClass"] = len(labelsNames) metaDataGrp.attrs["datasetLength"] = len(labels) datasetFile.close() - datasetFile, labelsDictionary = getClassicDBhdf5(views, pathF, nameDB, + datasetFile, labelsDictionary, dataset_name = getClassicDBhdf5(views, pathF, nameDB, NB_CLASS, askedLabelsNames, randomState, full) - return datasetFile, labelsDictionary + return datasetFile, labelsDictionary, dataset_name # def getLabelSupports(CLASS_LABELS): # """Used to get the number of example for each label""" diff --git a/multiview_platform/Tests/Test_MultiviewClassifiers/Test_DisagreeFusion/test_DisagreeFusionModule.py b/multiview_platform/Tests/Test_MultiviewClassifiers/Test_DisagreeFusion/test_DisagreeFusionModule.py index 1a32682b29f54a4de95651d56891f4b8918ebebf..16b809f78e39ca987e65b945f04789965d628fe9 100644 --- a/multiview_platform/Tests/Test_MultiviewClassifiers/Test_DisagreeFusion/test_DisagreeFusionModule.py +++ b/multiview_platform/Tests/Test_MultiviewClassifiers/Test_DisagreeFusion/test_DisagreeFusionModule.py @@ -6,150 +6,50 @@ from multiview_platform.MonoMultiViewClassifiers.Multiview.Additions import \ diversity_utils from ....MonoMultiViewClassifiers.MultiviewClassifiers.DisagreeFusion import \ DisagreeFusionModule - +from multiview_platform.MonoMultiViewClassifiers.Multiview.MultiviewUtils import MultiviewResult class Test_disagreement(unittest.TestCase): @classmethod def setUpClass(cls): cls.randomState = np.random.RandomState(42) - cls.allClassifiersNames = ["SCM", "SVM", "DT"] - cls.directory = "" + cls.allClassifiersNames = [["SCM", "SVM", "DT"], ["SCM", "SVM", "DT"]] cls.viewsIndices = np.array([0, 1]) - cls.resultsMonoview = np.array([[0, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]] - ]) + cls.classifiersDecisions = np.zeros((cls.viewsIndices.shape[0], len(cls.allClassifiersNames), 3, 6), + dtype=int) + for classifer_index, classifier in enumerate(cls.allClassifiersNames): + for view_index, view in enumerate(cls.viewsIndices): + cls.classifiersDecisions[view_index, classifer_index] = np.array([ + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6)]) + cls.folds_ground_truth = np.array([np.array([1,1,1,0,0,0]) for _ in range(3)]) cls.classificationIndices = np.array([]) def test_simple(cls): bestCombi, disagreement = diversity_utils.couple_div_measure( - cls.allClassifiersNames, cls.viewsIndices, cls.resultsMonoview, - DisagreeFusionModule.disagree) + cls.allClassifiersNames, cls.classifiersDecisions, DisagreeFusionModule.disagree, cls.folds_ground_truth) cls.assertAlmostEqual(disagreement, 0.666666666667) cls.assertEqual(len(bestCombi), 2) - def test_viewsIndices(cls): - cls.viewsIndices = np.array([0, 6]) - cls.resultsMonoview =np.array( [[0, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]] - ]) - bestCombi, disagreement = diversity_utils.couple_div_measure( - cls.allClassifiersNames, cls.viewsIndices, - cls.resultsMonoview, DisagreeFusionModule.disagree) - cls.assertAlmostEqual(disagreement, 0.611111111111) - cls.assertEqual(len(bestCombi), 2) - def test_multipleViews(cls): cls.viewsIndices = np.array([0, 6, 18]) - cls.resultsMonoview = np.array([[0, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [18, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, - 6)]) - ]], - [18, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, - 6)]) - ]], - [18, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, - 6)]) - ]] - ]) + cls.allClassifiersNames = [["SCM", "SVM", "DT"], ["SCM", "SVM", "DT"], ["SCM", "SVM", "DT"]] + cls.classifiersDecisions = np.zeros( + (cls.viewsIndices.shape[0], len(cls.allClassifiersNames), 3, 6), + dtype=int) + for classifer_index, classifier in enumerate(cls.allClassifiersNames): + for view_index, view in enumerate(cls.viewsIndices): + cls.classifiersDecisions[ + view_index, classifer_index] = np.array([ + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6)]) + bestCombi, disagreement = diversity_utils.couple_div_measure( - cls.allClassifiersNames, cls.viewsIndices, - cls.resultsMonoview, DisagreeFusionModule.disagree) - cls.assertAlmostEqual(disagreement, 0.592592592593) + cls.allClassifiersNames, cls.classifiersDecisions, + DisagreeFusionModule.disagree, cls.folds_ground_truth) + cls.assertAlmostEqual(disagreement, 0.55555555555555) cls.assertEqual(len(bestCombi), 3) diff --git a/multiview_platform/Tests/Test_MultiviewClassifiers/Test_DoubleFaultFusion/test_DoubleFaultFusionModule.py b/multiview_platform/Tests/Test_MultiviewClassifiers/Test_DoubleFaultFusion/test_DoubleFaultFusionModule.py index 7267f3087a0c40e54f31e9c045644750e17ab2ed..ab7b9d31a43334cb24db5a186ff850f22f062b14 100644 --- a/multiview_platform/Tests/Test_MultiviewClassifiers/Test_DoubleFaultFusion/test_DoubleFaultFusionModule.py +++ b/multiview_platform/Tests/Test_MultiviewClassifiers/Test_DoubleFaultFusion/test_DoubleFaultFusionModule.py @@ -13,148 +13,45 @@ class Test_doubleFaultRatio(unittest.TestCase): @classmethod def setUpClass(cls): cls.randomState = np.random.RandomState(42) - cls.allClassifiersNames = ["SCM", "SVM", "DT"] + cls.allClassifiersNames = [["SCM", "SVM", "DT"], ["SCM", "SVM", "DT"]] cls.directory = "" - cls.viewsIndices = [0, 1] - cls.resultsMonoview = [[0, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]] - ] - cls.classificationIndices = [] - cls.ground_truth = np.array([1, 1, 1, 0, 0, 0]) + cls.viewsIndices = np.array([0, 1]) + cls.classifiersDecisions = np.zeros( + (cls.viewsIndices.shape[0], len(cls.allClassifiersNames), 3, 6), + dtype=int) + for classifer_index, classifier in enumerate(cls.allClassifiersNames): + for view_index, view in enumerate(cls.viewsIndices): + cls.classifiersDecisions[ + view_index, classifer_index] = np.array([ + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6)]) + cls.folds_ground_truth = np.array([np.array([1,1,1,0,0,0]) for _ in range(3)]) def test_simple(cls): bestCombi, disagreement = diversity_utils.couple_div_measure( - cls.allClassifiersNames, cls.viewsIndices, - cls.resultsMonoview, - DoubleFaultFusionModule.doubleFault, - cls.ground_truth) - cls.assertAlmostEqual(disagreement, 0.55555555555555547) - cls.assertEqual(len(bestCombi), 2) - - def test_viewsIndices(cls): - cls.viewsIndices = [0, 6] - cls.resultsMonoview = [[0, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]] - ] - bestCombi, disagreement = diversity_utils.couple_div_measure( - cls.allClassifiersNames, cls.viewsIndices, - cls.resultsMonoview, DoubleFaultFusionModule.doubleFault, - cls.ground_truth) - cls.assertAlmostEqual(disagreement, 0.33333333333333331) + cls.allClassifiersNames,cls.classifiersDecisions, + DoubleFaultFusionModule.doubleFault, cls.folds_ground_truth) + cls.assertAlmostEqual(disagreement, 0.3888888888888) cls.assertEqual(len(bestCombi), 2) def test_multipleViews(cls): - cls.viewsIndices = [0, 6, 18] - cls.resultsMonoview = [[0, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [6, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [18, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, - 6)]) - ]], - [18, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, - 6)]) - ]], - [18, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, - 6)]) - ]] - ] + cls.viewsIndices = np.array([0, 6, 18]) + cls.allClassifiersNames = [["SCM", "SVM", "DT"], ["SCM", "SVM", "DT"], ["SCM", "SVM", "DT"]] + cls.classifiersDecisions = np.zeros( + (cls.viewsIndices.shape[0], len(cls.allClassifiersNames), 3, 6), + dtype=int) + for classifer_index, classifier in enumerate(cls.allClassifiersNames): + for view_index, view in enumerate(cls.viewsIndices): + cls.classifiersDecisions[ + view_index, classifer_index] = np.array([ + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6)]) bestCombi, disagreement = diversity_utils.couple_div_measure( - cls.allClassifiersNames, cls.viewsIndices, - cls.resultsMonoview, DoubleFaultFusionModule.doubleFault, - cls.ground_truth) - cls.assertAlmostEqual(disagreement, 0.31481481481481483) + cls.allClassifiersNames, cls.classifiersDecisions, + DoubleFaultFusionModule.doubleFault, cls.folds_ground_truth) + cls.assertAlmostEqual(disagreement, 0.3333333333) cls.assertEqual(len(bestCombi), 3) diff --git a/multiview_platform/Tests/Test_MultiviewClassifiers/test_diversity_utils.py b/multiview_platform/Tests/Test_MultiviewClassifiers/test_diversity_utils.py index a8e8149c4665b6b74cb266910e18485a46eab1d8..ea1c0bd88608d0e06a4fe2adc98b77bb20c9931f 100644 --- a/multiview_platform/Tests/Test_MultiviewClassifiers/test_diversity_utils.py +++ b/multiview_platform/Tests/Test_MultiviewClassifiers/test_diversity_utils.py @@ -14,50 +14,29 @@ class Test_global_div_measure(unittest.TestCase): @classmethod def setUpClass(cls): - cls.allClassifersNames = ["SCM", "DT", "SVM"] - cls.viewsIndices = [0, 1] cls.randomState = np.random.RandomState(42) - cls.resultsMonoview = np.array([[0, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [0, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["SCM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["SVM", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]], - [1, ["DT", "", "", "", "", "", - np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) - ]] - ]) + cls.allClassifiersNames = [["SCM", "SVM", "DT"], ["SCM", "SVM", "DT"]] + cls.viewsIndices = np.array([0, 1]) + cls.classifiersDecisions = np.zeros( + (cls.viewsIndices.shape[0], len(cls.allClassifiersNames), 3, 6), + dtype=int) + for classifer_index, classifier in enumerate(cls.allClassifiersNames): + for view_index, view in enumerate(cls.viewsIndices): + cls.classifiersDecisions[ + view_index, classifer_index] = np.array([ + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6), + cls.randomState.randint(0, 2, 6)]) + cls.folds_ground_truth = np.array( + [np.array([1, 1, 1, 0, 0, 0]) for _ in range(3)]) + cls.classificationIndices = np.array([]) cls.measurement = fake_measure - cls.foldsGroudTruth = np.array([cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6), - cls.randomState.randint(0, 2, 6)]) def test_simple(cls): clf_names, diversity_measure = diversity_utils.global_div_measure( - cls.allClassifersNames, - cls.resultsMonoview, + cls.allClassifiersNames, + cls.classifiersDecisions, cls.measurement, - cls.foldsGroudTruth)#cls.viewsIndices, + cls.folds_ground_truth) cls.assertEqual(len(clf_names), 2) cls.assertEqual(diversity_measure, 42) diff --git a/multiview_platform/Tests/Test_utils/test_GetMultiviewDB.py b/multiview_platform/Tests/Test_utils/test_GetMultiviewDB.py index 111cb76273ff616f5b678cb00500c13eb68d4ca6..4f344d0ad3ae3baf04e1c128127482aa0f82c0be 100644 --- a/multiview_platform/Tests/Test_utils/test_GetMultiviewDB.py +++ b/multiview_platform/Tests/Test_utils/test_GetMultiviewDB.py @@ -363,7 +363,7 @@ class Test_getClassicDBhdf5(unittest.TestCase): cls.dataset.attrs["name"] = "test_view_" + str(i) def test_simple(cls): - dataset_file, labels_dictionary = GetMultiviewDb.getClassicDBhdf5( + dataset_file, labels_dictionary, dataset_name = GetMultiviewDb.getClassicDBhdf5( cls.views, cls.pathF, cls.nameDB, cls.NB_CLASS, cls.askedLabelsNames, cls.random_state) @@ -381,10 +381,11 @@ class Test_getClassicDBhdf5(unittest.TestCase): askedLabelsNames = ["test_label_0", "test_label_1", "test_label_2", "test_label_3"] NB_CLASS = 4 - dataset_file, labels_dictionary = GetMultiviewDb.getClassicDBhdf5( + dataset_file, labels_dictionary, dataset_name = GetMultiviewDb.getClassicDBhdf5( cls.views, cls.pathF, cls.nameDB, NB_CLASS, askedLabelsNames, cls.random_state) + cls.assertEqual(dataset_name, 'test_dataset_temp_view_label_select') cls.assertEqual(dataset_file.get("View1").attrs["name"], "test_view_3") cls.assertEqual(labels_dictionary, {0: "test_label_0", 1: "test_label_1", @@ -397,7 +398,7 @@ class Test_getClassicDBhdf5(unittest.TestCase): def test_all_views_asked(cls): views = ["test_view_0", "test_view_1", "test_view_2", "test_view_3"] - dataset_file, labels_dictionary = GetMultiviewDb.getClassicDBhdf5(views, + dataset_file, labels_dictionary, dataset_name = GetMultiviewDb.getClassicDBhdf5(views, cls.pathF, cls.nameDB, cls.NB_CLASS, @@ -422,7 +423,7 @@ class Test_getClassicDBhdf5(unittest.TestCase): "test_label_3"] NB_CLASS = 4 views = ["test_view_0", "test_view_1", "test_view_2", "test_view_3"] - dataset_file, labels_dictionary = GetMultiviewDb.getClassicDBhdf5(views, + dataset_file, labels_dictionary, dataset_name = GetMultiviewDb.getClassicDBhdf5(views, cls.pathF, cls.nameDB, NB_CLASS, @@ -480,7 +481,7 @@ class Test_getClassicDBcsv(unittest.TestCase): cls.datas.append(data) def test_simple(cls): - dataset_file, labels_dictionary = GetMultiviewDb.getClassicDBcsv( + dataset_file, labels_dictionary, dataset_name = GetMultiviewDb.getClassicDBcsv( cls.views, cls.pathF, cls.nameDB, cls.NB_CLASS, cls.askedLabelsNames, cls.random_state, delimiter=",") @@ -496,7 +497,7 @@ class Test_getClassicDBcsv(unittest.TestCase): def test_all_views_asked(cls): views = ["test_view_0", "test_view_1", "test_view_2", "test_view_3"] - dataset_file, labels_dictionary = GetMultiviewDb.getClassicDBcsv(views, + dataset_file, labels_dictionary, dataset_name = GetMultiviewDb.getClassicDBcsv(views, cls.pathF, cls.nameDB, cls.NB_CLASS, @@ -508,6 +509,7 @@ class Test_getClassicDBcsv(unittest.TestCase): cls.assertEqual(dataset_file.get("Metadata").attrs["datasetLength"], 3) cls.assertEqual(dataset_file.get("Metadata").attrs["nbView"], 4) cls.assertEqual(dataset_file.get("Metadata").attrs["nbClass"], 2) + cls.assertEqual(dataset_name,'test_dataset_temp_view_label_select') for viewIndex in range(4): np.testing.assert_array_equal( dataset_file.get("View" + str(viewIndex)).value, @@ -520,7 +522,7 @@ class Test_getClassicDBcsv(unittest.TestCase): askedLabelsNames = ["test_label_0", "test_label_1", "test_label_2", "test_label_3"] NB_CLASS = 4 - dataset_file, labels_dictionary = GetMultiviewDb.getClassicDBcsv( + dataset_file, labels_dictionary, dataset_name = GetMultiviewDb.getClassicDBcsv( cls.views, cls.pathF, cls.nameDB, NB_CLASS, askedLabelsNames, cls.random_state, delimiter=",") @@ -539,7 +541,7 @@ class Test_getClassicDBcsv(unittest.TestCase): "test_label_3"] NB_CLASS = 4 views = ["test_view_0", "test_view_1", "test_view_2", "test_view_3"] - dataset_file, labels_dictionary = GetMultiviewDb.getClassicDBcsv(views, + dataset_file, labels_dictionary, dataset_name = GetMultiviewDb.getClassicDBcsv(views, cls.pathF, cls.nameDB, NB_CLASS, diff --git a/multiview_platform/Tests/test_ExecClassif.py b/multiview_platform/Tests/test_ExecClassif.py index 5d7bccb97c914dacba001129e849913ab341f20d..c9e6416adb0dd54ebb7794b3609ad90939d957d7 100644 --- a/multiview_platform/Tests/test_ExecClassif.py +++ b/multiview_platform/Tests/test_ExecClassif.py @@ -77,7 +77,7 @@ class Test_execBenchmark(unittest.TestCase): execOneBenchmarkMonoCore=fakeBenchmarkExec_monocore, getResults=fakegetResults, delete=fakeDelete) - cls.assertEqual(res, [[4]]) + cls.assertEqual(res, 3) def test_multiclass_no_iter(cls): cls.argumentDictionaries = [{"a": 10, "args": FakeArg()}, @@ -90,7 +90,7 @@ class Test_execBenchmark(unittest.TestCase): execOneBenchmarkMonoCore=fakeBenchmarkExec_monocore, getResults=fakegetResults, delete=fakeDelete) - cls.assertEqual(res, [[0, 10], [1, 4]]) + cls.assertEqual(res, 3) def test_multiclass_and_iter(cls): cls.argumentDictionaries = [{"a": 10, "args": FakeArg()}, @@ -105,7 +105,7 @@ class Test_execBenchmark(unittest.TestCase): execOneBenchmarkMonoCore=fakeBenchmarkExec_monocore, getResults=fakegetResults, delete=fakeDelete) - cls.assertEqual(res, [[0, 10], [1, 4], [0, 55], [1, 24]]) + cls.assertEqual(res, 3) def test_no_iter_biclass_multicore(cls): res = ExecClassif.execBenchmark(2, 1, 1, cls.argumentDictionaries, @@ -116,10 +116,11 @@ class Test_execBenchmark(unittest.TestCase): execOneBenchmarkMonoCore=fakeBenchmarkExec_monocore, getResults=fakegetResults, delete=fakeDelete) - cls.assertEqual(res, [[2, 4]]) + cls.assertEqual(res, 3) @classmethod def tearDownClass(cls): + cls.Dataset.close() os.remove("multiview_platform/Tests/tmp_tests/test_file.hdf5") os.rmdir("multiview_platform/Tests/tmp_tests") @@ -168,7 +169,7 @@ class Test_execOneBenchmark(unittest.TestCase): os.mkdir("multiview_platform/Tests/tmp_tests") def test_simple(cls): - flag, resMono, resMulti = ExecClassif.execOneBenchmark(coreIndex=10, + flag, results = ExecClassif.execOneBenchmark(coreIndex=10, LABELS_DICTIONARY={ 0: "a", 1: "b"}, @@ -201,10 +202,9 @@ class Test_execOneBenchmark(unittest.TestCase): initMultiviewArguments=fakeInitMulti) cls.assertEqual(flag, None) - cls.assertEqual(resMono, - [["Mono", {"try": 0}], ["Mono", {"try2": 100}]]) - cls.assertEqual(resMulti, - [["Multi", {"try3": 5}], ["Multi", {"try4": 10}]]) + cls.assertEqual(results , + [['Mono', {'try': 0}], ['Mono', {'try2': 100}], + ['Multi', {'try3': 5}], ['Multi', {'try4': 10}]]) @classmethod def tearDownClass(cls): @@ -225,7 +225,7 @@ class Test_execOneBenchmark_multicore(unittest.TestCase): os.mkdir("multiview_platform/Tests/tmp_tests") def test_simple(cls): - flag, resMono, resMulti = ExecClassif.execOneBenchmark_multicore( + flag, results = ExecClassif.execOneBenchmark_multicore( nbCores=2, LABELS_DICTIONARY={0: "a", 1: "b"}, directory="multiview_platform/Tests/tmp_tests/", @@ -246,10 +246,9 @@ class Test_execOneBenchmark_multicore(unittest.TestCase): initMultiviewArguments=fakeInitMulti) cls.assertEqual(flag, None) - cls.assertEqual(resMono, - [["Mono", {"try": 0}], ["Mono", {"try2": 100}]]) - cls.assertEqual(resMulti, - [["Multi", {"try3": 5}], ["Multi", {"try4": 10}]]) + cls.assertEqual(results , + [['Mono', {'try': 0}], ['Mono', {'try2': 100}], + ['Multi', {'try3': 5}], ['Multi', {'try4': 10}]]) @classmethod def tearDownClass(cls):