-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7. adding of eeg dataset with bayesian tests
- Loading branch information
Showing
5 changed files
with
158 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import os | ||
import unittest | ||
import numpy as np | ||
|
||
from imputegap.contamination.contamination import Contamination | ||
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_mcar_selection(self): | ||
""" | ||
the goal is to test if only the selected values are contaminated | ||
""" | ||
impute_gap = TimeSeries(get_file_path("test")) | ||
|
||
series_impacted = [0.4] | ||
missing_rates = [0.4] | ||
seeds_start, seeds_end = 42, 43 | ||
series_check = ["1", "2", "3", "4"] | ||
protection = 0.1 | ||
|
||
for seed_value in range(seeds_start, seeds_end): | ||
for series_sel in series_impacted: | ||
for missing_rate in missing_rates: | ||
|
||
ts_contaminate = Contamination.scenario_missing_percentage(ts=impute_gap.ts, | ||
series_impacted=series_sel, | ||
missing_rate=missing_rate, | ||
protection=protection, use_seed=True, | ||
seed=seed_value) | ||
|
||
check_nan_series = False | ||
|
||
for series, data in enumerate(ts_contaminate): | ||
if str(series) in series_check: | ||
if np.isnan(data).any(): | ||
check_nan_series = True | ||
else: | ||
if np.isnan(data).any(): | ||
check_nan_series = False | ||
break | ||
else: | ||
check_nan_series = True | ||
|
||
self.assertTrue(check_nan_series, True) | ||
|
||
def test_mcar_position(self): | ||
""" | ||
the goal is to test if the starting position is always guaranteed | ||
""" | ||
impute_gap = TimeSeries(get_file_path("test")) | ||
|
||
series_impacted = [0.4, 1] | ||
missing_rates = [0.1, 0.4, 0.6] | ||
ten_percent_index = int(impute_gap.ts.shape[1] * 0.1) | ||
seeds_start, seeds_end = 42, 43 | ||
|
||
for seed_value in range(seeds_start, seeds_end): | ||
for series_sel in series_impacted: | ||
for missing_rate in missing_rates: | ||
|
||
ts_contaminate = Contamination.scenario_missing_percentage(ts=impute_gap.ts, | ||
series_impacted=series_sel, | ||
missing_rate=missing_rate, protection=0.1, | ||
use_seed=True, seed=seed_value) | ||
|
||
if np.isnan(ts_contaminate[:, :ten_percent_index]).any(): | ||
check_position = False | ||
else: | ||
check_position = True | ||
|
||
self.assertTrue(check_position, True) |