Skip to content

Commit 5de2d08

Browse files
author
Matteo Allione
committed
Removed the constraint on positive weights during the minimization of dii (file diff_imbalance.py). Introduction of an early stopping criteria (diff_imbalance.py). Implementation of the Langevin dynamic, for the estimation of the error (diff_imbalance.py). Insertion of the calculation of the error with langevin dynamic (causal_graph.py).
1 parent a1ef16d commit 5de2d08

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

dadapy/causal_graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import numpy as np
2929
from tqdm.auto import tqdm
3030

31-
from diff_imbalance_langevin import DiffImbalance
31+
from dadapy import DiffImbalance
3232

3333

3434
class CausalGraph(DiffImbalance):
@@ -482,7 +482,7 @@ def optimize_present_to_future(
482482
weights_temp = np.concatenate([weights_temp, weights_langevin[1:]], axis=0)
483483
imbs_training[i_var, j_tau] = np.concatenate([imbs_temp[i_var, j_tau], imbs_langevin[1:]])
484484
if return_covariance:
485-
covariance_matrix[i_var, j_tau] = np.cov(weights_langevin ,rowvar=False)
485+
covariance_matrix[i_var, j_tau] = np.cov(weights_langevin[::10] ,rowvar=False)/len(weights_langevin[::10])
486486

487487
# save weights
488488
if embedding_dim_present == 1:
@@ -497,7 +497,7 @@ def optimize_present_to_future(
497497
)
498498
if save_weights is True:
499499
weights_training[i_var, j_tau] = weights_temp.reshape(
500-
(num_epochs + 1 + langevin_steps, self.num_variables, embedding_dim_present)
500+
(num_epochs + 1 + langevin_steps + langevin_steps, self.num_variables, embedding_dim_present)
501501
)
502502

503503
self.weights_final = weights_final

dadapy/diff_imbalance.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def __init__(
181181
learning_rate=1e-2,
182182
learning_rate_decay=None,
183183
num_points_rows=None,
184+
gradient_clip_value=0.0,
184185
early_stopping=0,
185186
):
186187
"""Initialise the DiffImbalance class."""
@@ -1635,7 +1636,7 @@ def backward_greedy_feature_selection(
16351636
print("------------------------------------------------")
16361637

16371638
return feature_sets, diis, errors, best_weights_list
1638-
1639+
16391640
def langevin(self, initial_params, n_epochs=1000, batch_size=100, noise=0):
16401641
"""
16411642
We consider Langevin dynamics as a method to estimate an error of the parameters
@@ -1700,4 +1701,4 @@ def langevin(self, initial_params, n_epochs=1000, batch_size=100, noise=0):
17001701
imbs_langevin = imbs_langevin.at[epoch_idx].set(imb_now)
17011702

17021703
return np.array(params_langevin), np.array(imbs_langevin)
1703-
1704+

0 commit comments

Comments
 (0)