-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
101 lines (83 loc) · 3.53 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from tigramite.independence_tests.gpdc import GPDC
from causalflow.CPrinter import CPLevel
from causalflow.causal_discovery.FPCMCI import FPCMCI
from causalflow.causal_discovery.baseline.DYNOTEARS import DYNOTEARS
from causalflow.causal_discovery.baseline.VarLiNGAM import VarLiNGAM
from causalflow.causal_discovery.baseline.PCMCI import PCMCI
from causalflow.causal_discovery.baseline.TCDF import TCDF
from causalflow.causal_discovery.baseline.tsFCI import tsFCI
from causalflow.preprocessing.data import Data
from causalflow.selection_methods.TE import TE, TEestimator
from causalflow.basics.constants import LabelType
import numpy as np
if __name__ == '__main__':
f_alpha = 0.1
pcmci_alpha = 0.05
min_lag = 0
max_lag = 2
np.random.seed(1)
nsample = 500
nfeature = 5
d = np.random.random(size = (nsample, nfeature))
for t in range(max_lag, nsample):
d[t, 1] += 0.5 * d[t-1, 0]**2
d[t, 2] += 0.3 * d[t-1, 0] * 0.75 * d[t-2, 1] - 2.5
d[t, 3] += 0.7 * d[t-1, 3] * d[t-2, 4]
df = Data(d, vars = ['X_0', 'X_1', 'X_2', 'X_3', 'X_4'])
fpcmci = FPCMCI(df,
f_alpha = f_alpha,
alpha = pcmci_alpha,
min_lag = min_lag,
max_lag = max_lag,
sel_method = TE(TEestimator.Gaussian),
val_condtest = GPDC(significance = 'analytic', gp_params = None),
verbosity = CPLevel.DEBUG,
neglect_only_autodep = True)
cm = fpcmci.run()
fpcmci.dag(label_type = LabelType.Lag, node_layout = 'dot', skip_autodep=True)
fpcmci.timeseries_dag()
dynotears = DYNOTEARS(df,
min_lag = min_lag,
max_lag = max_lag,
verbosity = CPLevel.DEBUG,
alpha = pcmci_alpha,
neglect_only_autodep = True)
cm = dynotears.run()
dynotears.dag(label_type = LabelType.Lag, node_layout = 'dot', skip_autodep=True)
dynotears.timeseries_dag()
pcmci = PCMCI(df,
min_lag = min_lag,
max_lag = max_lag,
val_condtest = GPDC(significance = 'analytic', gp_params = None),
verbosity = CPLevel.DEBUG,
alpha = pcmci_alpha,
neglect_only_autodep = True)
cm = pcmci.run()
pcmci.dag(label_type = LabelType.Lag, node_layout = 'dot', skip_autodep=True)
pcmci.timeseries_dag()
tcdf = TCDF(df,
min_lag = min_lag,
max_lag = max_lag,
verbosity = CPLevel.DEBUG,
neglect_only_autodep = True)
cm = tcdf.run(cuda=True)
tcdf.dag(label_type = LabelType.Lag, node_layout = 'dot')
tcdf.timeseries_dag()
tcdf = tsFCI(df,
min_lag = min_lag,
max_lag = max_lag,
verbosity = CPLevel.DEBUG,
alpha = pcmci_alpha,
neglect_only_autodep = True)
cm = tcdf.run()
tcdf.dag(label_type = LabelType.Lag, node_layout = 'dot')
tcdf.timeseries_dag()
varlingam = VarLiNGAM(df,
min_lag = min_lag,
max_lag = max_lag,
verbosity = CPLevel.DEBUG,
alpha = pcmci_alpha,
neglect_only_autodep = True)
cm = varlingam.run()
varlingam.dag(label_type = LabelType.Lag, node_layout = 'dot')
varlingam.timeseries_dag()