Skip to content

Commit

Permalink
15. adding of eeg dataset with bayesian tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qnater committed Sep 27, 2024
1 parent 88d02a3 commit c02f3cd
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 127 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/pytest_10.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pytest_contamination.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pytest - ImputeGAP - Contamination - MCAR - 8
name: Pytest - ImputeGAP - Contamination - MCAR - 12

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest_imp_cdrec.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Pytest - ImputeGAP - CDREC - 8
name: Pytest - ImputeGAP - CDREC - 12

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest_imp_iim.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Pytest - ImputeGAP - IIM - 8
name: Pytest - ImputeGAP - IIM - 12

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest_imp_mrnn.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Pytest - ImputeGAP - MRNN - 8
name: Pytest - ImputeGAP - MRNN - 12

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest_imp_stmvl.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Pytest - ImputeGAP - ST-MVL - 8
name: Pytest - ImputeGAP - ST-MVL - 12

on:
push:
Expand Down
54 changes: 33 additions & 21 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions env/optimal_parameters_cdrec.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[cdrec]
rank = "9"
epsilon = 1.591301339858638e-5
iteration = "100"
rank = "8"
epsilon = 0.00030828609249299515
iteration = "449"
Binary file modified imputegap/imputation/__pycache__/imputation.cpython-312.pyc
Binary file not shown.
60 changes: 7 additions & 53 deletions imputegap/imputation/imputation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,11 @@
from imputegap.algorithms.stmvl import stmvl
from imputegap.algorithms.zero_impute import zero_impute
from imputegap.evaluation.evaluation import Evaluation
from imputegap.manager import utils


class Imputation:

def load_parameters(query: str = "default", algorithm: str = "cdrec"):
"""
Load default values of algorithms
:param query : ('optimal' or 'default'), load default or optimal parameters for algorithms | default "default"
:param algorithm : algorithm parameters to load | default "cdrec"
:return: tuples of optimal parameters and the config of default values
"""

filepath = ""
if query == "default":
filepath = "../env/default_values.toml"
elif query == "optimal":
filepath = "../env/optimal_parameters_"+str(algorithm)+".toml"
else:
print("Query not found for this function ('optimal' or 'default')")

if not os.path.exists(filepath):
filepath = filepath[1:]

with open(filepath, "r") as _:
config = toml.load(filepath)

if algorithm == "cdrec":
truncation_rank = int(config['cdrec']['rank'])
epsilon = config['cdrec']['epsilon']
iterations = int(config['cdrec']['iteration'])
return (truncation_rank, epsilon, iterations)
elif algorithm == "stmvl":
window_size = int(config['stmvl']['window_size'])
gamma = float(config['stmvl']['gamma'])
alpha = int(config['stmvl']['alpha'])
return (window_size, gamma, alpha)
elif algorithm == "iim":
learning_neighbors = int(config['iim']['learning_neighbors'])
algo_code = config['iim']['algorithm_code']
return (learning_neighbors, algo_code)
elif algorithm == "mrnn":
hidden_dim = int(config['mrnn']['hidden_dim'])
learning_rate = float(config['mrnn']['learning_rate'])
iterations = int(config['mrnn']['iterations'])
sequence_length = int(config['mrnn']['sequence_length'])
return (hidden_dim, learning_rate, iterations, sequence_length)
else :
print("Default/Optimal config not found for this algorithm")
return None

def evaluate_params(ground_truth, contamination, configuration, algorithm="cdrec"):
"""
Expand All @@ -81,8 +35,8 @@ def evaluate_params(ground_truth, contamination, configuration, algorithm="cdrec
alg_code = "iim " + re.sub(r'[\W_]', '', str(learning_neighbours))
imputation, error_measures = Imputation.Regression.iim_imputation(ground_truth, contamination, (learning_neighbours, alg_code))
elif algorithm == 'mrnn':
hidden_dim, learning_rate, iterations, keep_prob, seq_len = configuration
imputation, error_measures = Imputation.ML.mrnn_imputation(ground_truth, contamination, (hidden_dim, learning_rate, iterations, seq_len))
hidden_dim, learning_rate, iterations = configuration
imputation, error_measures = Imputation.ML.mrnn_imputation(ground_truth, contamination, (hidden_dim, learning_rate, iterations, 7))
elif algorithm == 'stmvl':
window_size, gamma, alpha = configuration
imputation, error_measures = Imputation.Pattern.stmvl_imputation(ground_truth, contamination, (window_size, gamma, alpha))
Expand All @@ -106,7 +60,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(query="default", algorithm="cdrec")
truncation_rank, epsilon, iterations = utils.load_parameters(query="default", algorithm="cdrec")

imputed_matrix = cdrec(contamination=contamination, truncation_rank=truncation_rank, iterations=iterations, epsilon=epsilon)

Expand Down Expand Up @@ -163,7 +117,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(query="default", algorithm="iim")
neighbors, algo_code = utils.load_parameters(query="default", algorithm="iim")

imputed_matrix = iim(contamination=contamination, number_neighbor=neighbors, algo_code=algo_code)

Expand All @@ -186,7 +140,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(query="default", algorithm="mrnn")
hidden_dim, learning_rate, iterations, sequence_length = utils.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)

Expand All @@ -211,7 +165,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(query="default", algorithm="stmvl")
window_size, gamma, alpha = utils.load_parameters(query="default", algorithm="stmvl")

imputed_matrix = stmvl(contamination=contamination, window_size=window_size, gamma=gamma, alpha=alpha)

Expand Down
Binary file modified imputegap/manager/__pycache__/utils.cpython-312.pyc
Binary file not shown.
Loading

0 comments on commit c02f3cd

Please sign in to comment.