tigramite-fast 5.2.10.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tigramite/__init__.py +0 -0
- tigramite/causal_effects.py +1525 -0
- tigramite/causal_mediation.py +1592 -0
- tigramite/data_processing.py +1574 -0
- tigramite/graphs.py +1509 -0
- tigramite/independence_tests/LBFGS.py +1114 -0
- tigramite/independence_tests/__init__.py +0 -0
- tigramite/independence_tests/cmiknn.py +661 -0
- tigramite/independence_tests/cmiknn_mixed.py +1397 -0
- tigramite/independence_tests/cmisymb.py +286 -0
- tigramite/independence_tests/gpdc.py +664 -0
- tigramite/independence_tests/gpdc_torch.py +820 -0
- tigramite/independence_tests/gsquared.py +190 -0
- tigramite/independence_tests/independence_tests_base.py +1310 -0
- tigramite/independence_tests/oracle_conditional_independence.py +1582 -0
- tigramite/independence_tests/pairwise_CI.py +383 -0
- tigramite/independence_tests/parcorr.py +369 -0
- tigramite/independence_tests/parcorr_mult.py +485 -0
- tigramite/independence_tests/parcorr_wls.py +451 -0
- tigramite/independence_tests/regressionCI.py +403 -0
- tigramite/independence_tests/robust_parcorr.py +403 -0
- tigramite/jpcmciplus.py +966 -0
- tigramite/lpcmci.py +3649 -0
- tigramite/models.py +2257 -0
- tigramite/pcmci.py +3935 -0
- tigramite/pcmci_base.py +1218 -0
- tigramite/plotting.py +4735 -0
- tigramite/rpcmci.py +467 -0
- tigramite/toymodels/__init__.py +0 -0
- tigramite/toymodels/context_model.py +261 -0
- tigramite/toymodels/non_additive.py +1231 -0
- tigramite/toymodels/structural_causal_processes.py +1201 -0
- tigramite/toymodels/surrogate_generator.py +319 -0
- tigramite_fast-5.2.10.1.dist-info/METADATA +182 -0
- tigramite_fast-5.2.10.1.dist-info/RECORD +38 -0
- tigramite_fast-5.2.10.1.dist-info/WHEEL +5 -0
- tigramite_fast-5.2.10.1.dist-info/licenses/license.txt +621 -0
- tigramite_fast-5.2.10.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"""Tigramite toymodels."""
|
|
2
|
+
|
|
3
|
+
# Author: Jakob Runge <jakob@jakob-runge.com>
|
|
4
|
+
#
|
|
5
|
+
# License: GNU General Public License v3.0
|
|
6
|
+
from __future__ import print_function
|
|
7
|
+
import sys
|
|
8
|
+
import warnings
|
|
9
|
+
import copy
|
|
10
|
+
import math
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
from tigramite.toymodels import structural_causal_processes as toys
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def generate_linear_model_from_data(dataframe, parents, tau_max, realizations=100,
|
|
18
|
+
generate_noise_from='covariance',
|
|
19
|
+
T_data = None,
|
|
20
|
+
model_params=None,
|
|
21
|
+
data_transform=None,
|
|
22
|
+
mask_type='y',
|
|
23
|
+
boot_blocklength=1,
|
|
24
|
+
seed=42,
|
|
25
|
+
verbosity=0):
|
|
26
|
+
"""
|
|
27
|
+
Fits a (contemporaneous and lagged) linear SCM to data, computes
|
|
28
|
+
residuals, and then generates surrogate realizations with noise drawn
|
|
29
|
+
with replacement from residuals or from a multivariate normal.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
generate_noise_from : {'covariance', 'residuals'}
|
|
34
|
+
Whether to generate the noise from a gaussian with same mean and covariance
|
|
35
|
+
as residuals, or by drawing (with replacement) from the residuals.
|
|
36
|
+
boot_blocklength : int, or in {'cube_root', 'from_autocorrelation'}
|
|
37
|
+
Block length for block-bootstrap, which only applies to
|
|
38
|
+
generate_noise_from='residuals'. If 'from_autocorrelation', the block
|
|
39
|
+
length is determined from the decay of the autocovariance and
|
|
40
|
+
if 'cube_root' it is the cube root of the time series length.
|
|
41
|
+
seed : int, optional(default = None)
|
|
42
|
+
Seed for RandomState (default_rng)
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
from tigramite.models import Models
|
|
46
|
+
from sklearn.linear_model import LinearRegression
|
|
47
|
+
|
|
48
|
+
assert dataframe.analysis_mode == 'single'
|
|
49
|
+
|
|
50
|
+
random_state = np.random.default_rng(seed)
|
|
51
|
+
|
|
52
|
+
def lin_f(x): return x
|
|
53
|
+
|
|
54
|
+
if model_params is None:
|
|
55
|
+
model_params = {}
|
|
56
|
+
|
|
57
|
+
N = dataframe.N
|
|
58
|
+
T = dataframe.T[0]
|
|
59
|
+
if T_data is None:
|
|
60
|
+
T_data = T
|
|
61
|
+
|
|
62
|
+
## Estimate noise covariance matrix of residuals
|
|
63
|
+
model = Models(dataframe=dataframe,
|
|
64
|
+
model=LinearRegression(**model_params),
|
|
65
|
+
data_transform=data_transform,
|
|
66
|
+
mask_type='y',
|
|
67
|
+
verbosity=0)
|
|
68
|
+
|
|
69
|
+
model.fit_full_model(all_parents=parents, tau_max=tau_max, return_data=True)
|
|
70
|
+
|
|
71
|
+
links_coeffs = {}
|
|
72
|
+
for j in range(N):
|
|
73
|
+
links_coeffs[j] = []
|
|
74
|
+
if len(parents[j]) > 0:
|
|
75
|
+
for ipar, par in enumerate(parents[j]):
|
|
76
|
+
links_coeffs[j].append(((par[0], int(par[1])), model.fit_results[j]['model'].coef_[ipar], lin_f))
|
|
77
|
+
if verbosity > 0:
|
|
78
|
+
print(j, ((par[0], int(par[1])), np.round(model.fit_results[j]['model'].coef_[ipar], 2),) )
|
|
79
|
+
|
|
80
|
+
pred = model.predict_full_model(
|
|
81
|
+
new_data=None,
|
|
82
|
+
pred_params=None,
|
|
83
|
+
cut_off='max_lag_or_tau_max')
|
|
84
|
+
|
|
85
|
+
# Computes cov and mean, but internally also the residuals needed here
|
|
86
|
+
cov, mean = model.get_residuals_cov_mean(new_data=None,
|
|
87
|
+
pred_params=None,)
|
|
88
|
+
|
|
89
|
+
if generate_noise_from == 'covariance':
|
|
90
|
+
# cov = np.cov(overlapping_residuals, rowvar=0)
|
|
91
|
+
# mean = np.mean(overlapping_residuals, axis=0) # residuals should have zero mean due to prediction including constant
|
|
92
|
+
if verbosity > 0:
|
|
93
|
+
print('covariance')
|
|
94
|
+
print(np.round(cov, 2))
|
|
95
|
+
print('mean')
|
|
96
|
+
print(np.round(mean, 2))
|
|
97
|
+
|
|
98
|
+
overlapping_residuals = model.residuals
|
|
99
|
+
len_residuals = len(overlapping_residuals)
|
|
100
|
+
|
|
101
|
+
## Construct linear Gaussian structural causal model with this noise structure and generate many realizations with same sample size as data
|
|
102
|
+
transient_fraction = 0.2
|
|
103
|
+
size = T_data + int(math.floor(transient_fraction*T_data))
|
|
104
|
+
# datasets = {}
|
|
105
|
+
|
|
106
|
+
if generate_noise_from == 'residuals':
|
|
107
|
+
if boot_blocklength == 'cube_root':
|
|
108
|
+
boot_blocklength = max(1, int(T_data**(1/3)))
|
|
109
|
+
elif boot_blocklength == 'from_autocorrelation':
|
|
110
|
+
boot_blocklength = \
|
|
111
|
+
get_block_length(overlapping_residuals.T, xyz=np.zeros(N), mode='confidence')
|
|
112
|
+
elif type(boot_blocklength) is int and boot_blocklength > 0:
|
|
113
|
+
pass
|
|
114
|
+
else:
|
|
115
|
+
raise ValueError("boot_blocklength must be integer > 0, 'cube_root', or 'from_autocorrelation'")
|
|
116
|
+
|
|
117
|
+
# Determine the number of blocks total, rounding up for non-integer
|
|
118
|
+
# amounts
|
|
119
|
+
n_blks = int(math.ceil(float(size) / boot_blocklength))
|
|
120
|
+
if n_blks < 10:
|
|
121
|
+
raise ValueError("Only %d block(s) for block-sampling," %n_blks +
|
|
122
|
+
"choose smaller boot_blocklength!")
|
|
123
|
+
|
|
124
|
+
for r in range(realizations):
|
|
125
|
+
if generate_noise_from == 'covariance':
|
|
126
|
+
noises = random_state.multivariate_normal(mean=mean, cov=cov, size=size)
|
|
127
|
+
elif generate_noise_from == 'residuals':
|
|
128
|
+
|
|
129
|
+
# Get the starting indices for the blocks
|
|
130
|
+
blk_strt = random_state.choice(np.arange(len_residuals - boot_blocklength),
|
|
131
|
+
size=n_blks, replace=True)
|
|
132
|
+
|
|
133
|
+
# Get the empty array of block resampled values
|
|
134
|
+
boot_draw = np.zeros(n_blks*boot_blocklength, dtype='int')
|
|
135
|
+
# Fill the array of block resamples
|
|
136
|
+
for i in range(boot_blocklength):
|
|
137
|
+
boot_draw[i::boot_blocklength] = np.arange(size)[blk_strt + i]
|
|
138
|
+
# Cut to proper length
|
|
139
|
+
draw = boot_draw[:size]
|
|
140
|
+
# draw = np.random.randint(0, len(overlapping_residuals), size)
|
|
141
|
+
noises = overlapping_residuals[draw]
|
|
142
|
+
|
|
143
|
+
else: raise ValueError("generate_noise_from has to be either 'covariance' or 'residuals'")
|
|
144
|
+
|
|
145
|
+
dataset = toys.structural_causal_process(links=links_coeffs, noises=noises, T=T_data,
|
|
146
|
+
transient_fraction=transient_fraction)[0]
|
|
147
|
+
if np.any(np.isinf(dataset)):
|
|
148
|
+
raise ValueError("Infinite data")
|
|
149
|
+
|
|
150
|
+
yield dataset
|
|
151
|
+
|
|
152
|
+
# return self #datasets
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def get_acf(series, max_lag=None):
|
|
156
|
+
"""Returns autocorrelation function.
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
----------
|
|
160
|
+
series : 1D-array
|
|
161
|
+
data series to compute autocorrelation from
|
|
162
|
+
|
|
163
|
+
max_lag : int, optional (default: None)
|
|
164
|
+
maximum lag for autocorrelation function. If None is passed, 10% of
|
|
165
|
+
the data series length are used.
|
|
166
|
+
|
|
167
|
+
Returns
|
|
168
|
+
-------
|
|
169
|
+
autocorr : array of shape (max_lag + 1,)
|
|
170
|
+
Autocorrelation function.
|
|
171
|
+
"""
|
|
172
|
+
# Set the default max lag
|
|
173
|
+
if max_lag is None:
|
|
174
|
+
max_lag = int(max(5, 0.1*len(series)))
|
|
175
|
+
# Initialize the result
|
|
176
|
+
autocorr = np.ones(max_lag + 1)
|
|
177
|
+
# Iterate over possible lags
|
|
178
|
+
for lag in range(1, max_lag + 1):
|
|
179
|
+
# Set the values
|
|
180
|
+
y1_vals = series[lag:]
|
|
181
|
+
y2_vals = series[:len(series) - lag]
|
|
182
|
+
# Calculate the autocorrelation
|
|
183
|
+
autocorr[lag] = np.corrcoef(y1_vals, y2_vals)[0, 1]
|
|
184
|
+
return autocorr
|
|
185
|
+
|
|
186
|
+
def get_block_length(array, xyz, mode):
|
|
187
|
+
"""Returns optimal block length for significance and confidence tests.
|
|
188
|
+
|
|
189
|
+
Determine block length using approach in Mader (2013) [Eq. (6)] which
|
|
190
|
+
improves the method of Pfeifer (2005) with non-overlapping blocks In
|
|
191
|
+
case of multidimensional X, the max is used. Further details in [1]_.
|
|
192
|
+
Two modes are available. For mode='significance', only the indices
|
|
193
|
+
corresponding to X are shuffled in array. For mode='confidence' all
|
|
194
|
+
variables are jointly shuffled. If the autocorrelation curve fit fails,
|
|
195
|
+
a block length of 5% of T is used. The block length is limited to a
|
|
196
|
+
maximum of 10% of T.
|
|
197
|
+
|
|
198
|
+
Mader et al., Journal of Neuroscience Methods,
|
|
199
|
+
Volume 219, Issue 2, 15 October 2013, Pages 285-291
|
|
200
|
+
|
|
201
|
+
Parameters
|
|
202
|
+
----------
|
|
203
|
+
array : array-like
|
|
204
|
+
data array with X, Y, Z in rows and observations in columns
|
|
205
|
+
|
|
206
|
+
xyz : array of ints
|
|
207
|
+
XYZ identifier array of shape (dim,).
|
|
208
|
+
|
|
209
|
+
mode : str
|
|
210
|
+
Which mode to use.
|
|
211
|
+
|
|
212
|
+
Returns
|
|
213
|
+
-------
|
|
214
|
+
block_len : int
|
|
215
|
+
Optimal block length.
|
|
216
|
+
"""
|
|
217
|
+
# Inject a dependency on siganal, optimize
|
|
218
|
+
from scipy import signal, optimize
|
|
219
|
+
# Get the shape of the array
|
|
220
|
+
dim, T = array.shape
|
|
221
|
+
# Initiailize the indices
|
|
222
|
+
indices = range(dim)
|
|
223
|
+
if mode == 'significance':
|
|
224
|
+
indices = np.where(xyz == 0)[0]
|
|
225
|
+
|
|
226
|
+
# Maximum lag for autocov estimation
|
|
227
|
+
max_lag = int(0.1*T)
|
|
228
|
+
# Define the function to optimize against
|
|
229
|
+
def func(x_vals, a_const, decay):
|
|
230
|
+
return a_const * decay**x_vals
|
|
231
|
+
|
|
232
|
+
# Calculate the block length
|
|
233
|
+
block_len = 1
|
|
234
|
+
for i in indices:
|
|
235
|
+
# Get decay rate of envelope of autocorrelation functions
|
|
236
|
+
# via hilbert trafo
|
|
237
|
+
autocov = get_acf(series=array[i], max_lag=max_lag)
|
|
238
|
+
autocov[0] = 1.
|
|
239
|
+
hilbert = np.abs(signal.hilbert(autocov))
|
|
240
|
+
# Try to fit the curve
|
|
241
|
+
try:
|
|
242
|
+
popt, _ = optimize.curve_fit(
|
|
243
|
+
f=func,
|
|
244
|
+
xdata=np.arange(0, max_lag+1),
|
|
245
|
+
ydata=hilbert,
|
|
246
|
+
)
|
|
247
|
+
phi = popt[1]
|
|
248
|
+
# Formula of Mader (2013) assuming non-overlapping blocks
|
|
249
|
+
l_opt = (4. * T * (phi / (1. - phi) + phi**2 / (1. - phi)**2)**2
|
|
250
|
+
/ (1. + 2. * phi / (1. - phi))**2)**(1. / 3.)
|
|
251
|
+
block_len = max(block_len, int(l_opt))
|
|
252
|
+
|
|
253
|
+
# pylab.plot(np.arange(0, max_lag+1), hilbert)
|
|
254
|
+
# pylab.plot(np.arange(0, max_lag+1), func(np.arange(0, max_lag+1), popt[0], popt[1]))
|
|
255
|
+
# print("block_len ", block_len, int(l_opt))
|
|
256
|
+
# pylab.show()
|
|
257
|
+
except RuntimeError:
|
|
258
|
+
warnings.warn("Error - curve_fit failed for estimating block_shuffle length, using"
|
|
259
|
+
" block_len = %d" % (int(.05 * T)))
|
|
260
|
+
# block_len = max(int(.05 * T), block_len)
|
|
261
|
+
|
|
262
|
+
# print("chosen ", block_len)
|
|
263
|
+
# Limit block length to a maximum of 10% of T
|
|
264
|
+
block_len = min(block_len, int(0.1 * T))
|
|
265
|
+
# print("chosen ", block_len)
|
|
266
|
+
|
|
267
|
+
return block_len
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
if __name__ == '__main__':
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
import tigramite
|
|
274
|
+
from tigramite import data_processing as pp
|
|
275
|
+
|
|
276
|
+
lin_f = lambda x: x
|
|
277
|
+
links_coeffs = {0: [((0, -1), 0.98, lin_f), ((0, -2), -0.7, lin_f)],
|
|
278
|
+
1: [((1, -1), 0.9, lin_f), ((0, -1), 0.3, lin_f)],
|
|
279
|
+
2: [((2, -1), 0.9, lin_f), ((0, -2), -0.5, lin_f)],
|
|
280
|
+
3: [((3, -1), 0.9, lin_f)], #, ((4, -1), 0.4, lin_f)],
|
|
281
|
+
4: [((4, -1), 0.9, lin_f), ((3, 0), 0.5, lin_f)], #, ((3, -1), 0.3, lin_f)],
|
|
282
|
+
}
|
|
283
|
+
T = 50 # time series length
|
|
284
|
+
# Make some noise with different variance, alternatively just noises=None
|
|
285
|
+
noises = None # np.array([(1. + 0.2*float(j))*np.random.randn((T + int(math.floor(0.2*T))))
|
|
286
|
+
# for j in range(len(links_coeffs))]).T
|
|
287
|
+
|
|
288
|
+
data, _ = toys.structural_causal_process(links_coeffs, T=T, noises=noises)
|
|
289
|
+
T, N = data.shape
|
|
290
|
+
|
|
291
|
+
# For generality, we include some masking
|
|
292
|
+
mask = np.zeros(data.shape, dtype='int')
|
|
293
|
+
mask[:int(T/2),0] = True
|
|
294
|
+
# mask[int(T/2)+30:,1] = True
|
|
295
|
+
# Create some missing samples at different time points
|
|
296
|
+
data[11,0] = 9999.
|
|
297
|
+
data[22,2] = 9999.
|
|
298
|
+
data[33,3] = 9999.
|
|
299
|
+
|
|
300
|
+
tau_max = 4
|
|
301
|
+
# Initialize dataframe object, specify time axis and variable names
|
|
302
|
+
var_names = [r'$X^0$', r'$X^1$', r'$X^2$', r'$X^3$', r'$X^4$']
|
|
303
|
+
dataframe = pp.DataFrame(data,
|
|
304
|
+
mask=mask,
|
|
305
|
+
missing_flag = 9999.,
|
|
306
|
+
datatime = {0:np.arange(len(data))},
|
|
307
|
+
var_names=var_names)
|
|
308
|
+
parents = {}
|
|
309
|
+
for j in links_coeffs:
|
|
310
|
+
parents[j] = []
|
|
311
|
+
for par in links_coeffs[j]:
|
|
312
|
+
parents[j].append(par[0])
|
|
313
|
+
print(parents)
|
|
314
|
+
datasets = list(generate_linear_model_from_data(dataframe, parents=parents,
|
|
315
|
+
tau_max=tau_max, realizations=100,
|
|
316
|
+
generate_noise_from='residuals',
|
|
317
|
+
boot_blocklength=3, #'from_autocorrelation',
|
|
318
|
+
verbosity=0))
|
|
319
|
+
print(datasets[0].shape)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tigramite-fast
|
|
3
|
+
Version: 5.2.10.1
|
|
4
|
+
Summary: Tigramite causal inference for time series
|
|
5
|
+
Home-page: https://github.com/jakobrunge/tigramite/
|
|
6
|
+
Author: Jakob Runge
|
|
7
|
+
Author-email: jakob@jakob-runge.com
|
|
8
|
+
License: GNU General Public License v3.0
|
|
9
|
+
Keywords: causal inference,causal discovery,prediction,time series
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
14
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: license.txt
|
|
18
|
+
Requires-Dist: numpy>=1.18
|
|
19
|
+
Requires-Dist: scipy>=1.10.0
|
|
20
|
+
Requires-Dist: six
|
|
21
|
+
Provides-Extra: all
|
|
22
|
+
Requires-Dist: scikit-learn>=1.2; extra == "all"
|
|
23
|
+
Requires-Dist: matplotlib>=3.7.0; extra == "all"
|
|
24
|
+
Requires-Dist: seaborn>=0.12.2; extra == "all"
|
|
25
|
+
Requires-Dist: networkx>=3.0; extra == "all"
|
|
26
|
+
Requires-Dist: torch>=1.13.1; extra == "all"
|
|
27
|
+
Requires-Dist: gpytorch>=1.9.1; extra == "all"
|
|
28
|
+
Requires-Dist: dcor>=0.6; extra == "all"
|
|
29
|
+
Requires-Dist: joblib>=1.2.0; extra == "all"
|
|
30
|
+
Requires-Dist: ortools>=9.2; extra == "all"
|
|
31
|
+
Requires-Dist: numba>=0.58; extra == "all"
|
|
32
|
+
Provides-Extra: test
|
|
33
|
+
Requires-Dist: nose; extra == "test"
|
|
34
|
+
Requires-Dist: pytest; extra == "test"
|
|
35
|
+
Requires-Dist: networkx>=3.0; extra == "test"
|
|
36
|
+
Requires-Dist: scikit-learn>=1.2; extra == "test"
|
|
37
|
+
Requires-Dist: pytorch>=1.13.1; extra == "test"
|
|
38
|
+
Requires-Dist: gpytorch>=1.9.1; extra == "test"
|
|
39
|
+
Requires-Dist: dcor>=0.6; extra == "test"
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: scikit-learn>=1.2; extra == "dev"
|
|
42
|
+
Requires-Dist: matplotlib>=3.7.0; extra == "dev"
|
|
43
|
+
Requires-Dist: seaborn>=0.12.2; extra == "dev"
|
|
44
|
+
Requires-Dist: networkx>=3.0; extra == "dev"
|
|
45
|
+
Requires-Dist: torch>=1.13.1; extra == "dev"
|
|
46
|
+
Requires-Dist: gpytorch>=1.9.1; extra == "dev"
|
|
47
|
+
Requires-Dist: dcor>=0.6; extra == "dev"
|
|
48
|
+
Requires-Dist: joblib>=1.2.0; extra == "dev"
|
|
49
|
+
Requires-Dist: ortools>=9.2; extra == "dev"
|
|
50
|
+
Requires-Dist: numba>=0.58; extra == "dev"
|
|
51
|
+
Dynamic: author
|
|
52
|
+
Dynamic: author-email
|
|
53
|
+
Dynamic: classifier
|
|
54
|
+
Dynamic: description
|
|
55
|
+
Dynamic: description-content-type
|
|
56
|
+
Dynamic: home-page
|
|
57
|
+
Dynamic: keywords
|
|
58
|
+
Dynamic: license
|
|
59
|
+
Dynamic: license-file
|
|
60
|
+
Dynamic: provides-extra
|
|
61
|
+
Dynamic: requires-dist
|
|
62
|
+
Dynamic: summary
|
|
63
|
+
|
|
64
|
+
# Tigramite – Causal inference for time series datasets
|
|
65
|
+

|
|
66
|
+
Version 5.2
|
|
67
|
+
(Python Package)
|
|
68
|
+
|
|
69
|
+
[Github](https://github.com/jakobrunge/tigramite.git)
|
|
70
|
+
|
|
71
|
+
[Documentation](https://jakobrunge.github.io/tigramite/)
|
|
72
|
+
|
|
73
|
+
[Tutorials](https://github.com/jakobrunge/tigramite/tree/master/tutorials/)
|
|
74
|
+
|
|
75
|
+
## Overview
|
|
76
|
+
|
|
77
|
+
It's best to start with our [Overview/review paper: Causal inference for time series](https://github.com/jakobrunge/tigramite/blob/master/tutorials/Runge_Causal_Inference_for_Time_Series_NREE.pdf)
|
|
78
|
+
|
|
79
|
+
__Update:__ Tigramite now has a new CausalEffects class that allows to estimate (conditional) causal effects and mediation based on assuming a causal graph. Have a look at the tutorial.
|
|
80
|
+
|
|
81
|
+
Further, Tigramite provides several causal discovery methods that can be used under different sets of assumptions. An application always consists of a method and a chosen conditional independence test, e.g. PCMCIplus together with ParCorr. The following two tables give an overview of the assumptions involved:
|
|
82
|
+
|
|
83
|
+
| Method | Assumptions | Output |
|
|
84
|
+
| :-- | :-- | :-- |
|
|
85
|
+
| | (in addition to Causal Markov Condition and Faithfulness) | |
|
|
86
|
+
| PCMCI | Causal stationarity, no contemporaneous causal links, no hidden variables | Directed lagged links, undirected contemporaneous links (for tau_min=0) |
|
|
87
|
+
| PCMCIplus | Causal stationarity, no hidden variables | Directed lagged links, directed and undirected contemp. links (Time series CPDAG) |
|
|
88
|
+
| LPCMCI | Causal stationarity | Time series PAG |
|
|
89
|
+
| RPCMCI | No contemporaneous causal links, no hidden variables | Regime-variable and causal graphs for each regime with directed lagged links, undirected contemporaneous links (for tau_min=0) |
|
|
90
|
+
| J-PCMCI+ | Multiple datasets, causal stationarity, no hidden system confounding, except if context-related | Directed lagged links, directed and undirected contemp. links (Joint time series CPDAG) |
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
| Conditional independence test | Assumptions |
|
|
94
|
+
| :-- | :-- |
|
|
95
|
+
| ParCorr | univariate, continuous variables with linear dependencies and Gaussian noise |
|
|
96
|
+
| RobustParCorr | univariate, continuous variables with linear dependencies, robust for different marginal distributions |
|
|
97
|
+
| ParCorrWLS | univariate, continuous variables with linear dependencies, can account for heteroskedastic data |
|
|
98
|
+
| GPDC / GPDCtorch | univariate, continuous variables with additive dependencies |
|
|
99
|
+
| CMIknn | multivariate, continuous variables with more general dependencies (permutation-based test) |
|
|
100
|
+
| Gsquared | univariate discrete/categorical variables |
|
|
101
|
+
| CMIsymb | multivariate discrete/categorical variables (permutation-based test) |
|
|
102
|
+
| RegressionCI | mixed datasets with univariate discrete/categorical and (linear) continuous variables |
|
|
103
|
+
| CMIknnMixed | mixed datasets with multivariate discr./cat./cont. variables with more general dependencies (permutation-based test) |
|
|
104
|
+
|
|
105
|
+
Remark: With the conditional independence test wrapper class PairwiseMultCI you can turn every univariate test into a multivariate test.
|
|
106
|
+
|
|
107
|
+
## General Notes
|
|
108
|
+
|
|
109
|
+
Tigramite is a causal inference for time series python package. It allows to efficiently estimate causal graphs from high-dimensional time series datasets (causal discovery) and to use graphs for robust forecasting and the estimation and prediction of direct, total, and mediated effects. Causal discovery is based on linear as well as non-parametric conditional independence tests applicable to discrete or continuously-valued time series. Also includes functions for high-quality plots of the results. Please cite the following papers depending on which method you use:
|
|
110
|
+
|
|
111
|
+
- Overview: Runge, J., Gerhardus, A., Varando, G. et al. Causal inference for time series. Nat Rev Earth Environ (2023). https://doi.org/10.1038/s43017-023-00431-y
|
|
112
|
+
|
|
113
|
+
- PCMCI: J. Runge, P. Nowack, M. Kretschmer, S. Flaxman, D. Sejdinovic, Detecting and quantifying causal associations in large nonlinear time series datasets. Sci. Adv. 5, eaau4996 (2019). https://advances.sciencemag.org/content/5/11/eaau4996
|
|
114
|
+
- PCMCI+: J. Runge (2020): Discovering contemporaneous and lagged causal relations in autocorrelated nonlinear time series datasets. Proceedings of the 36th Conference on Uncertainty in Artificial Intelligence, UAI 2020,Toronto, Canada, 2019, AUAI Press, 2020. http://auai.org/uai2020/proceedings/579_main_paper.pdf
|
|
115
|
+
- LPCMCI: Gerhardus, A. & Runge, J. High-recall causal discovery for autocorrelated time series with latent confounders Advances in Neural Information Processing Systems, 2020, 33. https://proceedings.neurips.cc/paper/2020/hash/94e70705efae423efda1088614128d0b-Abstract.html
|
|
116
|
+
- RPCMCI: Elena Saggioro, Jana de Wiljes, Marlene Kretschmer, Jakob Runge; Reconstructing regime-dependent causal relationships from observational time series. Chaos 1 November 2020; 30 (11): 113115. https://doi.org/10.1063/5.0020538
|
|
117
|
+
- Generally: J. Runge (2018): Causal Network Reconstruction from Time Series: From Theoretical Assumptions to Practical Estimation. Chaos: An Interdisciplinary Journal of Nonlinear Science 28 (7): 075310. https://aip.scitation.org/doi/10.1063/1.5025050
|
|
118
|
+
- Nature Communications Perspective paper: https://www.nature.com/articles/s41467-019-10105-3
|
|
119
|
+
- Mediation class: J. Runge et al. (2015): Identifying causal gateways and mediators in complex spatio-temporal systems. Nature Communications, 6, 8502. http://doi.org/10.1038/ncomms9502
|
|
120
|
+
- Mediation class: J. Runge (2015): Quantifying information transfer and mediation along causal pathways in complex systems. Phys. Rev. E, 92(6), 62829. http://doi.org/10.1103/PhysRevE.92.062829
|
|
121
|
+
- CMIknn: J. Runge (2018): Conditional Independence Testing Based on a Nearest-Neighbor Estimator of Conditional Mutual Information. In Proceedings of the 21st International Conference on Artificial Intelligence and Statistics. http://proceedings.mlr.press/v84/runge18a.html
|
|
122
|
+
- CausalEffects: J. Runge, Necessary and sufficient graphical conditions for optimal adjustment sets in causal graphical models with hidden variables, Advances in Neural Information Processing Systems, 2021, 34. https://proceedings.neurips.cc/paper/2021/hash/8485ae387a981d783f8764e508151cd9-Abstract.html
|
|
123
|
+
- CMIknnMixed: Oana-Iuliana Popescu, Andreas Gerhardus, Martin Rabel, Jakob Runge (2024), submitted to CLEAR 2025, https://arxiv.org/abs/2310.11132
|
|
124
|
+
|
|
125
|
+
## Features
|
|
126
|
+
|
|
127
|
+
- flexible conditional independence test statistics adapted to
|
|
128
|
+
continuously-valued, discrete and mixed data, and different assumptions about
|
|
129
|
+
linear or nonlinear dependencies
|
|
130
|
+
- handling of missing values and masks
|
|
131
|
+
- p-value correction and (bootstrap) confidence interval estimation
|
|
132
|
+
- causal effect class to non-parametrically estimate (conditional) causal effects and also linear mediated causal effects
|
|
133
|
+
- prediction class based on sklearn models including causal feature selection
|
|
134
|
+
|
|
135
|
+
## Required python packages
|
|
136
|
+
|
|
137
|
+
- python>=3.10
|
|
138
|
+
- numpy>=1.18
|
|
139
|
+
- scipy>=1.10.0
|
|
140
|
+
- numba>=0.56.4
|
|
141
|
+
|
|
142
|
+
## Optional packages depending on used functions
|
|
143
|
+
- scikit-learn>=1.2 # Gaussian Process (GP) Regression
|
|
144
|
+
- matplotlib>=3.7.0 # Plotting
|
|
145
|
+
- seaborn>=0.12.2 # Plotting
|
|
146
|
+
- networkx>=3.0 # Plotting
|
|
147
|
+
- torch>=1.13.1 # GPDC pytorch version (in conda install pytorch)
|
|
148
|
+
- gpytorch>=1.9.1 # GPDC gpytorch version
|
|
149
|
+
- dcor>=0.6 # GPDC distance correlation version
|
|
150
|
+
- joblib>=1.2.0 # CMIsymb shuffle parallelization
|
|
151
|
+
- ortools>=9.2 # RPCMCI
|
|
152
|
+
|
|
153
|
+
## Installation
|
|
154
|
+
|
|
155
|
+
python setup.py install
|
|
156
|
+
|
|
157
|
+
This will install tigramite in your path.
|
|
158
|
+
|
|
159
|
+
To use just the ParCorr, CMIknn, and CMIsymb independence tests, only numpy/numba and scipy are required. For other independence tests more packages are required:
|
|
160
|
+
|
|
161
|
+
- GPDC: scikit-learn is required for Gaussian Process regression and dcor for distance correlation
|
|
162
|
+
|
|
163
|
+
- GPDCtorch: gpytorch is required for Gaussian Process regression
|
|
164
|
+
|
|
165
|
+
Note: Due to incompatibility issues between numba and numpy, we currently enforce soft dependencies on the versions.
|
|
166
|
+
|
|
167
|
+
## User Agreement
|
|
168
|
+
|
|
169
|
+
By downloading TIGRAMITE you agree with the following points: TIGRAMITE is provided without any warranty or conditions of any kind. We assume no responsibility for errors or omissions in the results and interpretations following from application of TIGRAMITE.
|
|
170
|
+
|
|
171
|
+
You commit to cite above papers in your reports or publications.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
Copyright (C) 2014-2025 Jakob Runge
|
|
177
|
+
|
|
178
|
+
See license.txt for full text.
|
|
179
|
+
|
|
180
|
+
GNU General Public License v3.0
|
|
181
|
+
|
|
182
|
+
TIGRAMITE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. TIGRAMITE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
tigramite/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
tigramite/causal_effects.py,sha256=yCEezbLmo5sMA0HOv2aCGHvpFjvQ_ocN8SGxZbbq1no,58582
|
|
3
|
+
tigramite/causal_mediation.py,sha256=u2749xbiq2KIwnVqheBP3Prd6TDmXNpk8ZHceX9E-Wg,71024
|
|
4
|
+
tigramite/data_processing.py,sha256=Wb15aVRaqx93TpDrkOYbetg_k3z_2EMUtoQLveKnGPM,66977
|
|
5
|
+
tigramite/graphs.py,sha256=-b3ePCEFgDVopU15iomSoF7PkpW1qPIb0fOCxNYpKtc,60541
|
|
6
|
+
tigramite/jpcmciplus.py,sha256=BfKlkUDT9MFq9c5O3c-yHINVKVd9PPGOnaB7lw24AeE,49043
|
|
7
|
+
tigramite/lpcmci.py,sha256=uet3oN3NyIg5frqhF2yoiggp9AShv7FVT_ke0h_30TE,173012
|
|
8
|
+
tigramite/models.py,sha256=M_oEDyu33RYw7hDAZK2jjoKAOuS66Ja9OQ1iC3yIM2E,87465
|
|
9
|
+
tigramite/pcmci.py,sha256=qJe-HxB0bvsyFQ8oqCn4dfPy9z6Y2WOVJHlY_Vz7Alw,175905
|
|
10
|
+
tigramite/pcmci_base.py,sha256=gscRFLi55yNw1CSCGGJawYE82eWnDhwDe0E7B-3mdM0,52292
|
|
11
|
+
tigramite/plotting.py,sha256=-tga5nOnMawHpCsg40dsbq9321i0kNjSPx4UYYt5THQ,170061
|
|
12
|
+
tigramite/rpcmci.py,sha256=vEEdKy4u6Xx55DkFdY_pmYxu8xi8HfLI0yKCD6WeVI0,19620
|
|
13
|
+
tigramite/independence_tests/LBFGS.py,sha256=B1SDZp23qHBIz2pvUJaHGqlNk5MS0rxjnKFx7MyqlqA,43660
|
|
14
|
+
tigramite/independence_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
tigramite/independence_tests/cmiknn.py,sha256=9JRtRszMSuIxtutdJcTBQBqyL36UBsk1Zaflb1sk3G4,25263
|
|
16
|
+
tigramite/independence_tests/cmiknn_mixed.py,sha256=NxmRN0IxW5tInwDF5qfSpI2_0TaPbC3aeUkQYHxapXo,56741
|
|
17
|
+
tigramite/independence_tests/cmisymb.py,sha256=dmgFTAdikadnInDAQtnnTywXo8Wm0rivwZi2ybJCMjg,11050
|
|
18
|
+
tigramite/independence_tests/gpdc.py,sha256=rpWZCTbvrHaj9m7eEVH3vZj6YcgaYfPQCSNO0rwU3yc,24265
|
|
19
|
+
tigramite/independence_tests/gpdc_torch.py,sha256=DESgxrq7gY_DFTTQylC9X3FfEST47zaFGY1TKb2EQ8E,31460
|
|
20
|
+
tigramite/independence_tests/gsquared.py,sha256=YqMWhB07L-sLoxzrbaRbRHPRF1JjMkukdbAd1Wh1VGs,6559
|
|
21
|
+
tigramite/independence_tests/independence_tests_base.py,sha256=3fnTn9_bvFBOpUfBnn4mKERpOVCD0ArJj-qi4ePo4Tw,51770
|
|
22
|
+
tigramite/independence_tests/oracle_conditional_independence.py,sha256=SrrVaXdpTTYTDhTiL15WMdYl5tEvwxl30VrhjTgLR94,63379
|
|
23
|
+
tigramite/independence_tests/pairwise_CI.py,sha256=QOERKQBE7FYRVXymCz8pgK2ONZyTvHPhP4OiT_sHqR4,18271
|
|
24
|
+
tigramite/independence_tests/parcorr.py,sha256=2PrHHhVGSotyMQX4EAEEbJCySKmv9bv5C3vsG_LH_pw,12024
|
|
25
|
+
tigramite/independence_tests/parcorr_mult.py,sha256=H-1wJriPYmkRgezNxkgUmhBnw-IRTSm9cTL5rPACrJQ,16318
|
|
26
|
+
tigramite/independence_tests/parcorr_wls.py,sha256=Cv2zWsdXX7UZ_PeHVmT87lOhbpQtfi--3qnWszSs7G0,18794
|
|
27
|
+
tigramite/independence_tests/regressionCI.py,sha256=290KzuQhBkRZ_z_PM4om3yWP84B_P9ewJ9IunjjgCik,15008
|
|
28
|
+
tigramite/independence_tests/robust_parcorr.py,sha256=_u35qBXaGsF6SDx_EDEn1OV0iUN9NzpTFsfdwdDA-jI,13805
|
|
29
|
+
tigramite/toymodels/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
30
|
+
tigramite/toymodels/context_model.py,sha256=ixV7GcIxjfw8H-h2shhwVOFpQImPjtxFHNMGaGu0OFo,13239
|
|
31
|
+
tigramite/toymodels/non_additive.py,sha256=4PCyWfY6n_jkKVa49VRjzZWI235mk6EHUJyFcyQuOH4,45161
|
|
32
|
+
tigramite/toymodels/structural_causal_processes.py,sha256=y5HIlbFNdWn_cUVeFkdTxxEF-MWRWZ4GRxvY0sGEmc4,43363
|
|
33
|
+
tigramite/toymodels/surrogate_generator.py,sha256=GNRB2s9zHOktJE0uCLnc4t8DPKANyrM2VkXnjIffMGw,11942
|
|
34
|
+
tigramite_fast-5.2.10.1.dist-info/licenses/license.txt,sha256=scVEb0_a6u-SwMjZ00QjylmopLfNbR6V0AMYjbLsbPM,32453
|
|
35
|
+
tigramite_fast-5.2.10.1.dist-info/METADATA,sha256=U05ETTtXHfqcAgroJ46kDbbrwiHlI8bbjhqf6BVOTn0,11862
|
|
36
|
+
tigramite_fast-5.2.10.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
37
|
+
tigramite_fast-5.2.10.1.dist-info/top_level.txt,sha256=i9LendHtmnjM0otoYjPjyiaLR0qTHLUxr7Fam_PHamY,10
|
|
38
|
+
tigramite_fast-5.2.10.1.dist-info/RECORD,,
|