cits package¶
Submodules¶
cits.methods module¶
- cits.methods.causaleff_lscm(g, data)[source]¶
Assigns weights to edges in the unrolled graph estimate of CITS algorithm
- Parameters
g (networkx.DiGraph) – Unrolled causal graph
data (nump.array) – Transformed original time series X by data_transformed function
- Returns
Adjacency matrix with (i,j) entry having the weight of causal relationship from the variable with index i \(\rightarrow\) the variable with index j in the unrolled graph g
- Return type
numpy.array
- cits.methods.cits_full(X, tau, alpha=0.05, cond_dep='cond_dep_pcorr')[source]¶
Convenient wrapper for CITS algorithm in computing the unweighted rolled graph from time series data. See cits_full_weighted to compute the weighted rolled graph.
- Parameters
X (nump.array) – pxT array for time series with p variables and T time points
tau (int) – Markovian order, in other words, maximum time delay of interaction, i.e. \(X_t\) can depend up to \(X_{t-\tau}\) and not earlier.
alpha (float) – Significance level of conditional dependence tests (default is 0.05)
cond_dep (string) – Specifies which conditional dependence test to use. It can take value ‘cond_dep_pcorr’ for Partial correlation based test suitable for Gaussian noise distribution and ‘cond_dep_hsic’ for test based on Hilbert-Schmidt criterion applicable for either Gaussian or non-Gaussian noise distributions. Partial correlation based test would be more powerful if the noise distribution is known to be Gaussian. (default is ‘cond_dep_pcorr’)
- Returns
Unweighted adjacency matrix of rolled graph
- Return type
numpy.array (shape is (p,p))
- cits.methods.cits_full_weighted(X, tau, alpha=0.05, cond_dep='cond_dep_pcorr', thresh=10)[source]¶
Convenient wrapper for CITS algorithm in computing the weighted rolled graph from time series data.
Instead, if you like to compute the unweighted rolled graph, see cits_full. Or alternatively, process the output of this current function to have non-zero edge weights indicating an edge and zero edge weights indicating no edge in the unweighted rolled graph.
- Parameters
X (nump.array) – pxT array for time series with p variables and T time points
tau (int) – Markovian order, in other words, maximum time delay of interaction, i.e. \(X_t\) can depend up to \(X_{t-\tau}\) and not earlier.
alpha (float) – Significance level of conditional dependence tests (default is 0.05)
cond_dep (string) – Specifies which conditional dependence test to use. It can take value ‘cond_dep_pcorr’ for Partial correlation based test suitable for Gaussian noise distribution and ‘cond_dep_hsic’ for test based on Hilbert-Schmidt criterion applicable for either Gaussian or non-Gaussian noise distributions. Partial correlation based test would be more powerful if the noise distribution is known to be Gaussian. (default is ‘cond_dep_pcorr’)
- Returns
Weighted adjacency matrix of rolled graph, whose (i,j) entry represents the weight of causal relationships from variable i \(\rightarrow\) variable j. A non-zero weight indicates the presence of a causal relationship and zero weight indicates its absence.
- Return type
numpy.array (shape is (p,p))
- cits.methods.cits_rolled(A, p, tau)[source]¶
Step in the CITS algorithm to transform the unrolled causal graph to rolled graph
- Parameters
p (int) – # of variables
A (numpy.array) – Adjacency matrix of unrolled graph
tau (int) – Markovian order, in other words, maximum time delay of interaction, i.e. \(X_t\) can depend up to \(X_{t-\tau}\) and not earlier.
- Returns
Adjacency matrix of rolled graph
- Return type
numpy.array
- cits.methods.cits_unrolled(X, tau, alpha=0.05, cond_dep='cond_dep_pcorr')[source]¶
Step in the CITS algorithm to estimation the unrolled causal graph step from time series data
- Parameters
X (numpy.array) – pxT array with p variables and T time points
tau (int) – Markovian order, in other words, maximum time delay of interaction, i.e. \(X_t\) can depend up to \(X_{t-\tau}\) and not earlier.
alpha (float) – Significance level of conditional dependence tests (default is 0.05)
cond_dep (string) – Specifies which conditional dependence test to use. It can take value ‘cond_dep_pcorr’ for Partial correlation based test suitable for Gaussian noise distribution and ‘cond_dep_hsic’ for test based on Hilbert-Schmidt criterion applicable for either Gaussian or non-Gaussian noise distributions. Partial correlation based test would be more powerful if the noise distribution is known to be Gaussian. (default is ‘cond_dep_pcorr’)
- Returns
Adjacency matrix of unrolled graph
- Return type
numpy.array
- cits.methods.cits_weighted_rolled(A, p, tau)[source]¶
Step in the CITS algorithm to transform the weighted unrolled causal graph to the weighted rolled graph
- Parameters
A (numpy.array) – Adjacency matrix of weighted unrolled graph
p (int) – # of variables
tau (int) – Markovian order
- Returns
Adjacency matrix of weighted rolled graph
- Return type
numpy.array
- cits.methods.cond_dep_hsic(chi, i1, j1, k, p, alpha=0.05, reps=10)[source]¶
Convenient wrapper for conditional dependence test based on Hilbert-Schmidt criterion
- cits.methods.cond_dep_pcorr(chi, i1, j1, k, p, alpha=0.05)[source]¶
Conditional dependence test based on partial correlation
- cits.methods.data_transform(X, tau)[source]¶
Transforms data X of shape (p,T) to time-windowed samples \(\chi\) of shape \((p*2*(\tau+1),N)\), where \(N = \lfloor \frac{T-2*(\tau+1)}{2*(\tau+1)} \rfloor\).
- Parameters
X (numpy.array) – pxT array with p variables and T time points
- Tau
Markovian order, in other words, maximum time delay of interaction, i.e. \(X_t\) can depend up to \(X_{t-\tau}\) and not earlier.
- Returns
Transformed dataset which is an array of shape \((p*2*(\tau+1),N)\)
- Return type
numpy.array
- cits.methods.data_transformed(X, tau)[source]¶
Transforms data X of shape (p,n) to time-windowed samples of shape \((N,p*(\tau+1))\), with an inter-sample time gap of \(\tau+1\), where \(N = \lfloor \frac{n-2*(\tau+1)}{2*(\tau+1)} \rfloor\).
- Parameters
X (numpy.array) – pxT array with p variables and T time points
tau (int) – Markovian order, in other words, maximum time delay of interaction, i.e. \(X_t\) can depend up to \(X_{t-\tau}\) and not earlier.
- Returns
Transformed dataset which is an array of shape \((N,p*(\tau+1))\)
- Return type
numpy.array
- cits.methods.hsic_condind(A, B, S, data, reps)[source]¶
Computes p-value of conditional dependence test based on Hilbert-Schmidt criterion
- cits.methods.partial_corr(A, B, S, data)[source]¶
Computes partial correlation of variables A and B given S based on data.
- Parameters
A (int) – index of one variable
B (int) – index of another variable
S (set) – indices of conditioning variables
data (numpy.array shape of data should be (# of variables, # of samples)) – Dataset with samples for the variables
- Returns
Partial correlation of A and B given S based on data
- Return type
float
cits.simulate_timeseries module¶
- cits.simulate_timeseries.simulate(model, noise, T)[source]¶
Simulate time series from different models and ground truth adjacencies for time series causal graph.
- Parameters
model (string) – Model for simulation. It take one of the these values: ‘lingauss1’ for Linear Gaussian Model 1, ‘lingauss2’ for Linear Gaussian Model 2, ‘nonlinnongauss1’ for Non-linear Non-Gaussian Model 1, ‘nonlinnongauss2’ for Non-linear Non-Gaussian Model 2, ‘ctrnn’: CTRNN
noise (float) – Noise standard deviation in the simulation
T (int) – Number of time points to have in the simulated time series
- Returns
a tuple of three numpy.array as follows. first numpy.array : Simulated time series of shape (4,T) with T time-recordings for 4 variables. second numpy.array : Grouth truth unweighted adjacency matrix: (i,j) entry represents causal influence from i->j. third numpy.array : Grouth truth weighted adjacency matrix: (i,j) entry has the strength of causal influence from i->j.
- Return type
tuple
- cits.simulate_timeseries.simulate_ctrnn(T, n_vars, w, tau, noise=1)[source]¶
Simulate a continuous time recurrent neural network (CTRNN) time series
- Parameters
T (int) – Number of time points to have in the simulated time series
n_vars (int) – Number of variables to have in the simulated time series
w (numpy.array) – Weights of the CTRNN
tau (float) – Time constant of the CTRNN
noise (float) – Noise standard deviation in the simulation
- Returns
Simulated time series of shape (n_vars,T) with T time-recordings for n_vars many variables
- Return type
numpy.array