Skip to content

Commit

Permalink
1. adding correction for the optimization autml and imputation, with …
Browse files Browse the repository at this point in the history
…normalization and timing
  • Loading branch information
qnater committed Oct 10, 2024
1 parent 1d9ec16 commit 596d29b
Show file tree
Hide file tree
Showing 50 changed files with 459 additions and 179 deletions.
90 changes: 59 additions & 31 deletions .idea/workspace.xml

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions env/default_values.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ learning_rate = 0.01
iterations = 50
sequence_length = 7

[greedy]
n_calls = 250
selected_metrics='RMSE'

[bayesian]
n_calls = 2
n_random_starts = 50
acq_func = 'gp_hedge'
selected_metrics='RMSE'

[pso]
n_particles = 50
c1 = 0.5
c2 = 0.3
w = 0.9
iterations=10
n_processes=1
selected_metrics='RMSE'


[explainer]
splitter = 10
nbr_series = 15
Expand Down
Binary file modified imputegap/algorithms/__pycache__/cdrec.cpython-312.pyc
Binary file not shown.
Binary file modified imputegap/algorithms/__pycache__/iim.cpython-312.pyc
Binary file not shown.
Binary file modified imputegap/algorithms/__pycache__/mrnn.cpython-312.pyc
Binary file not shown.
Binary file modified imputegap/algorithms/__pycache__/stmvl.cpython-312.pyc
Binary file not shown.
11 changes: 10 additions & 1 deletion imputegap/algorithms/cdrec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ctypes
import os
import platform
import time
import ctypes as __native_c_types_import;
import numpy as __numpy_import;

Expand Down Expand Up @@ -80,7 +81,7 @@ def native_cdrec(__py_matrix, __py_rank, __py_eps, __py_iters):
return __py_recovered;


def cdrec(contamination, truncation_rank, iterations, epsilon):
def cdrec(contamination, truncation_rank, iterations, epsilon, logs=True):
"""
CDREC algorithm for imputation of missing data
@author : Quentin Nater
Expand All @@ -90,11 +91,19 @@ def cdrec(contamination, truncation_rank, iterations, epsilon):
:param epsilon : learning rate
:param iterations : number of iterations
:param logs: print logs of time execution
:return: imputed_matrix, metrics : all time series with imputation data and their metrics
"""
start_time = time.time() # Record start time

# Call the C++ function to perform recovery
imputed_matrix = native_cdrec(contamination, truncation_rank, epsilon, iterations)

end_time = time.time()

if logs:
print(f"\n\t\t> logs, imputation cdrec - Execution Time: {(end_time - start_time):.4f} seconds\n")

return imputed_matrix
15 changes: 11 additions & 4 deletions imputegap/algorithms/iim.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import numpy as np

import time
from imputegap.wrapper.AlgoPython.IIM.testerIIM import impute_with_algorithm


def iim(contamination, number_neighbor, algo_code):
def iim(contamination, number_neighbor, algo_code, logs=True):
"""
Template zero impute for adding your own algorithms
@author : Quentin Nater
Expand All @@ -12,10 +11,18 @@ def iim(contamination, number_neighbor, algo_code):
:param adaptive_flag: The algorithm will run the non-adaptive version of the algorithm, as described in the paper
:param number_neighbor : The number of neighbors to use for the KNN classifier, by default 10.
:param algo_code : Action of the IIM output
:param logs: print logs of time execution
:return: imputed_matrix, metrics : all time series with imputation data and their metrics
"""
#imputed_matrix = iim_recovery(matrix_nan=contamination, adaptive_flag=adaptive_flag, learning_neighbors=number_neighbor)
start_time = time.time() # Record start time

imputed_matrix = impute_with_algorithm(algo_code, contamination.copy(), number_neighbor)

end_time = time.time()
if logs:
print(f"\n\t\t> logs, imputation iim - Execution Time: {(end_time - start_time):.4f} seconds\n")

return imputed_matrix
12 changes: 11 additions & 1 deletion imputegap/algorithms/mrnn.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import time
from imputegap.wrapper.AlgoPython.MRNN.testerMRNN import mrnn_recov


def mrnn(contamination, hidden_dim, learning_rate, iterations, sequence_length):
def mrnn(contamination, hidden_dim, learning_rate, iterations, sequence_length, logs=True):

"""
Template zero impute for adding your own algorithms
Expand All @@ -12,9 +13,18 @@ def mrnn(contamination, hidden_dim, learning_rate, iterations, sequence_length):
:param learning_rate : learning rate of the training
:param iterations : iterations during the training
:param seq_length : length of the sequences inside MRNN
:param logs: print logs of time execution
:return: imputed_matrix, metrics : all time series with imputation data and their metrics
"""
start_time = time.time() # Record start time

imputed_matrix = mrnn_recov(matrix_in=contamination, hidden_dim=hidden_dim, learning_rate=learning_rate, iterations=iterations, seq_length=sequence_length)

end_time = time.time()
if logs:
print(f"\n\t\t> logs, imputation mrnn - Execution Time: {(end_time - start_time):.4f} seconds\n")

return imputed_matrix
12 changes: 10 additions & 2 deletions imputegap/algorithms/stmvl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ctypes
import time
import os
import platform
import ctypes as __native_c_types_import;
Expand Down Expand Up @@ -34,7 +35,7 @@ def load_share_lib(name = "lib_stmvl"):
lib_path = os.path.join(local_path_win)
else:
lib_path = os.path.join(local_path_lin)
print("\n", lib_path, " has been loaded...")
#print("\n", lib_path, " has been loaded...")

return ctypes.CDLL(lib_path)

Expand Down Expand Up @@ -86,7 +87,7 @@ def native_stmvl(__py_matrix, __py_window, __py_gamma, __py_alpha):
return __py_recovered;


def stmvl(contamination, window_size, gamma, alpha):
def stmvl(contamination, window_size, gamma, alpha, logs=True):
"""
CDREC algorithm for imputation of missing data
@author : Quentin Nater
Expand All @@ -96,13 +97,20 @@ def stmvl(contamination, window_size, gamma, alpha):
:param gamma: smoothing parameter for temporal weight
:param alpha: power for spatial weight
:param logs: print logs of time execution
:return: imputed_matrix, metrics : all time series with imputation data and their metrics
"""
start_time = time.time() # Record start time

# Call the C++ function to perform recovery
imputed_matrix = native_stmvl(contamination, window_size, gamma, alpha)

end_time = time.time()
if logs:
print(f"\n\t\t> logs, imputation stvml - Execution Time: {(end_time - start_time):.4f} seconds\n")

return imputed_matrix


Binary file modified imputegap/assets/TimeSeriesData_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified imputegap/assets/contamination_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified imputegap/explainer/__pycache__/explainer.cpython-312.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion imputegap/explainer/explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def shap_explainer(raw_data, algorithm="cdrec", params=None, contamination="mcar
elif algorithm == "mrnn":
algo = Imputation.ML.MRNN(obfuscated_matrix)

algo.impute(params)
algo.impute(user_defined=True, params=params)
algo.score(raw_data)
imputation_results = algo.metrics

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

0 comments on commit 596d29b

Please sign in to comment.