diff --git a/multiview_platform/execute.py b/multiview_platform/execute.py index a142cb88fa45fb4f904bb71a97295b50f02195a5..39ca74f1c40b776e34354f56deeb4359b9837f16 100644 --- a/multiview_platform/execute.py +++ b/multiview_platform/execute.py @@ -1,6 +1,5 @@ """This is the execution module, used to execute the code""" - def exec(): import multiview_platform.versions as versions versions.test_versions() diff --git a/multiview_platform/mono_multi_view_classifiers/exec_classif.py b/multiview_platform/mono_multi_view_classifiers/exec_classif.py index 93c6f75964a477927c51adb142251d107d476e53..6bf02eb49a9d33196092600dea846cb1fffe8894 100644 --- a/multiview_platform/mono_multi_view_classifiers/exec_classif.py +++ b/multiview_platform/mono_multi_view_classifiers/exec_classif.py @@ -458,7 +458,7 @@ def exec_one_benchmark(core_index=-1, labels_dictionary=None, directory=None, classification_indices, k_folds, core_index, args["Base"]["type"], args["Base"]["pathf"], random_state, labels, - hyperParamSearch=hyper_param_search, + hyper_param_search=hyper_param_search, metrics=metrics, nIter=args["Classification"]["hps_iter"], **argument) for argument in argument_dictionaries["Monoview"]] diff --git a/multiview_platform/mono_multi_view_classifiers/monoview/exec_classif_mono_view.py b/multiview_platform/mono_multi_view_classifiers/monoview/exec_classif_mono_view.py index 5c807f3ac3523e21b9b17ec7c91b5112385fa564..c61d5d12c2602d46917cf864756921b52a914ec7 100644 --- a/multiview_platform/mono_multi_view_classifiers/monoview/exec_classif_mono_view.py +++ b/multiview_platform/mono_multi_view_classifiers/monoview/exec_classif_mono_view.py @@ -30,22 +30,22 @@ __status__ = "Prototype" # Production, Development, Prototype def exec_monoview_multicore(directory, name, labelsNames, classificationIndices, KFolds, datasetFileIndex, databaseType, path, randomState, labels, - hyperParamSearch="randomizedSearch", + hyper_param_search="randomized_search", metrics=[["accuracy_score", None]], nIter=30, **args): DATASET = h5py.File(path + name + str(datasetFileIndex) + ".hdf5", "r") neededViewIndex = args["viewIndex"] X = DATASET.get("View" + str(neededViewIndex)) Y = labels - return ExecMonoview(directory, X, Y, name, labelsNames, + return exec_monoview(directory, X, Y, name, labelsNames, classificationIndices, KFolds, 1, databaseType, path, - randomState, hyperParamSearch=hyperParamSearch, + randomState, hyper_param_search=hyper_param_search, metrics=metrics, nIter=nIter, **args) def exec_monoview(directory, X, Y, name, labelsNames, classificationIndices, KFolds, nbCores, databaseType, path, - randomState, hyperParamSearch="randomizedSearch", + randomState, hyper_param_search="randomized_search", metrics=[["accuracy_score", None]], nIter=30, **args): logging.debug("Start:\t Loading data") kwargs, \ @@ -67,7 +67,7 @@ def exec_monoview(directory, X, Y, name, labelsNames, classificationIndices, + str(nbCores) + ", algorithm : " + CL_type) logging.debug("Start:\t Determine Train/Test split") - X_train, y_train, X_test, y_test, X_test_multiclass = initTrainTest(X, Y, + X_train, y_train, X_test, y_test, X_test_multiclass = init_train_test(X, Y, classificationIndices) logging.debug("Info:\t Shape X_train:" + str( @@ -79,7 +79,7 @@ def exec_monoview(directory, X, Y, name, labelsNames, classificationIndices, logging.debug("Start:\t Generate classifier args") classifierModule = getattr(monoview_classifiers, CL_type) classifier_class_name = classifierModule.classifier_class_name - clKWARGS, testFoldsPreds = getHPs(classifierModule, hyperParamSearch, + clKWARGS, testFoldsPreds = getHPs(classifierModule, hyper_parameter_search, nIter, CL_type, classifier_class_name, X_train, y_train, randomState, outputFileName, @@ -114,7 +114,7 @@ def exec_monoview(directory, X, Y, name, labelsNames, classificationIndices, stringAnalysis, \ imagesAnalysis, \ metricsScores = execute(name, classificationIndices, KFolds, nbCores, - hyperParamSearch, metrics, nIter, feat, CL_type, + hyper_parameter_search, metrics, nIter, feat, CL_type, clKWARGS, labelsNames, X.shape, y_train, y_train_pred, y_test, y_test_pred, t_end, randomState, classifier, outputFileName) diff --git a/multiview_platform/mono_multi_view_classifiers/multiview/additions/diversity_utils.py b/multiview_platform/mono_multi_view_classifiers/multiview/additions/diversity_utils.py index 977730184b0f502af77fe4d0025e37d869eddccd..9cf1ba574b9acfe3e0374a67313704f9bf1fe3e5 100644 --- a/multiview_platform/mono_multi_view_classifiers/multiview/additions/diversity_utils.py +++ b/multiview_platform/mono_multi_view_classifiers/multiview/additions/diversity_utils.py @@ -4,7 +4,7 @@ import os import numpy as np -from ...utils.multiclass import isBiclass, genMulticlassMonoviewDecision +from ...utils.multiclass import is_biclass, gen_multiclass_monoview_decision def getClassifiersDecisions(allClassifersNames, viewsIndices, resultsMonoview): diff --git a/multiview_platform/mono_multi_view_classifiers/multiview/exec_multiview.py b/multiview_platform/mono_multi_view_classifiers/multiview/exec_multiview.py index 696c97e5cafd44e82d78bebbd9dd71d21d3405d8..fdbf358cf8ce67aa8fe7b9377c0bee89c3aaa43b 100644 --- a/multiview_platform/mono_multi_view_classifiers/multiview/exec_multiview.py +++ b/multiview_platform/mono_multi_view_classifiers/multiview/exec_multiview.py @@ -80,21 +80,21 @@ def saveResults(classifier, LABELS_DICTIONARY, stringAnalysis, views, classifier def exec_multiview_multicore(directory, coreIndex, name, learningRate, nbFolds, databaseType, path, LABELS_DICTIONARY, randomState, labels, - hyperParamSearch=False, nbCores=1, metrics=None, + hyper_param_search=False, nbCores=1, metrics=None, nIter=30, **arguments): """Used to load an HDF5 dataset for each parallel job and execute multiview classification""" DATASET = h5py.File(path + name + str(coreIndex) + ".hdf5", "r") - return ExecMultiview(directory, DATASET, name, learningRate, nbFolds, 1, + return exec_multiview(directory, DATASET, name, learningRate, nbFolds, 1, databaseType, path, LABELS_DICTIONARY, randomState, labels, - hyperParamSearch=hyperParamSearch, metrics=metrics, + hyper_param_search=hyper_param_search, metrics=metrics, nIter=nIter, **arguments) def exec_multiview(directory, DATASET, name, classificationIndices, KFolds, - nbCores, databaseType, path, - LABELS_DICTIONARY, randomState, labels, - hyperParamSearch=False, metrics=None, nIter=30, **kwargs): + nbCores, databaseType, path, + LABELS_DICTIONARY, randomState, labels, + hyper_param_search=False, metrics=None, nIter=30, **kwargs): """Used to execute multiview classification and result analysis""" logging.debug("Start:\t Initialize constants") CL_type, \ @@ -122,20 +122,20 @@ def exec_multiview(directory, DATASET, name, classificationIndices, KFolds, logging.debug("Done:\t Getting classifiers modules") logging.debug("Start:\t Optimizing hyperparameters") - if hyperParamSearch != "None": + if hyper_param_search != "None": classifier_config = hyper_parameter_search.searchBestSettings(DATASET, labels, - classifier_module, - classifier_name, - metrics[0], - learningIndices, - KFolds, - randomState, - directory, - nb_cores=nbCores, - viewsIndices=viewsIndices, - searchingTool=hyperParamSearch, - n_iter=nIter, - classifier_config=classifier_config) + classifier_module, + classifier_name, + metrics[0], + learningIndices, + KFolds, + randomState, + directory, + nb_cores=nbCores, + viewsIndices=viewsIndices, + searchingTool=hyper_param_search, + n_iter=nIter, + classifier_config=classifier_config) classifier = getattr(classifier_module, classifier_name)(randomState, **classifier_config) @@ -177,7 +177,7 @@ def exec_multiview(directory, DATASET, name, classificationIndices, KFolds, classifier_config, classificationIndices, LABELS_DICTIONARY, views, nbCores, times, name, KFolds, - hyperParamSearch, nIter, metrics, + hyper_param_search, nIter, metrics, viewsIndices, randomState, labels, classifier_module) logging.info("Done:\t Result Analysis for " + CL_type) @@ -283,7 +283,7 @@ if __name__ == "__main__": if args.log: logging.getLogger().addHandler(logging.StreamHandler()) - res = ExecMultiview(directory, DATASET, name, classificationIndices, KFolds, + res = exec_multiview(directory, DATASET, name, classificationIndices, KFolds, nbCores, databaseType, path, LABELS_DICTIONARY, randomState, labels, hyperParamSearch=hyperParamSearch, metrics=metrics, diff --git a/multiview_platform/mono_multi_view_classifiers/utils/execution.py b/multiview_platform/mono_multi_view_classifiers/utils/execution.py index e5bfe258bccf5dc9dfd36c6c7ce43c6590ca0418..65cfae5df01a3b73045243d38e6f6533150fe871 100644 --- a/multiview_platform/mono_multi_view_classifiers/utils/execution.py +++ b/multiview_platform/mono_multi_view_classifiers/utils/execution.py @@ -108,10 +108,10 @@ def get_database_function(name, type_var): getDatabase : function The function that will be used to extract the database """ - if name not in ["Fake", "Plausible"]: - get_database = getattr(DB, "getClassicDB" + type_var[1:]) + if name not in ["fake", "plausible"]: + get_database = getattr(DB, "get_classic_db_" + type_var[1:]) else: - get_database = getattr(DB, "get" + name + "DB" + type_var[1:]) + get_database = getattr(DB, "get_" + name + "_db_" + type_var[1:]) return get_database diff --git a/multiview_platform/mono_multi_view_classifiers/utils/get_multiview_db.py b/multiview_platform/mono_multi_view_classifiers/utils/get_multiview_db.py index 0d86492787e2e290fc5d351ec446ada1c49c1049..e83eff45eb9a41b258fb71fec8a813c914155860 100644 --- a/multiview_platform/mono_multi_view_classifiers/utils/get_multiview_db.py +++ b/multiview_platform/mono_multi_view_classifiers/utils/get_multiview_db.py @@ -90,7 +90,7 @@ def makeMeNoisy(viewData, randomState, percentage=5): return noisyViewData -def getPlausibleDBhdf5(features, pathF, name, NB_CLASS=3, LABELS_NAME="", +def get_plausible_db_hdf5(features, pathF, name, NB_CLASS=3, LABELS_NAME="", randomState=None, full=True, add_noise=False, noise_std=0.15, nbView=3, nbClass=2, datasetLength=100, randomStateInt=42, nbFeatures = 10): @@ -380,7 +380,7 @@ def copyhdf5_dataset(source_data_file, destination_data_file, source_dataset_nam new_d_set.attrs[key] = value -def get_classicDBhdf5(views, path_f, name_DB, nb_class, asked_labels_names, +def get_classic_db_hdf5(views, path_f, name_DB, nb_class, asked_labels_names, random_state, full=False, add_noise=False, noise_std=0.15,): """Used to load a hdf5 database""" if full: @@ -467,7 +467,7 @@ def add_gaussian_noise(dataset_file, random_state, path_f, dataset_name, return noisy_dataset, dataset_name + "_noised" -def getClassicDBcsv(views, pathF, nameDB, NB_CLASS, askedLabelsNames, +def get_classic_db_csv(views, pathF, nameDB, NB_CLASS, askedLabelsNames, randomState, full=False, add_noise=False, noise_std=0.15, delimiter=","): # TODO : Update this one @@ -497,7 +497,7 @@ def getClassicDBcsv(views, pathF, nameDB, NB_CLASS, askedLabelsNames, metaDataGrp.attrs["nbClass"] = len(labelsNames) metaDataGrp.attrs["datasetLength"] = len(labels) datasetFile.close() - datasetFile, labelsDictionary, dataset_name = getClassicDBhdf5(views, pathF, nameDB, + datasetFile, labelsDictionary, dataset_name = get_classic_db_hdf5(views, pathF, nameDB, NB_CLASS, askedLabelsNames, randomState, full) diff --git a/multiview_platform/tests/test_ExecClassif.py b/multiview_platform/tests/test_ExecClassif.py index 07ba4ecc0dce6ad16f6924625072b273bc5dd53c..ea295dbf36a30be1358582a5ff15d4a1f12a94df 100644 --- a/multiview_platform/tests/test_ExecClassif.py +++ b/multiview_platform/tests/test_ExecClassif.py @@ -20,7 +20,7 @@ class Test_initKWARGS(unittest.TestCase): def test_initKWARGSFunc_no_monoview(self): benchmark = {"monoview": {}, "multiview": {}} - args = exec_classif.initKWARGSFunc({}, benchmark) + args = exec_classif.init_kwargs_func({}, benchmark) self.assertEqual(args, {"monoview": {}, "multiview": {}}) @@ -205,15 +205,15 @@ class Test_init_argument_dictionaries(unittest.TestCase): self.assertEqual(arguments["multiview"][0], expected_output[0]) -def fakeBenchmarkExec(coreIndex=-1, a=7, args=1): - return [coreIndex, a] +def fakeBenchmarkExec(core_index=-1, a=7, args=1): + return [core_index, a] -def fakeBenchmarkExec_mutlicore(nbCores=-1, a=6, args=1): - return [nbCores, a] +def fakeBenchmarkExec_mutlicore(nb_cores=-1, a=6, args=1): + return [nb_cores, a] -def fakeBenchmarkExec_monocore(DATASET=1, a=4, args=1): +def fakeBenchmarkExec_monocore(dataset_var=1, a=4, args=1): return [a] @@ -247,10 +247,10 @@ class Test_execBenchmark(unittest.TestCase): res = exec_classif.exec_benchmark(1, 2, 3, cls.argumentDictionaries, [[[1, 2], [3, 4, 5]]], 5, 6, 7, 8, 9, 10, cls.Dataset, - execOneBenchmark=fakeBenchmarkExec, - execOneBenchmark_multicore=fakeBenchmarkExec_mutlicore, - execOneBenchmarkMonoCore=fakeBenchmarkExec_monocore, - getResults=fakegetResults, + exec_one_benchmark=fakeBenchmarkExec, + exec_one_benchmark_multicore=fakeBenchmarkExec_mutlicore, + exec_one_benchmark_mono_core=fakeBenchmarkExec_monocore, + get_results=fakegetResults, delete=fakeDelete) cls.assertEqual(res, 3) @@ -260,10 +260,10 @@ class Test_execBenchmark(unittest.TestCase): res = exec_classif.exec_benchmark(2, 1, 2, cls.argumentDictionaries, [[[1, 2], [3, 4, 5]]], 5, 6, 7, 8, 9, 10, cls.Dataset, - execOneBenchmark=fakeBenchmarkExec, - execOneBenchmark_multicore=fakeBenchmarkExec_mutlicore, - execOneBenchmarkMonoCore=fakeBenchmarkExec_monocore, - getResults=fakegetResults, + exec_one_benchmark=fakeBenchmarkExec, + exec_one_benchmark_multicore=fakeBenchmarkExec_mutlicore, + exec_one_benchmark_mono_core=fakeBenchmarkExec_monocore, + get_results=fakegetResults, delete=fakeDelete) cls.assertEqual(res, 3) @@ -275,10 +275,10 @@ class Test_execBenchmark(unittest.TestCase): res = exec_classif.exec_benchmark(2, 2, 2, cls.argumentDictionaries, [[[1, 2], [3, 4, 5]]], 5, 6, 7, 8, 9, 10, cls.Dataset, - execOneBenchmark=fakeBenchmarkExec, - execOneBenchmark_multicore=fakeBenchmarkExec_mutlicore, - execOneBenchmarkMonoCore=fakeBenchmarkExec_monocore, - getResults=fakegetResults, + exec_one_benchmark=fakeBenchmarkExec, + exec_one_benchmark_multicore=fakeBenchmarkExec_mutlicore, + exec_one_benchmark_mono_core=fakeBenchmarkExec_monocore, + get_results=fakegetResults, delete=fakeDelete) cls.assertEqual(res, 3) @@ -286,10 +286,10 @@ class Test_execBenchmark(unittest.TestCase): res = exec_classif.exec_benchmark(2, 1, 1, cls.argumentDictionaries, [[[1, 2], [3, 4, 5]]], 5, 6, 7, 8, 9, 10, cls.Dataset, - execOneBenchmark=fakeBenchmarkExec, - execOneBenchmark_multicore=fakeBenchmarkExec_mutlicore, - execOneBenchmarkMonoCore=fakeBenchmarkExec_monocore, - getResults=fakegetResults, + exec_one_benchmark=fakeBenchmarkExec, + exec_one_benchmark_multicore=fakeBenchmarkExec_mutlicore, + exec_one_benchmark_mono_core=fakeBenchmarkExec_monocore, + get_results=fakegetResults, delete=fakeDelete) cls.assertEqual(res, 3) @@ -304,13 +304,13 @@ class Test_execBenchmark(unittest.TestCase): def fakeExecMono(directory, name, labelsNames, classificationIndices, kFolds, coreIndex, type, pathF, randomState, labels, - hyperParamSearch="try", metrics="try", nIter=1, **arguments): + hyper_param_search="try", metrics="try", nIter=1, **arguments): return ["Mono", arguments] def fakeExecMulti(directory, coreIndex, name, classificationIndices, kFolds, type, pathF, LABELS_DICTIONARY, - randomState, labels, hyperParamSearch="", metrics=None, + randomState, labels, hyper_param_search="", metrics=None, nIter=1, **arguments): return ["Multi", arguments] @@ -344,20 +344,20 @@ class Test_execOneBenchmark(unittest.TestCase): "Classification": {"hps_iter": 1}} def test_simple(cls): - flag, results = exec_classif.execOneBenchmark(coreIndex=10, - LABELS_DICTIONARY={ + flag, results = exec_classif.exec_one_benchmark(core_index=10, + labels_dictionary={ 0: "a", 1: "b"}, directory="multiview_platform/tests/tmp_tests/", - classificationIndices=( + classification_indices=( [1, 2, 3, 4], [0, 5, 6, 7, 8]), args=cls.args, - kFolds=FakeKfold(), - randomState="try", - hyperParamSearch="try", + k_folds=FakeKfold(), + random_state="try", + hyper_param_search="try", metrics="try", - argumentDictionaries={ + argument_dictionaries={ "Monoview": [ { "try": 0}, @@ -369,16 +369,16 @@ class Test_execOneBenchmark(unittest.TestCase): "try4": 10}]}, benchmark="try", views="try", - viewsIndices="try", + views_indices="try", flag=None, labels=np.array( [0, 1, 2, 1, 2, 2, 2, 12, 1, 2, 1, 1, 2, 1, 21]), - ExecMonoview_multicore=fakeExecMono, + exec_monoview_multicore=fakeExecMono, exec_multiview_multicore=fakeExecMulti, - initMultiviewArguments=fakeInitMulti) + init_multiview_arguments=fakeInitMulti) cls.assertEqual(flag, None) cls.assertEqual(results , @@ -411,17 +411,17 @@ class Test_execOneBenchmark_multicore(unittest.TestCase): "Classification": {"hps_iter": 1}} def test_simple(cls): - flag, results = exec_classif.execOneBenchmark_multicore( - nbCores=2, - LABELS_DICTIONARY={0: "a", 1: "b"}, + flag, results = exec_classif.exec_one_benchmark_multicore( + nb_cores=2, + labels_dictionary={0: "a", 1: "b"}, directory="multiview_platform/tests/tmp_tests/", - classificationIndices=([1, 2, 3, 4], [0, 10, 20, 30, 40]), + classification_indices=([1, 2, 3, 4], [0, 10, 20, 30, 40]), args=cls.args, - kFolds=FakeKfold(), - randomState="try", - hyperParamSearch="try", + k_folds=FakeKfold(), + random_state="try", + hyper_param_search="try", metrics="try", - argumentDictionaries={ + argument_dictionaries={ "monoview": [ { "try": 0}, @@ -436,9 +436,9 @@ class Test_execOneBenchmark_multicore(unittest.TestCase): viewsIndices="try", flag=None, labels=np.array([0, 1, 2, 3, 4, 2, 2, 12, 1, 2, 1, 1, 2, 1, 21]), - ExecMonoview_multicore=fakeExecMono, + exec_monoview_multicore=fakeExecMono, exec_multiview_multicore=fakeExecMulti, - initMultiviewArguments=fakeInitMulti) + init_multiview_arguments=fakeInitMulti) cls.assertEqual(flag, None) cls.assertEqual(results , diff --git a/multiview_platform/tests/test_mono_view/test_ExecClassifMonoView.py b/multiview_platform/tests/test_mono_view/test_ExecClassifMonoView.py index c5e70b74c7aadddf7b7d93bef5030e2911d1f647..43dcefa76126d59820490abff5a642a48a6eb63a 100644 --- a/multiview_platform/tests/test_mono_view/test_ExecClassifMonoView.py +++ b/multiview_platform/tests/test_mono_view/test_ExecClassifMonoView.py @@ -77,7 +77,7 @@ class Test_initTrainTest(unittest.TestCase): np.array([1, 3, 5, 7, 9])] def test_simple(cls): - X_train, y_train, X_test, y_test, X_test_multiclass = exec_classif_mono_view.initTrainTest( + X_train, y_train, X_test, y_test, X_test_multiclass = exec_classif_mono_view.init_train_test( cls.X, cls.Y, cls.classificationIndices) np.testing.assert_array_equal(X_train, np.array( [np.array([102, 435, 348, 270, 106]), diff --git a/multiview_platform/tests/test_utils/test_GetMultiviewDB.py b/multiview_platform/tests/test_utils/test_GetMultiviewDB.py index e59ce5fbc419a28643dff535be8fb6d1347a49bc..c97e04d02afcd366943b4eceeed3c6a7312077f8 100644 --- a/multiview_platform/tests/test_utils/test_GetMultiviewDB.py +++ b/multiview_platform/tests/test_utils/test_GetMultiviewDB.py @@ -22,7 +22,7 @@ class Test_copyhdf5Dataset(unittest.TestCase): cls.dataset.attrs["test_arg"] = "Am I copied" def test_simple_copy(cls): - get_multiview_db.copyhdf5Dataset(cls.dataset_file, cls.dataset_file, + get_multiview_db.copyhdf5_dataset(cls.dataset_file, cls.dataset_file, "test", "test_copy_1", np.arange(10)) np.testing.assert_array_equal(cls.dataset_file.get("test").value, cls.dataset_file.get("test_copy_1").value) @@ -31,7 +31,7 @@ class Test_copyhdf5Dataset(unittest.TestCase): def test_copy_only_some_indices(cls): usedIndices = cls.random_state.choice(10, 6, replace=False) - get_multiview_db.copyhdf5Dataset(cls.dataset_file, cls.dataset_file, + get_multiview_db.copyhdf5_dataset(cls.dataset_file, cls.dataset_file, "test", "test_copy", usedIndices) np.testing.assert_array_equal( cls.dataset_file.get("test").value[usedIndices, :], @@ -68,7 +68,7 @@ class Test_filterViews(unittest.TestCase): cls.temp_dataset_file = h5py.File( "multiview_platform/tests/temp_tests/test_copy_temp.hdf5", "w") cls.dataset_file.copy("Metadata", cls.temp_dataset_file) - get_multiview_db.filterViews(cls.dataset_file, cls.temp_dataset_file, + get_multiview_db.filter_views(cls.dataset_file, cls.temp_dataset_file, cls.views, np.arange(10)) cls.assertEqual(cls.dataset_file.get("View1").attrs["name"], cls.temp_dataset_file.get("View0").attrs["name"]) @@ -82,7 +82,7 @@ class Test_filterViews(unittest.TestCase): "multiview_platform/tests/temp_tests/test_copy_temp.hdf5", "w") cls.dataset_file.copy("Metadata", cls.temp_dataset_file) usedIndices = cls.random_state.choice(10, 6, replace=False) - get_multiview_db.filterViews(cls.dataset_file, cls.temp_dataset_file, + get_multiview_db.filter_views(cls.dataset_file, cls.temp_dataset_file, cls.views, usedIndices) np.testing.assert_array_equal( cls.dataset_file.get("View1").value[usedIndices, :], @@ -112,7 +112,7 @@ class Test_filterLabels(unittest.TestCase): def test_simple(cls): newLabels, \ newLabelsNames, \ - usedIndices = get_multiview_db.filterLabels(cls.labelsSet, + usedIndices = get_multiview_db.filter_labels(cls.labelsSet, cls.askedLabelsNamesSet, cls.fullLabels, cls.availableLabelsNames, @@ -127,7 +127,7 @@ class Test_filterLabels(unittest.TestCase): cls.availableLabelsNames = ["test_label_0", "test_label_1"] newLabels, \ newLabelsNames, \ - usedIndices = get_multiview_db.filterLabels(cls.labelsSet, + usedIndices = get_multiview_db.filter_labels(cls.labelsSet, cls.askedLabelsNamesSet, cls.fullLabels, cls.availableLabelsNames, @@ -141,7 +141,7 @@ class Test_filterLabels(unittest.TestCase): "test_label_2", "test_label_3", "chicken_is_heaven"} with cls.assertRaises(get_multiview_db.DatasetError) as catcher: - get_multiview_db.filterLabels(cls.labelsSet, + get_multiview_db.filter_labels(cls.labelsSet, cls.askedLabelsNamesSet, cls.fullLabels, cls.availableLabelsNames, @@ -155,7 +155,7 @@ class Test_filterLabels(unittest.TestCase): "test_label_3"] newLabels, \ newLabelsNames, \ - usedIndices = get_multiview_db.filterLabels(cls.labelsSet, + usedIndices = get_multiview_db.filter_labels(cls.labelsSet, cls.askedLabelsNamesSet, cls.fullLabels, cls.availableLabelsNames, @@ -179,7 +179,7 @@ class Test_selectAskedLabels(unittest.TestCase): def test_simple(cls): newLabels, \ newLabelsNames, \ - usedIndices = get_multiview_db.selectAskedLabels(cls.askedLabelsNamesSet, + usedIndices = get_multiview_db.select_asked_labels(cls.askedLabelsNamesSet, cls.availableLabelsNames, cls.askedLabelsNames, cls.fullLabels) @@ -194,7 +194,7 @@ class Test_selectAskedLabels(unittest.TestCase): "test_label_3"] newLabels, \ newLabelsNames, \ - usedIndices = get_multiview_db.selectAskedLabels(cls.askedLabelsNamesSet, + usedIndices = get_multiview_db.select_asked_labels(cls.askedLabelsNamesSet, cls.availableLabelsNames, cls.askedLabelsNames, cls.fullLabels) @@ -206,7 +206,7 @@ class Test_selectAskedLabels(unittest.TestCase): cls.askedLabelsNamesSet = {"test_label_1", "test_label_3", "chicken_is_heaven"} with cls.assertRaises(get_multiview_db.DatasetError) as catcher: - get_multiview_db.selectAskedLabels(cls.askedLabelsNamesSet, + get_multiview_db.select_asked_labels(cls.askedLabelsNamesSet, cls.availableLabelsNames, cls.askedLabelsNames, cls.fullLabels) @@ -224,7 +224,7 @@ class Test_getAllLabels(unittest.TestCase): "test_label_2", "test_label_3"] def test_simple(cls): - newLabels, newLabelsNames, usedIndices = get_multiview_db.getAllLabels( + newLabels, newLabelsNames, usedIndices = get_multiview_db.get_all_labels( cls.fullLabels, cls.availableLabelsNames) cls.assertEqual(cls.availableLabelsNames, newLabelsNames) np.testing.assert_array_equal(usedIndices, np.arange(10)) @@ -241,7 +241,7 @@ class Test_fillLabelNames(unittest.TestCase): cls.availableLabelsNames = ["test_label_" + str(_) for _ in range(40)] def test_simple(cls): - askedLabelsNames, askedLabelsNamesSet = get_multiview_db.fillLabelNames( + askedLabelsNames, askedLabelsNamesSet = get_multiview_db.fill_label_names( cls.NB_CLASS, cls.askedLabelsNames, cls.randomState, @@ -251,7 +251,7 @@ class Test_fillLabelNames(unittest.TestCase): def test_missing_labels_names(cls): cls.NB_CLASS = 39 - askedLabelsNames, askedLabelsNamesSet = get_multiview_db.fillLabelNames( + askedLabelsNames, askedLabelsNamesSet = get_multiview_db.fill_label_names( cls.NB_CLASS, cls.askedLabelsNames, cls.randomState, @@ -279,7 +279,7 @@ class Test_fillLabelNames(unittest.TestCase): cls.NB_CLASS = 2 cls.askedLabelsNames = ["test_label_1", "test_label_3", "test_label_4", "test_label_6"] - askedLabelsNames, askedLabelsNamesSet = get_multiview_db.fillLabelNames( + askedLabelsNames, askedLabelsNamesSet = get_multiview_db.fill_label_names( cls.NB_CLASS, cls.askedLabelsNames, cls.randomState, @@ -298,14 +298,14 @@ class Test_allAskedLabelsAreAvailable(unittest.TestCase): def test_asked_available_labels(cls): cls.assertTrue( - get_multiview_db.allAskedLabelsAreAvailable(cls.askedLabelsNamesSet, + get_multiview_db.all_asked_labels_are_available(cls.askedLabelsNamesSet, cls.availableLabelsNames)) def test_asked_unavailable_label(cls): cls.askedLabelsNamesSet = {"test_label_1", "test_label_3", "chicken_is_heaven"} cls.assertFalse( - get_multiview_db.allAskedLabelsAreAvailable(cls.askedLabelsNamesSet, + get_multiview_db.all_asked_labels_are_available(cls.askedLabelsNamesSet, cls.availableLabelsNames)) @@ -316,18 +316,18 @@ class Test_getClasses(unittest.TestCase): cls.random_state = np.random.RandomState(42) def test_multiclass(cls): - labelsSet = get_multiview_db.getClasses( + labelsSet = get_multiview_db.get_classes( cls.random_state.randint(0, 5, 30)) cls.assertEqual(labelsSet, {0, 1, 2, 3, 4}) def test_biclass(cls): - labelsSet = get_multiview_db.getClasses( + labelsSet = get_multiview_db.get_classes( cls.random_state.randint(0, 2, 30)) cls.assertEqual(labelsSet, {0, 1}) def test_one_class(cls): with cls.assertRaises(get_multiview_db.DatasetError) as catcher: - get_multiview_db.getClasses(np.zeros(30, dtype=int)) + get_multiview_db.get_classes(np.zeros(30, dtype=int)) exception = catcher.exception # cls.assertTrue("Dataset must have at least two different labels" in exception) @@ -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, dataset_name = get_multiview_db.getClassicDBhdf5( + dataset_file, labels_dictionary, dataset_name = get_multiview_db.get_classic_db_hdf5( cls.views, cls.pathF, cls.nameDB, cls.NB_CLASS, cls.askedLabelsNames, cls.random_state) @@ -381,7 +381,7 @@ 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, dataset_name = get_multiview_db.getClassicDBhdf5( + dataset_file, labels_dictionary, dataset_name = get_multiview_db.get_classic_db_hdf5( cls.views, cls.pathF, cls.nameDB, NB_CLASS, askedLabelsNames, cls.random_state) @@ -398,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, dataset_name = get_multiview_db.getClassicDBhdf5(views, + dataset_file, labels_dictionary, dataset_name = get_multiview_db.get_classic_db_hdf5(views, cls.pathF, cls.nameDB, cls.NB_CLASS, @@ -423,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, dataset_name = get_multiview_db.getClassicDBhdf5(views, + dataset_file, labels_dictionary, dataset_name = get_multiview_db.get_classic_db_hdf5(views, cls.pathF, cls.nameDB, NB_CLASS, @@ -481,7 +481,7 @@ class Test_getClassicDBcsv(unittest.TestCase): cls.datas.append(data) def test_simple(cls): - dataset_file, labels_dictionary, dataset_name = get_multiview_db.getClassicDBcsv( + dataset_file, labels_dictionary, dataset_name = get_multiview_db.get_classic_db_csv( cls.views, cls.pathF, cls.nameDB, cls.NB_CLASS, cls.askedLabelsNames, cls.random_state, delimiter=",") @@ -497,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, dataset_name = get_multiview_db.getClassicDBcsv(views, + dataset_file, labels_dictionary, dataset_name = get_multiview_db.get_classic_db_csv(views, cls.pathF, cls.nameDB, cls.NB_CLASS, @@ -522,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, dataset_name = get_multiview_db.getClassicDBcsv( + dataset_file, labels_dictionary, dataset_name = get_multiview_db.get_classic_db_csv( cls.views, cls.pathF, cls.nameDB, NB_CLASS, askedLabelsNames, cls.random_state, delimiter=",") @@ -541,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, dataset_name = get_multiview_db.getClassicDBcsv(views, + dataset_file, labels_dictionary, dataset_name = get_multiview_db.get_classic_db_csv(views, cls.pathF, cls.nameDB, NB_CLASS, diff --git a/multiview_platform/tests/test_utils/test_execution.py b/multiview_platform/tests/test_utils/test_execution.py index 003b928bccd7816d0b84d86249fece750c4c2abe..b974324d3d0a0027762c7ca6e7ab0fbb0042eca3 100644 --- a/multiview_platform/tests/test_utils/test_execution.py +++ b/multiview_platform/tests/test_utils/test_execution.py @@ -3,6 +3,8 @@ import unittest import numpy as np +from ..utils import rm_tmp + from ...mono_multi_view_classifiers.utils import execution @@ -12,7 +14,7 @@ class Test_parseTheArgs(unittest.TestCase): self.args = [] def test_empty_args(self): - args = execution.parseTheArgs([]) + args = execution.parse_the_args([]) # print args @@ -25,14 +27,14 @@ class Test_initStatsIterRandomStates(unittest.TestCase): def test_one_statiter(cls): cls.state = cls.randomState.get_state()[1] - statsIterRandomStates = execution.initStatsIterRandomStates( + statsIterRandomStates = execution.init_stats_iter_random_states( cls.statsIter, cls.randomState) np.testing.assert_array_equal(statsIterRandomStates[0].get_state()[1], cls.state) def test_multiple_iter(cls): cls.statsIter = 3 - statsIterRandomStates = execution.initStatsIterRandomStates( + statsIterRandomStates = execution.init_stats_iter_random_states( cls.statsIter, cls.randomState) cls.assertAlmostEqual(len(statsIterRandomStates), 3) cls.assertNotEqual(statsIterRandomStates[0].randint(5000), @@ -51,50 +53,51 @@ class Test_getDatabaseFunction(unittest.TestCase): cls.type = ".csv" def test_simple(cls): - getDB = execution.getDatabaseFunction(cls.name, cls.type) + getDB = execution.get_database_function(cls.name, cls.type) from ...mono_multi_view_classifiers.utils.get_multiview_db import \ - getClassicDBcsv - cls.assertEqual(getDB, getClassicDBcsv) + get_classic_db_csv + cls.assertEqual(getDB, get_classic_db_csv) def test_hdf5(cls): cls.type = ".hdf5" - getDB = execution.getDatabaseFunction(cls.name, cls.type) + getDB = execution.get_database_function(cls.name, cls.type) from ...mono_multi_view_classifiers.utils.get_multiview_db import \ - getClassicDBhdf5 - cls.assertEqual(getDB, getClassicDBhdf5) + get_classic_db_hdf5 + cls.assertEqual(getDB, get_classic_db_hdf5) def test_plausible_hdf5(cls): - cls.name = "Plausible" + cls.name = "plausible" cls.type = ".hdf5" - getDB = execution.getDatabaseFunction(cls.name, cls.type) + getDB = execution.get_database_function(cls.name, cls.type) from ...mono_multi_view_classifiers.utils.get_multiview_db import \ - getPlausibleDBhdf5 - cls.assertEqual(getDB, getPlausibleDBhdf5) + get_plausible_db_hdf5 + cls.assertEqual(getDB, get_plausible_db_hdf5) class Test_initRandomState(unittest.TestCase): def setUp(self): - os.mkdir("multiview_platform/tests/temp_tests/") + rm_tmp() + os.mkdir("multiview_platform/tests/tmp_tests/") def tearDown(self): - os.rmdir("multiview_platform/tests/temp_tests/") + os.rmdir("multiview_platform/tests/tmp_tests/") def test_random_state_42(self): randomState_42 = np.random.RandomState(42) - randomState = execution.initRandomState("42", - "multiview_platform/tests/temp_tests/") - os.remove("multiview_platform/tests/temp_tests/randomState.pickle") + randomState = execution.init_random_state("42", + "multiview_platform/tests/tmp_tests/") + os.remove("multiview_platform/tests/tmp_tests/randomState.pickle") np.testing.assert_array_equal(randomState.beta(1, 100, 100), randomState_42.beta(1, 100, 100)) def test_random_state_pickle(self): - randomState_to_pickle = execution.initRandomState(None, - "multiview_platform/tests/temp_tests/") - pickled_randomState = execution.initRandomState( - "multiview_platform/tests/temp_tests/randomState.pickle", - "multiview_platform/tests/temp_tests/") - os.remove("multiview_platform/tests/temp_tests/randomState.pickle") + randomState_to_pickle = execution.init_random_state(None, + "multiview_platform/tests/tmp_tests/") + pickled_randomState = execution.init_random_state( + "multiview_platform/tests/tmp_tests/randomState.pickle", + "multiview_platform/tests/tmp_tests/") + os.remove("multiview_platform/tests/tmp_tests/randomState.pickle") np.testing.assert_array_equal(randomState_to_pickle.beta(1, 100, 100), pickled_randomState.beta(1, 100, 100)) @@ -144,7 +147,7 @@ class Test_genSplits(unittest.TestCase): self.splitRatio = 0.2 def test_simple(self): - splits = execution.genSplits(self.labels, self.splitRatio, + splits = execution.gen_splits(self.labels, self.splitRatio, self.statsIterRandomStates) self.assertEqual(len(splits), 3) self.assertEqual(len(splits[1]), 2) @@ -159,7 +162,7 @@ class Test_genSplits(unittest.TestCase): self.assertGreater(len(np.where(self.labels[splits[1][1]] == 2)[0]), 0) def test_genSplits_no_iter(self): - splits = execution.genSplits(self.labels, self.splitRatio, + splits = execution.gen_splits(self.labels, self.splitRatio, self.statsIterRandomStates) self.assertEqual(len(splits), 3) self.assertEqual(len(splits[0]), 2) @@ -194,7 +197,7 @@ class Test_genDirecortiesNames(unittest.TestCase): cls.stats_iter = 5 def test_simple_ovo(cls): - directories = execution.genDirecortiesNames(cls.directory, + directories = execution.gen_direcorties_names(cls.directory, cls.stats_iter) cls.assertEqual(len(directories), 5) cls.assertEqual(directories[0], "../chicken_is_heaven/iter_1/") @@ -202,7 +205,7 @@ class Test_genDirecortiesNames(unittest.TestCase): def test_ovo_no_iter(cls): cls.stats_iter = 1 - directories = execution.genDirecortiesNames(cls.directory, + directories = execution.gen_direcorties_names(cls.directory, cls.stats_iter) cls.assertEqual(len(directories), 1) cls.assertEqual(directories[0], "../chicken_is_heaven/") diff --git a/multiview_platform/tests/test_utils/test_multiclass.py b/multiview_platform/tests/test_utils/test_multiclass.py index a73e9f2b044dd8cd42c534e21d610ba384a897ec..7b00a32842e3dcbd7b8c7d99fdd1a2c8267d4126 100644 --- a/multiview_platform/tests/test_utils/test_multiclass.py +++ b/multiview_platform/tests/test_utils/test_multiclass.py @@ -21,7 +21,7 @@ class Test_genMulticlassLabels(unittest.TestCase): cls.testIndices[1]]] def test_one_versus_one(cls): - multiclassLabels, labelsIndices, oldIndicesMulticlass = multiclass.genMulticlassLabels( + multiclassLabels, labelsIndices, oldIndicesMulticlass = multiclass.gen_multiclass_labels( cls.labels, "oneVersusOne", cls.classificationIndices) cls.assertEqual(len(multiclassLabels), 10) cls.assertEqual(labelsIndices,