Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developer #193

Merged
merged 5 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ Tigramite is a causal time series analysis python package. It allows to efficien
## Required python packages

- python=3.7/3.8/3.9
- numpy
- scipy
- numba
- numpy==1.21.5
- scipy==1.8.0
- numba==0.55.1

## Optional packages depending on used functions
- scikit-learn>=0.21 # Gaussian Process (GP) Regression
Expand All @@ -86,6 +86,7 @@ To use just the ParCorr, CMIknn, and CMIsymb independence tests, only numpy/numb

- GPDCtorch: gpytorch is required for Gaussian Process regression

Note: Due to incompatibility issues between numba and numpy/scipy, we currently freeze their versions.

## User Agreement

Expand Down
8 changes: 4 additions & 4 deletions environment_py3.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tigramite4_conda
name: tigramite_conda
dependencies:
- python>=3.9
- numpy
- scipy
- numba
- numpy==1.21.5
- scipy==1.8.0
- numba==0.55.1
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def run(self):
long_description = fh.read()

# Define the minimal classes needed to install and run tigramite
# INSTALL_REQUIRES = ["numpy==1.21.4", "scipy==1.7.2", "numba==0.53.1", "six"]
INSTALL_REQUIRES = ["numpy", "scipy", "numba", "six"]
INSTALL_REQUIRES = ["numpy==1.21.5", "scipy==1.8.0", "numba==0.55.1", "six"]
# INSTALL_REQUIRES = ["numpy", "scipy", "numba", "six"]
# Define all the possible extras needed
EXTRAS_REQUIRE = {
"all": [
Expand Down Expand Up @@ -63,7 +63,7 @@ def run(self):
# Run the setup
setup(
name="tigramite",
version="5.0.1.1",
version="5.0.1.2",
packages=["tigramite", "tigramite.independence_tests", "tigramite.toymodels"],
license="GNU General Public License v3.0",
description="Tigramite causal discovery for time series",
Expand Down
16 changes: 13 additions & 3 deletions tigramite/causal_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def __init__(self,
# and hidden variables
# (self.graph, self.graph_type,
# self.tau_max, self.hidden_variables) =

self._construct_graph(graph=graph, graph_type=graph_type,
hidden_variables=hidden_variables)

Expand Down Expand Up @@ -270,6 +271,8 @@ def _construct_graph(self, graph, graph_type, hidden_variables):

stat_graph = deepcopy(graph)

allowed_edges = ["-->", "<--"]

# Construct tsg_graph
graph = np.zeros((self.N, self.N, self.tau_max + 1, self.tau_max + 1), dtype='<U3')
graph[:] = ""
Expand All @@ -294,6 +297,16 @@ def _construct_graph(self, graph, graph_type, hidden_variables):
if stat_graph[i, j, tau] == '-->':
graph[i, j, taui, tauj] = "-->"
graph[j, i, tauj, taui] = "<--"
elif stat_graph[i, j, tau] == '<--':
pass
elif stat_graph[i, j, tau] == '':
pass
else:
edge = stat_graph[i, j, tau]
raise ValueError("Invalid graph edge %s. " %(edge) +
"For graph_type = %s only %s are allowed." %(graph_type, str(allowed_edges)))



# elif stat_graph[i, j, tau] == '<--':
# graph[i, j, taui, tauj] = "<--"
Expand Down Expand Up @@ -1860,7 +1873,6 @@ def fit_total_effect(self,
conditions=self.listS,
tau_max=self.tau_max,
cut_off='max_lag_or_tau_max',
remove_missing_upto_maxlag=False,
return_data=False)

return self
Expand Down Expand Up @@ -2018,7 +2030,6 @@ def fit_wright_effect(self,
Y=[medy], X=[par], Z=oset,
tau_max=self.tau_max,
cut_off='max_lag_or_tau_max',
remove_missing_upto_maxlag=False,
return_data=False)
coeffs[medy][par] = fit_res[medy]['model'].coef_[0]
# print(mediators, par, medy, coeffs[medy][par])
Expand All @@ -2039,7 +2050,6 @@ def fit_wright_effect(self,
conditions=None,
tau_max=self.tau_max,
cut_off='max_lag_or_tau_max',
remove_missing_upto_maxlag=False,
return_data=False)

for ipar, par in enumerate(all_parents):
Expand Down
9 changes: 6 additions & 3 deletions tigramite/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
class DataFrame():
"""Data object containing time series array and optional mask.

Alternatively, a panda dataframe can be used.

Parameters
----------
data : array-like
Expand Down Expand Up @@ -61,7 +59,9 @@ def __init__(self, data, mask=None, missing_flag=None, var_names=None,
# Set the default variable names if none are set
if self.var_names is None:
self.var_names = {i: i for i in range(N)}

else:
if len(self.var_names) != N:
raise ValueError("len(var_names) != data.shape[1].")
# Set datatime
self.datatime = datatime
if self.datatime is None:
Expand Down Expand Up @@ -728,6 +728,7 @@ def structural_causal_process(links, T, noises=None,

if __name__ == '__main__':

from tigramite.toymodels.structural_causal_processes import structural_causal_process
## Generate some time series from a structural causal process
def lin_f(x): return x
def nonlin_f(x): return (x + 5. * x**2 * np.exp(-x**2 / 20.))
Expand All @@ -740,3 +741,5 @@ def nonlin_f(x): return (x + 5. * x**2 * np.exp(-x**2 / 20.))
data, nonstat = structural_causal_process(links,
T=100, noises=noises)
print(data.shape)

frame = DataFrame(data)
Loading