diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1934d80..fca67af 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,20 @@ + - + + + + + + + + + @@ -72,8 +81,8 @@ - - + + - + - + - + - + - - + + - - - + + + @@ -204,7 +206,7 @@ - + @@ -228,8 +230,8 @@ - - + + \ No newline at end of file diff --git a/imputegap/assets/contamination/test_contamination.png b/imputegap/assets/contamination/test_contamination.png index e95ea06..9623a3e 100644 Binary files a/imputegap/assets/contamination/test_contamination.png and b/imputegap/assets/contamination/test_contamination.png differ diff --git a/imputegap/assets/ground_truth/test_ground_truth.png b/imputegap/assets/ground_truth/test_ground_truth.png index 61ef585..d41fd71 100644 Binary files a/imputegap/assets/ground_truth/test_ground_truth.png and b/imputegap/assets/ground_truth/test_ground_truth.png differ diff --git a/imputegap/imputation/__pycache__/imputation.cpython-312.pyc b/imputegap/imputation/__pycache__/imputation.cpython-312.pyc index d42086e..95e3d8e 100644 Binary files a/imputegap/imputation/__pycache__/imputation.cpython-312.pyc and b/imputegap/imputation/__pycache__/imputation.cpython-312.pyc differ diff --git a/imputegap/imputation/imputation.py b/imputegap/imputation/imputation.py index 674ee69..48483b0 100644 --- a/imputegap/imputation/imputation.py +++ b/imputegap/imputation/imputation.py @@ -12,7 +12,6 @@ class Imputation: - @classmethod def load_parameters(query: str = "default", algorithm: str = "cdrec"): """ Load default values of algorithms @@ -34,8 +33,6 @@ def load_parameters(query: str = "default", algorithm: str = "cdrec"): if not os.path.exists(filepath): filepath = filepath[1:] - print(filepath) - with open(filepath, "r") as _: config = toml.load(filepath) @@ -111,7 +108,7 @@ def cdrec(ground_truth, contamination, params=None): if params is not None: truncation_rank, epsilon, iterations = params else: - truncation_rank, epsilon, iterations = Imputation.load_parameters(algorithm="cdrec") + truncation_rank, epsilon, iterations = Imputation.load_parameters(query="default", algorithm="cdrec") imputed_matrix = cdrec(contamination=contamination, truncation_rank=truncation_rank, iterations=iterations, epsilon=epsilon) @@ -168,7 +165,7 @@ def iim_imputation(ground_truth, contamination, params=None): if params is not None: neighbors, algo_code = params else: - neighbors, algo_code = Imputation.load_parameters(algorithm="iim") + neighbors, algo_code = Imputation.load_parameters(query="default", algorithm="iim") imputed_matrix = iim(contamination=contamination, number_neighbor=neighbors, algo_code=algo_code) @@ -191,7 +188,7 @@ def mrnn_imputation(ground_truth, contamination, params=None): if params is not None: hidden_dim, learning_rate, iterations, sequence_length = params else: - hidden_dim, learning_rate, iterations, sequence_length = Imputation.load_parameters(algorithm="mrnn") + hidden_dim, learning_rate, iterations, sequence_length = Imputation.load_parameters(query="default", algorithm="mrnn") imputed_matrix = mrnn(contamination=contamination, hidden_dim=hidden_dim, learning_rate=learning_rate, iterations=iterations, sequence_length=sequence_length) @@ -216,7 +213,7 @@ def stmvl_imputation(ground_truth, contamination, params=None): if params is not None: window_size, gamma, alpha = params else: - window_size, gamma, alpha = Imputation.load_parameters(algorithm="stmvl") + window_size, gamma, alpha = Imputation.load_parameters(query="default", algorithm="stmvl") imputed_matrix = stmvl(contamination=contamination, window_size=window_size, gamma=gamma, alpha=alpha) diff --git a/imputegap/manager/__pycache__/utils.cpython-312.pyc b/imputegap/manager/__pycache__/utils.cpython-312.pyc new file mode 100644 index 0000000..e6a61c1 Binary files /dev/null and b/imputegap/manager/__pycache__/utils.cpython-312.pyc differ diff --git a/imputegap/manager/utils.py b/imputegap/manager/utils.py new file mode 100644 index 0000000..38fbfcf --- /dev/null +++ b/imputegap/manager/utils.py @@ -0,0 +1,28 @@ +import os + + +def get_file_path_dataset(set_name="test"): + """ + Find the accurate path for loading files of tests + :return: correct file paths + """ + + filepath = "../imputegap/dataset/" + set_name + ".txt" + + if not os.path.exists(filepath): + filepath = filepath[1:] + + return filepath + + +def get_save_path_asset(): + """ + Find the accurate path for saving files of tests + :return: correct file paths + """ + filepath = "../tests/assets" + + if not os.path.exists(filepath): + filepath = filepath[1:] + + return filepath diff --git a/imputegap/runner_optimization.py b/imputegap/runner_optimization.py index e4fb079..e26a224 100644 --- a/imputegap/runner_optimization.py +++ b/imputegap/runner_optimization.py @@ -37,11 +37,11 @@ def check_block_size(filename): gap.print() gap.plot(ts_type="contamination", title="test", save_path="assets", limitation=3, display=False) - optimal_params, yi = Optimization.Bayesian.bayesian_optimization(ground_truth=gap.ts, contamination=gap.ts_contaminate, algorithm="iim") - - print("\nOptical Params : ", optimal_params) - print("\nyi : ", yi, "\n") - - Optimization.save_optimization(optimal_params=optimal_params, algorithm="cdrec") - - print("\n", "_"*95, "end") \ No newline at end of file + for algo in ["cdrec", "stmvl", "iim", "mrnn"]: + print("RUN OPTIMIZATION FOR : ", algo, "...") + optimal_params, yi = Optimization.Bayesian.bayesian_optimization(ground_truth=gap.ts, contamination=gap.ts_contaminate, algorithm=algo) + print("\nOptical Params : ", optimal_params) + print("\nyi : ", yi, "\n") + Optimization.save_optimization(optimal_params=optimal_params, algorithm=algo) + print("\n", "_"*95, "end") + print("\n", "_" * 95, "end") \ No newline at end of file diff --git a/tests/__pycache__/test_contamination_mcar.cpython-312.pyc b/tests/__pycache__/test_contamination_mcar.cpython-312.pyc index afa3b5a..1328b96 100644 Binary files a/tests/__pycache__/test_contamination_mcar.cpython-312.pyc and b/tests/__pycache__/test_contamination_mcar.cpython-312.pyc differ diff --git a/tests/__pycache__/test_contamination_mp.cpython-312.pyc b/tests/__pycache__/test_contamination_mp.cpython-312.pyc index c947ce0..86e73f3 100644 Binary files a/tests/__pycache__/test_contamination_mp.cpython-312.pyc and b/tests/__pycache__/test_contamination_mp.cpython-312.pyc differ diff --git a/tests/__pycache__/test_imputation_iim.cpython-312.pyc b/tests/__pycache__/test_imputation_iim.cpython-312.pyc index 3c416db..c3b19a0 100644 Binary files a/tests/__pycache__/test_imputation_iim.cpython-312.pyc and b/tests/__pycache__/test_imputation_iim.cpython-312.pyc differ diff --git a/tests/test_contamination_mcar.py b/tests/test_contamination_mcar.py index 5c4c5a3..776a5f4 100644 --- a/tests/test_contamination_mcar.py +++ b/tests/test_contamination_mcar.py @@ -3,48 +3,17 @@ import numpy as np from imputegap.contamination.contamination import Contamination +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_save_path(): - """ - Find the accurate path for saving files of tests - :return: correct file paths - """ - return resolve_path('../tests/assets', './tests/assets') - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - - class TestContamination(unittest.TestCase): def test_mcar_selection(self): """ the goal is to test if only the selected values are contaminated """ - impute_gap = TimeSeries(get_file_path("test")) + impute_gap = TimeSeries(utils.get_file_path_dataset("test")) series_impacted = [0.4] missing_rates = [0.4] @@ -82,7 +51,7 @@ def test_mcar_position(self): """ the goal is to test if the starting position is always guaranteed """ - impute_gap = TimeSeries(get_file_path("test")) + impute_gap = TimeSeries(utils.get_file_path_dataset("test")) series_impacted = [0.4, 1] missing_rates = [0.1, 0.4, 0.6] @@ -118,7 +87,7 @@ def test_mcar_selection_datasets(self): block_size = 10 for dataset in datasets: - impute_gap = TimeSeries(get_file_path(dataset)) + impute_gap = TimeSeries(utils.get_file_path_dataset(dataset)) for seed_value in range(seeds_start, seeds_end): for series_sel in series_impacted: @@ -156,7 +125,7 @@ def test_mcar_position_datasets(self): block_size = 10 for dataset in datasets: - impute_gap = TimeSeries(get_file_path(dataset)) + impute_gap = TimeSeries(utils.get_file_path_dataset(dataset)) ten_percent_index = int(impute_gap.ts.shape[1] * 0.1) for seed_value in range(seeds_start, seeds_end): @@ -180,11 +149,11 @@ def test_contaminate_plot(self): """ Verify if the manager of a dataset is working """ - impute_gap = TimeSeries(get_file_path("chlorine")) + impute_gap = TimeSeries(utils.get_file_path_dataset("chlorine")) impute_gap.ts_contaminate = Contamination.scenario_mcar(ts=impute_gap.ts, series_impacted=0.4, missing_rate=0.1, block_size=10, protection=0.1, use_seed=True, seed=42) impute_gap.print() - filepath = impute_gap.plot("contamination", "test", get_save_path(), 5, (16, 8), False) + filepath = impute_gap.plot("contamination", "test", utils.get_save_path_asset(), 5, (16, 8), False) self.assertTrue(os.path.exists(filepath)) diff --git a/tests/test_contamination_mp.py b/tests/test_contamination_mp.py index 0e17f48..34c079b 100644 --- a/tests/test_contamination_mp.py +++ b/tests/test_contamination_mp.py @@ -4,40 +4,17 @@ import math from imputegap.contamination.contamination import Contamination +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - - class TestContamination(unittest.TestCase): def test_mp_selection(self): """ the goal is to test if only the selected values are contaminated """ - impute_gap = TimeSeries(get_file_path("test")) + impute_gap = TimeSeries(utils.get_file_path_dataset("test")) series_impacted = [0.4] missing_rates = [0.4] @@ -78,7 +55,7 @@ def test_mp_position(self): """ the goal is to test if the starting position is always guaranteed """ - impute_gap = TimeSeries(get_file_path("test")) + impute_gap = TimeSeries(utils.get_file_path_dataset("test")) series_impacted = [0.4, 1] missing_rates = [0.1, 0.4, 0.6] diff --git a/tests/test_explainer.py b/tests/test_explainer.py index 40a8384..c1135bb 100644 --- a/tests/test_explainer.py +++ b/tests/test_explainer.py @@ -4,33 +4,10 @@ import numpy as np from imputegap.explainer.explainer import Explainer +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - - class TestExplainer(unittest.TestCase): def test_explainer_shap(self): @@ -47,7 +24,7 @@ def test_explainer_shap(self): expected_categories, expected_features = Explainer.load_configuration() - gap = TimeSeries(data=get_file_path(filename)) + gap = TimeSeries(data=utils.get_file_path_dataset(filename)) shap_values, shap_details = Explainer.shap_explainer(ground_truth=gap.ts, file_name=filename, use_seed=True, seed=42) diff --git a/tests/test_imputation_cdrec.py b/tests/test_imputation_cdrec.py index a1b546b..8497e0c 100644 --- a/tests/test_imputation_cdrec.py +++ b/tests/test_imputation_cdrec.py @@ -4,6 +4,7 @@ from imputegap.contamination.contamination import Contamination from imputegap.imputation.imputation import Imputation +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries @@ -45,7 +46,7 @@ def test_imputation_cdrec(self): """ the goal is to test if only the simple imputation with cdrec has the expected outcome """ - impute_gap = TimeSeries(get_file_path("test")) + impute_gap = TimeSeries((utils.get_file_path_dataset("test"))) ts_contaminated = Contamination.scenario_mcar(ts=impute_gap.ts, series_impacted=0.4, missing_rate=0.4, block_size=2, protection=0.1, use_seed=True, seed=42) imputation, metrics = Imputation.MR.cdrec(impute_gap.ts, ts_contaminated) @@ -73,7 +74,7 @@ def test_imputation_cdrec_chlorine(self): """ the goal is to test if only the simple imputation with cdrec has the expected outcome """ - impute_gap = TimeSeries(get_file_path("chlorine")) + impute_gap = TimeSeries(utils.get_file_path_dataset("chlorine")) ts_contaminated = Contamination.scenario_mcar(ts=impute_gap.ts, series_impacted=0.4, missing_rate=0.4, block_size=10, protection=0.1, diff --git a/tests/test_imputation_iim.py b/tests/test_imputation_iim.py index d6ef62c..abd1b65 100644 --- a/tests/test_imputation_iim.py +++ b/tests/test_imputation_iim.py @@ -4,39 +4,10 @@ from imputegap.contamination.contamination import Contamination from imputegap.imputation.imputation import Imputation +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_save_path(): - """ - Find the accurate path for saving files of tests - :return: correct file paths - """ - return resolve_path('../tests/assets', './tests/assets') - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') class TestIIM(unittest.TestCase): @@ -45,7 +16,7 @@ def test_imputation_iim_chlorine(self): """ the goal is to test if only the simple imputation with IIM has the expected outcome """ - impute_gap = TimeSeries(get_file_path("chlorine")) + impute_gap = TimeSeries(utils.get_file_path_dataset("chlorine")) ts_contaminated = Contamination.scenario_mcar(ts=impute_gap.ts, series_impacted=0.4, missing_rate=0.4, block_size=10, protection=0.1, use_seed=True, seed=42) diff --git a/tests/test_imputation_mrnn.py b/tests/test_imputation_mrnn.py index 2bee7a3..f51109c 100644 --- a/tests/test_imputation_mrnn.py +++ b/tests/test_imputation_mrnn.py @@ -4,48 +4,17 @@ from imputegap.contamination.contamination import Contamination from imputegap.imputation.imputation import Imputation +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_save_path(): - """ - Find the accurate path for saving files of tests - :return: correct file paths - """ - return resolve_path('../tests/assets', './tests/assets') - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - - class TestMRNN(unittest.TestCase): def test_imputation_mrnn_chlorine(self): """ the goal is to test if only the simple imputation with MRNN has the expected outcome """ - impute_gap = TimeSeries(get_file_path("chlorine")) + impute_gap = TimeSeries(utils.get_file_path_dataset("chlorine")) ts_contaminated = Contamination.scenario_mcar(ts=impute_gap.ts, series_impacted=0.4, missing_rate=0.4, block_size=10, protection=0.1, use_seed=True, seed=42) diff --git a/tests/test_imputation_stmvl.py b/tests/test_imputation_stmvl.py index 8e87331..3531279 100644 --- a/tests/test_imputation_stmvl.py +++ b/tests/test_imputation_stmvl.py @@ -4,48 +4,16 @@ from imputegap.contamination.contamination import Contamination from imputegap.imputation.imputation import Imputation +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries - -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_save_path(): - """ - Find the accurate path for saving files of tests - :return: correct file paths - """ - return resolve_path('../tests/assets', './tests/assets') - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - - class TestSTMVL(unittest.TestCase): def test_imputation_mrnn_chlorine(self): """ the goal is to test if only the simple imputation with ST-MVL has the expected outcome """ - impute_gap = TimeSeries(get_file_path("chlorine")) + impute_gap = TimeSeries((utils.get_file_path_dataset("chlorine"))) ts_contaminated = Contamination.scenario_mcar(ts=impute_gap.ts, series_impacted=0.4, missing_rate=0.4, block_size=10, protection=0.1, use_seed=True, seed=42) diff --git a/tests/test_loading.py b/tests/test_loading.py index 10a0e5a..6fc43b9 100644 --- a/tests/test_loading.py +++ b/tests/test_loading.py @@ -5,48 +5,16 @@ from scipy.stats import zscore from sklearn.preprocessing import MinMaxScaler +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries - -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_save_path(): - """ - Find the accurate path for saving files of tests - :return: correct file paths - """ - return resolve_path('../tests/assets', './tests/assets') - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - - class TestLoading(unittest.TestCase): def test_loading_set(self): """ Verify if the manager of a dataset is working """ - impute_gap = TimeSeries(get_file_path("test")) + impute_gap = TimeSeries(utils.get_file_path_dataset("test")) self.assertEqual(impute_gap.ts.shape, (10, 25)) self.assertEqual(impute_gap.ts[0, 1], 2.5) @@ -56,7 +24,7 @@ def test_loading_chlorine(self): """ Verify if the manager of a dataset is working """ - impute_gap = TimeSeries(get_file_path("chlorine")) + impute_gap = TimeSeries(utils.get_file_path_dataset("chlorine")) self.assertEqual(impute_gap.ts.shape, (50, 1000)) self.assertEqual(impute_gap.ts[0, 1], 0.0154797) @@ -66,20 +34,20 @@ def test_loading_plot(self): """ Verify if the manager of a dataset is working """ - impute_gap = TimeSeries(get_file_path("test")) - to_save = get_save_path() + impute_gap = TimeSeries(utils.get_file_path_dataset("test")) + to_save = utils.get_save_path_asset() file_path = impute_gap.plot("ground_truth", "test", to_save, 5, (16, 8), False) self.assertTrue(os.path.exists(file_path)) def test_loading_normalization_min_max(self): - impute_gap = TimeSeries(get_file_path("test"), normalization="min_max") + impute_gap = TimeSeries(utils.get_file_path_dataset("test"), normalization="min_max") assert np.isclose(np.min(impute_gap.ts), 0), f"Min value after Min-Max normalization is not 0: {np.min(impute_gap.normalized_ts)}" assert np.isclose(np.max(impute_gap.ts), 1), f"Max value after Min-Max normalization is not 1: {np.max(impute_gap.normalized_ts)}" def test_loading_normalization_z_score(self): - normalized = TimeSeries(get_file_path("test"), normalization="z_score") + normalized = TimeSeries(utils.get_file_path_dataset("test"), normalization="z_score") mean = np.mean(normalized.ts) std_dev = np.std(normalized.ts) @@ -88,8 +56,8 @@ def test_loading_normalization_z_score(self): assert np.isclose(std_dev, 1, atol=1e-7), f"Standard deviation after Z-score normalization is not 1: {std_dev}" def test_loading_normalization_min_max_lib(impute_gap): - ground_truth = TimeSeries(get_file_path("chlorine")) - impute_gap = TimeSeries(get_file_path("chlorine"), normalization="min_max") + ground_truth = TimeSeries(utils.get_file_path_dataset("chlorine")) + impute_gap = TimeSeries(utils.get_file_path_dataset("chlorine"), normalization="min_max") scaler = MinMaxScaler() lib_normalized = scaler.fit_transform(ground_truth.ts) @@ -97,8 +65,8 @@ def test_loading_normalization_min_max_lib(impute_gap): assert np.allclose(impute_gap.ts, lib_normalized) def test_loading_normalization_z_score_lib(impute_gap): - ground_truth = TimeSeries(get_file_path("chlorine")) - impute_gap = TimeSeries(get_file_path("chlorine"), normalization="z_score") + ground_truth = TimeSeries(utils.get_file_path_dataset("chlorine")) + impute_gap = TimeSeries(utils.get_file_path_dataset("chlorine"), normalization="z_score") lib_normalized = zscore(ground_truth.ts, axis=None) diff --git a/tests/test_opti_bayesian_cdrec.py b/tests/test_opti_bayesian_cdrec.py index 3f48ac7..eabdf58 100644 --- a/tests/test_opti_bayesian_cdrec.py +++ b/tests/test_opti_bayesian_cdrec.py @@ -4,41 +4,18 @@ from imputegap.contamination.contamination import Contamination from imputegap.imputation.imputation import Imputation +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries from imputegap.optimization.bayesian_optimization import Optimization -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - - class TestOptiCDREC(unittest.TestCase): def test_optimization_bayesian_cdrec(self): """ the goal is to test if only the simple optimization with cdrec has the expected outcome """ - gap = TimeSeries(get_file_path("chlorine")) + gap = TimeSeries(utils.get_file_path_dataset("chlorine")) algorithm = "cdrec" diff --git a/tests/test_opti_bayesian_iim.py b/tests/test_opti_bayesian_iim.py index bcd03eb..8452d5a 100644 --- a/tests/test_opti_bayesian_iim.py +++ b/tests/test_opti_bayesian_iim.py @@ -4,33 +4,11 @@ from imputegap.contamination.contamination import Contamination from imputegap.imputation.imputation import Imputation +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries from imputegap.optimization.bayesian_optimization import Optimization -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - class TestOptiIMM(unittest.TestCase): @@ -38,7 +16,7 @@ def test_optimization_bayesian_iim(self): """ the goal is to test if only the simple optimization with stmvl has the expected outcome """ - gap = TimeSeries(get_file_path("chlorine")) + gap = TimeSeries(utils.get_file_path_dataset("chlorine")) algorithm = "iim" diff --git a/tests/test_opti_bayesian_mrnn.py b/tests/test_opti_bayesian_mrnn.py index 24ae435..ae028fd 100644 --- a/tests/test_opti_bayesian_mrnn.py +++ b/tests/test_opti_bayesian_mrnn.py @@ -4,33 +4,11 @@ from imputegap.contamination.contamination import Contamination from imputegap.imputation.imputation import Imputation +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries from imputegap.optimization.bayesian_optimization import Optimization -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - class TestOptiMRNN(unittest.TestCase): @@ -38,7 +16,7 @@ def test_optimization_bayesian_mrnn(self): """ the goal is to test if only the simple optimization with mrnn has the expected outcome """ - gap = TimeSeries(get_file_path("chlorine")) + gap = TimeSeries(utils.get_file_path_dataset("chlorine")) algorithm = "mrnn" diff --git a/tests/test_opti_bayesian_stmvl.py b/tests/test_opti_bayesian_stmvl.py index f482fa9..ba361e7 100644 --- a/tests/test_opti_bayesian_stmvl.py +++ b/tests/test_opti_bayesian_stmvl.py @@ -4,33 +4,11 @@ from imputegap.contamination.contamination import Contamination from imputegap.imputation.imputation import Imputation +from imputegap.manager import utils from imputegap.manager.manager import TimeSeries from imputegap.optimization.bayesian_optimization import Optimization -def resolve_path(local_path, github_actions_path): - """ - Find the accurate path for tests - - :param local_path: path of local code - :param github_actions_path: path on GitHub action - :return: correct file paths - """ - if os.path.exists(local_path): - return local_path - elif os.path.exists(github_actions_path): - return github_actions_path - else: - raise FileNotFoundError("File not found in both: ", local_path, " and ", github_actions_path) - - -def get_file_path(set_name="test"): - """ - Find the accurate path for loading files of tests - :return: correct file paths - """ - return resolve_path(f'../imputegap/dataset/{set_name}.txt', f'./imputegap/dataset/{set_name}.txt') - class TestOptiSTMVL(unittest.TestCase): @@ -38,7 +16,7 @@ def test_optimization_bayesian_stmvl(self): """ the goal is to test if only the simple optimization with stmvl has the expected outcome """ - gap = TimeSeries(get_file_path("chlorine")) + gap = TimeSeries(utils.get_file_path_dataset("chlorine")) algorithm = "stmvl"