├── .gitattributes
├── .github
└── workflows
│ ├── pre-commit.yml
│ └── publish-to-pypi.yml
├── .gitignore
├── .pre-commit-config.yaml
├── LICENSE.md
├── Makefile
├── README.md
├── causing
├── __init__.py
├── examples
│ ├── __main__.py
│ ├── input
│ │ ├── education.csv
│ │ ├── example.json
│ │ ├── example2.json
│ │ └── example3.json
│ └── models.py
├── graph.py
├── model.py
└── utils.py
├── data
├── education.csv
├── xdat.csv
└── ymdat.csv
├── docs
├── contributing.md
└── education.md
├── images_education
└── IME_32.svg
├── images_readme
├── IME_1.svg
└── RealRate_AI_Software_Winner.png
├── mypy.ini
├── output
├── education
│ └── graphs.json
├── example
│ └── graphs.json
├── example2
│ └── graphs.json
├── example3
│ └── graphs.json
└── heaviside
│ └── graphs.json
├── setup.py
└── tests
├── __init__.py
├── examples
├── __init__.py
└── models.py
├── test_estimate.py
└── utils.py
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.github/workflows/pre-commit.yml:
--------------------------------------------------------------------------------
1 | name: pre-commit
2 |
3 | on:
4 | pull_request:
5 | push:
6 | branches:
7 | - main
8 | - develop
9 |
10 | jobs:
11 | pre-commit:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v2
15 | - uses: actions/setup-python@v2
16 | - uses: pre-commit/action@v2.0.0
17 |
18 | verify-output:
19 | runs-on: ubuntu-latest
20 | steps:
21 | - uses: actions/checkout@v2
22 | - uses: actions/setup-python@v2
23 | with:
24 | python-version: '3.9'
25 | - uses: actions/cache@v3
26 | with:
27 | path: ${{ env.pythonLocation }}
28 | key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}
29 | - name: Install dependencies
30 | run: |
31 | python -m pip install --upgrade pip
32 | pip install .[estimate]
33 | sudo apt-get install graphviz
34 | - name: Verify examples output
35 | run: make verify-output
36 |
--------------------------------------------------------------------------------
/.github/workflows/publish-to-pypi.yml:
--------------------------------------------------------------------------------
1 | name: release
2 |
3 | on:
4 | release:
5 | types: [published]
6 |
7 | jobs:
8 | upload-to-pypi:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@v2
12 | - uses: actions/setup-python@v2
13 | with:
14 | python-version: '3.9'
15 | - name: Install pypa/build
16 | run: >-
17 | python -m
18 | pip install build --user
19 | - name: Build a binary wheel and a source tarball
20 | run: >-
21 | python -m
22 | build
23 | --sdist
24 | --wheel
25 | --outdir dist/
26 | .
27 | - name: Publish distribution to PyPI
28 | uses: pypa/gh-action-pypi-publish@release/v1
29 | with:
30 | password: ${{ secrets.PYPI_API_TOKEN }}
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .png
2 | .pylint.d
3 | .spyproject
4 | .venv
5 | *.egg-info/
6 | .eggs/
7 |
8 | ~$*.doc*
9 | *.pdf
10 | *.mp4
11 |
12 | /output/*/graphs
13 | /output/*/logging.txt
14 | __pycache__
15 |
16 | build/
17 | dist/
18 | .idea/
19 |
20 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | # See https://pre-commit.com for more information
2 | # See https://pre-commit.com/hooks.html for more hooks
3 | repos:
4 | - repo: https://github.com/psf/black
5 | rev: 22.3.0
6 | hooks:
7 | - id: black
8 | - repo: https://github.com/pre-commit/mirrors-mypy
9 | rev: v0.910
10 | hooks:
11 | - id: mypy
12 | - repo: https://github.com/pycqa/flake8
13 | rev: 5.0.4
14 | hooks:
15 | - id: flake8
16 | args:
17 | - "--max-line-length=120"
18 | - "--extend-ignore=E203" # conflicts with black
19 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # MIT License
2 |
3 | **Copyright (c) 2020 Dr. Holger Bartel, RealRate GmbH**
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | lint:
2 | pre-commit run
3 |
4 | lint-all:
5 | pre-commit run --all-files
6 |
7 | examples:
8 | python -m causing.examples example > /tmp/example.log
9 | python -m causing.examples example2 > /tmp/example2.log
10 | python -m causing.examples example3 > /tmp/example3.log
11 | python -m causing.examples education > /tmp/education.log
12 | python -m causing.examples heaviside > /tmp/heaviside.log
13 |
14 | verify-output: examples
15 | git diff --exit-code output/
16 |
17 | test:
18 | python3 -m unittest
19 |
20 | .PHONY: lint lint-all examples verify-output test
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Causing: CAUSal INterpretation using Graphs
2 |
3 | [](https://opensource.org/licenses/MIT)
4 | [](https://www.python.org/)
5 |
6 | _Causing is a multivariate graphical analysis tool helping you to interpret the causal
7 | effects of a given equation system._
8 |
9 | Get a nice colored graph and immediately understand the causal effects between the variables.
10 |
11 | **Input:** You simply have to put in a dataset and provide an equation system in form of a
12 | python function. The endogenous variables on the left-hand side are assumed to be caused by
13 | the variables on the right-hand side of the equation. Thus, you provide the causal structure
14 | in form of a directed acyclic graph (DAG).
15 |
16 | **Output:** As an output, you will get a colored graph of quantified effects acting between
17 | the model variables. You can immediately interpret mediation chains for every
18 | individual observation - even for highly complex nonlinear systems.
19 |
20 | Here is a table relating Causing to other approaches:
21 |
22 | Causing is | Causing is NOT
23 | --- | ---
24 | ✅ causal model given | ❌ causal search
25 | ✅ DAG directed acyclic graph | ❌ cyclic, undirected, or bidirected graph
26 | ✅ latent variables | ❌ just observed / manifest variables
27 | ✅ individual effects | ❌ just average effects
28 | ✅ direct, total, and mediation effects | ❌ just total effects
29 | ✅ structural model | ❌ reduced model
30 | ✅ small and big data | ❌ big data requirement
31 | ✅ graphical results | ❌ just numerical results
32 | ✅ XAI explainable AI | ❌ black box neural network
33 |
34 | The Causing approach is quite flexible. It can be applied to highly latent models with many of the modeled endogenous variables being unobserved. Exogenous variables are assumed to be observed and deterministic. The most severe restriction certainly is that you need to specify the causal model / causal ordering.
35 |
36 | ## Causal Effects
37 |
38 | Causing combines total effects and mediation effects in one single graph that is easy to explain.
39 |
40 | The total effects of a variable on the final variable are shown in the corresponding nodes of the graph. The total effects are split up over their outgoing edges, yielding the mediation effects shown on the edges. Just education has more than one outgoing edge to be interpreted in this way.
41 |
42 | The effects differ from individual to individual. To emphasize this, we talk about individual effects. And the corresponding graph, combining total and mediation effects is called the Individual Mediation Effects (IME) graph.
43 |
44 | ## Software
45 |
46 | Causing is free software written in _Python 3_. Graphs are generated using _Graphviz_. See dependencies in [setup.py](setup.py). Causing is available under MIT license. See [LICENSE](LICENSE.md "LICENSE").
47 |
48 | The software is developed by RealRate, an AI rating agency aiming to re-invent the rating market by using AI, interpretability, and avoiding any conflict of interest. See www.realrate.ai.
49 |
50 | When starting `python -m causing.examples example` after cloning / downloading the Causing repository you will find the results in the _output_ folder. The results are saved in SVG files. The IME files show the individual mediation effects graphs for the respective individual.
51 |
52 | See `causing/examples` for the code generating some examples.
53 |
54 | ## Start your Model
55 |
56 | To start your model, you have to provide the following information, as done in the example code below:
57 |
58 | - Define all your model variables as SymPy symbols.
59 | - Note that in Sympy some operators are special, e.g. Max() instead of max().
60 | - Provide the model equations in topological order, that is, in order of computation.
61 | - Then the model is specified with:
62 | - _xvars_: exogenous variables
63 | - _yvars_: endogenous variables in topological order
64 | - _equations_: previously defined equations
65 | - _final_var_: the final variable of interest used for mediation effects
66 |
67 | ## 1. A Simple Example
68 |
69 | Assume a model defined by the equation system:
70 |
71 | Y1 = X1
72 |
73 | Y2 = X2 + 2 * Y12
74 |
75 | Y3 = Y1 + Y2.
76 |
77 | This gives the following graphs. Some notes to understand them:
78 |
79 | - The data used consists of 200 observations. They are available for the x variables X1 and X2 with mean(X1) = 3 and mean(X2) = 2. Variables Y1 and Y2 are assumed to be latent / unobserved. Y3 is assumed to be manifest / observed. Therefore, 200 observations are available for Y3.
80 |
81 | - To allow for benchmark comparisons, each individual effect is measured with respect to the mean of all observations.
82 |
83 | - Nodes and edges are colored, showing positive (_green_) and negative (_red_) effects they have on the final variable Y3.
84 |
85 | - Individual effects are based on the given model. For each individual, however, its _own_ exogenous data is put into the given graph function to yield the corresponding endogenous values. The effects are computed at this individual point. Individual effects are shown below just for individual no. 1 out of the 200 observations.
86 |
87 | - Total effects are shown below in the nodes and they are split up over the outgoing edges yielding the Mediation effects shown on the edges. Note, however, that just outgoing edges sum up to the node value, incoming edges do not. All effects are effects just on the final variable of interest, assumed here to be Y3.
88 |
89 | 
90 |
91 | As you can see in the right-most graph for the individual mediation effects (IME), there is one green path starting at X1 passing through Y1, Y2, and finally ending in Y3. This means that X1 is the main cause for Y3 taking on a value above average with its effect on Y3 being +29.81. However, this positive effect is slightly reduced by X2. In total, accounting for all exogenous and endogenous effects, Y3 is +27.07 above average. You can understand at one glance why Y3 is above average for individual no. 1.
92 |
93 | You can find the full source code for this example [here](https://github.com/realrate/Causing/blob/develop/causing/examples/models.py#L16-L45).
94 |
95 | ## 2. Application to Education and Wages
96 |
97 | To dig a bit deeper, here we have a real-world example from social sciences. We analyze how the wage earned by young American workers is determined by their educational attainment, family characteristics, and test scores.
98 |
99 | This 5-minute introductory video gives a short overview of Causing and includes this real data example: See [Causing Introduction Video](https://youtu.be/GJLsjSZOk2w "Causing_Introduction_Video").
100 |
101 | See here for a detailed analysis of the Education and Wages example: [An Application of Causing: Education and Wages](docs/education.md).
102 |
103 | ## 3. Application to Insurance Ratings
104 |
105 | The Causing approach and its formulas together with an application are given in:
106 |
107 | > Bartel, Holger (2020), "Causal Analysis - With an Application to Insurance Ratings"
108 | DOI: 10.13140/RG.2.2.31524.83848
109 | https://www.researchgate.net/publication/339091133
110 |
111 | Note that in this early paper the mediation effects on the final variable of interest are called final effects. Also, while the current Causing version just uses numerically computed effects, that paper uses closed formulas.
112 |
113 | The paper proposes simple linear algebra formulas for the causal analysis of equation systems. The effect of one variable on another is the total derivative. It is extended to endogenous system variables. These total effects are identical to the effects used in graph theory and its do-calculus. Further, mediation effects are defined, decomposing the total effect of one variable on a final variable of interest over all its directly caused variables. This allows for an easy but in-depth causal and mediation analysis.
114 |
115 | The equation system provided by the user is represented as a structural neural network (SNN). The network's nodes are represented by the model variables and its edge weights are given by the effects. Unlike classical deep neural networks, we follow a sparse and 'small data' approach. This new methodology is applied to the financial strength ratings of insurance companies.
116 |
117 | > **Keywords:** total derivative, graphical effect, graph theory, do-Calculus, structural neural network, linear Simultaneous Equations Model (SEM), Structural Causal Model (SCM), insurance rating
118 |
119 | ## Award
120 |
121 | RealRate's AI software _Causing_ is a winner of the PyTorch AI Hackathon.
122 |
123 |
124 |
125 | We are excited to be a winner of the PyTorch AI Hackathon 2020 in the Responsible AI category. This is quite an honor given that more than 2,500 teams submitted their projects.
126 |
127 | [devpost.com/software/realrate-explainable-ai-for-company-ratings](https://devpost.com/software/realrate-explainable-ai-for-company-ratings "devpost.com/software/realrate-explainable-ai-for-company-ratings").
128 |
129 | ## GitHub Star History
130 |
131 | [star-history.com](https://www.star-history.com/#realrate/Causing&Date)
132 | 
133 |
134 | ## Contact
135 |
136 | Dr. Holger Bartel
137 | RealRate
138 | Cecilienstr. 14, D-12307 Berlin
139 | [holger.bartel@realrate.ai](mailto:holger.bartel@realrate.ai?subject=[Causing])
140 | Phone: +49 160 957 90 844
141 | [realrate.ai](https://realrate.ai)
142 | [drbartel.com](https://drbartel.com)
143 |
--------------------------------------------------------------------------------
/causing/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """causing - causal interpretation using graphs."""
3 |
4 | # flake8: noqa
5 |
6 | # public Causing API
7 | from causing.model import Model
8 |
9 |
10 | def create_indiv(m: Model, xdat, show_nr_indiv: int) -> dict:
11 | """Calculate effects and limit result set to `show_nr_indiv`
12 |
13 | This is mostly to for backwards compatability and to shrink the amount of
14 | data for tests cases. Otherwise, use `Model.calc_effects` directly.
15 | """
16 | eff = m.calc_effects(xdat)
17 | for key in ["exj_indivs", "eyj_indivs", "eyx_indivs", "eyy_indivs"]:
18 | if key in ["exj_indivs", "eyj_indivs"]:
19 | eff[key] = eff[key][:, :show_nr_indiv]
20 | else:
21 | eff[key] = eff[key][:show_nr_indiv]
22 | return eff
23 |
--------------------------------------------------------------------------------
/causing/examples/__main__.py:
--------------------------------------------------------------------------------
1 | from sys import argv
2 | from pathlib import Path
3 | import warnings
4 | import logging
5 |
6 | import pandas
7 |
8 | import causing.graph
9 | from causing.examples import models
10 | from causing.utils import round_sig_recursive, dump_json
11 |
12 | logging.basicConfig(level=logging.INFO) # type: ignore
13 |
14 | # Our examples should run without any warnings, so let's treat them as errors.
15 | warnings.filterwarnings("error")
16 |
17 | # Keep wide output even if redirecting to file
18 | pandas.set_option("display.max_columns", 500)
19 | pandas.set_option("display.max_rows", 500)
20 | pandas.set_option("display.width", 500)
21 |
22 | if len(argv) != 2:
23 | print('Please call with model name as argument (e.g. "example" or "education").')
24 | exit(1)
25 |
26 | model_name = argv[1]
27 |
28 | try:
29 | model_function = getattr(models, model_name)
30 | except AttributeError:
31 | print(f'Unkown model function "{model_name}".')
32 | exit(1)
33 |
34 |
35 | # Do all calculations
36 | m, xdat = model_function()
37 | graphs = m.calc_effects(xdat)
38 |
39 | # Print json output
40 | output_dir = Path("output") / model_name
41 | dump_json(round_sig_recursive(graphs, 6), output_dir / "graphs.json")
42 |
43 | # Draw graphs
44 | show_nr_indiv = 33 if model_name == "education" else 3
45 | annotated_graphs = causing.graph.annotated_graphs(
46 | m, graphs, ids=[str(i) for i in range(show_nr_indiv)]
47 | )
48 | causing.graph.create_graphs(annotated_graphs, output_dir / "graphs")
49 |
--------------------------------------------------------------------------------
/causing/examples/input/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "xdat": [
3 | [
4 | 2.8872869691061602,
5 | 4.785026931424977,
6 | 2.6736792144640185,
7 | 3.3758664973419217,
8 | 2.6500242287369096,
9 | 4.200911925211615,
10 | 4.854028741791787,
11 | 2.869288568402771,
12 | 2.0263377372073608,
13 | 2.2820785332228883,
14 | 2.2227999905821543,
15 | 2.942381145922457,
16 | 1.8167989405733076,
17 | 3.912256171757456,
18 | 2.304230997962419,
19 | 2.212758471472195,
20 | 3.0933081068260373,
21 | 3.7802448586640867,
22 | 2.519391413372405,
23 | 2.4972656287527957,
24 | 2.075002378029681,
25 | 1.599763814234508,
26 | 3.2173406802207793,
27 | 3.0858755266228397,
28 | 2.802968785886549,
29 | 3.3451739807671483,
30 | 2.4047148350193743,
31 | 4.331252678012974,
32 | 2.5142442071775224,
33 | 0.40464257762082045,
34 | 4.0389596412374775,
35 | 3.7586409441262836,
36 | 0.6557068408092563,
37 | 1.49721232937859,
38 | 2.446821476108088,
39 | 2.130682143294284,
40 | 2.8928450354571593,
41 | 2.65946206614633,
42 | 1.7053831777164132,
43 | 4.126269575524226,
44 | 3.7655853172760128,
45 | 3.5738584993611338,
46 | 3.645188978621543,
47 | 4.899738557080213,
48 | 3.499970383255115,
49 | 1.997115783987647,
50 | 3.204277735537852,
51 | 1.9250025366322525,
52 | 3.6469302206281182,
53 | 2.8274358144735015,
54 | 2.8879561501492454,
55 | 3.45473818292903,
56 | 3.062460465192962,
57 | 2.5464461674841923,
58 | 2.186884007640653,
59 | 3.445713200789419,
60 | 3.1078318128236835,
61 | 2.8431479090574925,
62 | 1.5277366136014627,
63 | 2.106610472737535,
64 | 3.001462948847881,
65 | 2.4944514415718055,
66 | 4.758176140420122,
67 | 3.7946416510491887,
68 | 2.908823602380252,
69 | 2.731887381170233,
70 | 2.40603677745438,
71 | 2.1664383556553113,
72 | 3.6441244592704134,
73 | 2.2182410399027823,
74 | 3.3051991650580543,
75 | 2.501928484246964,
76 | 2.9445662409692055,
77 | 1.1876853032251635,
78 | 2.6208023317844744,
79 | 2.96889984080992,
80 | 3.270149615184717,
81 | 2.739032565895155,
82 | 1.673923343601349,
83 | 3.2579314850568326,
84 | 1.8502340173256802,
85 | 3.8311648452832605,
86 | 3.7311102235595213,
87 | 6.2592559170283915,
88 | 0.9484913453096051,
89 | 2.767983030562516,
90 | 2.116166313265303,
91 | 4.066938240964659,
92 | 3.7648748965769148,
93 | 2.483665572184565,
94 | 2.8861545302601717,
95 | 2.5734428378111573,
96 | 3.2759071317142463,
97 | 4.2115136836422185,
98 | 1.549904523402743,
99 | 3.4763530654671584,
100 | 2.571267249401294,
101 | 4.039451329698665,
102 | 3.371804663869714,
103 | 3.621954815294834,
104 | 3.061394449445934,
105 | 2.730352442998404,
106 | 2.9927653627393807,
107 | 2.03313616388579,
108 | 2.89852800879,
109 | 2.3040956673625486,
110 | 2.8944942969662772,
111 | 2.4004027518716806,
112 | 3.11359668445339,
113 | 4.284907708139697,
114 | 1.8763025547279524,
115 | 2.4623858130099046,
116 | 2.3479797052171394,
117 | 2.524438919555902,
118 | 2.4586609739140277,
119 | 4.713092512432414,
120 | 1.4891068463473403,
121 | 4.377964234434829,
122 | 3.1569983934533132,
123 | 2.6190877126068717,
124 | 2.87375023091356,
125 | 3.2486564582861166,
126 | 2.6528455754460745,
127 | 3.005476921270593,
128 | 4.164232296973058,
129 | 3.780966820743133,
130 | 4.816306941606609,
131 | 2.66655002687836,
132 | 5.047364009401332,
133 | 3.6969608986513998,
134 | 3.5670551666090775,
135 | 3.661881588239103,
136 | 2.0929879464576757,
137 | 2.9099855912552752,
138 | 3.0774500846462565,
139 | 4.098866238256457,
140 | 2.6237114311605927,
141 | 1.046540865873361,
142 | 2.228691751324142,
143 | 2.7618070480377344,
144 | 3.846074678747882,
145 | 2.94351360255783,
146 | 3.954767364075697,
147 | 3.3118891480087354,
148 | 2.8936539288318435,
149 | 3.76306781846118,
150 | 0.6552130470177158,
151 | 3.656514304436807,
152 | 2.0206212078730834,
153 | 2.2685397111761723,
154 | 3.534031795914862,
155 | 3.1715241767872833,
156 | 2.110420588830027,
157 | 3.393343513161322,
158 | 4.104738237889165,
159 | 3.680783663265437,
160 | 3.563299169053024,
161 | 3.005614352581387,
162 | 3.087266524609803,
163 | 3.4313093353724726,
164 | 3.232336023851622,
165 | 3.9734899485918684,
166 | 2.9504362681593572,
167 | 2.0661992197778942,
168 | 3.160150193317373,
169 | 3.259285881992602,
170 | 2.8323858865562337,
171 | 1.0271769233156829,
172 | 2.5935738333609066,
173 | 2.8015362631274687,
174 | 5.194837332354277,
175 | 3.7663408873157636,
176 | 4.031791927556463,
177 | 2.2567868006120047,
178 | 4.056446908530157,
179 | 2.4007762052187513,
180 | 3.280445470271719,
181 | 3.8570325888238717,
182 | 3.860621845169172,
183 | 3.4850094100306594,
184 | 2.7490990870560683,
185 | 1.6186175139101526,
186 | 2.1647664944760656,
187 | 2.8268549424378078,
188 | 4.576259428567907,
189 | 4.126690293240515,
190 | 1.5275721604715555,
191 | 4.324972261723336,
192 | 2.3080556055625405,
193 | 4.315641617626974,
194 | 3.6738139571871877,
195 | 2.0712800147844592,
196 | 1.53607688458728,
197 | 1.5554929600778507,
198 | 2.2732617847626293,
199 | 1.3015309837029603,
200 | 3.7079411806877287,
201 | 2.9598664447073637,
202 | 2.887364555410513,
203 | 4.962038075781968
204 | ],
205 | [
206 | 0.9226444224672825,
207 | 0.9294591185928729,
208 | 0.7002944365636006,
209 | 1.214768112917615,
210 | 2.2206712953453698,
211 | 0.7028872875674521,
212 | 2.8547875011343207,
213 | 1.578881654341097,
214 | 1.3472455129620644,
215 | 3.0531318572670036,
216 | 1.267924982888177,
217 | 2.0664482732752085,
218 | 0.24590829408531278,
219 | 2.5867843279163028,
220 | -0.3816831012145938,
221 | 0.8348152790525589,
222 | 1.500159348577411,
223 | 1.9592915569971832,
224 | 0.8895327013178551,
225 | 2.6733843052360955,
226 | 3.9803840140549758,
227 | 1.4856861319804242,
228 | 1.698202483406017,
229 | 2.121672268788325,
230 | 3.280314026453696,
231 | 2.615412507064239,
232 | 2.5989689409333256,
233 | 1.550967258816849,
234 | 2.958004972041247,
235 | 1.6444840642836143,
236 | 0.43575868063162804,
237 | 1.6617197113173978,
238 | 1.425404059032009,
239 | 2.1783457927798424,
240 | 2.925505829592848,
241 | 1.7525624835650067,
242 | 4.034986208906158,
243 | 1.4146531550770585,
244 | 1.9508499885709887,
245 | 2.6186770883947976,
246 | 0.8273283355360868,
247 | 1.8990822461613104,
248 | 1.1446179404584775,
249 | 2.592427050821793,
250 | 1.4860627063397391,
251 | 1.0338986053567427,
252 | 2.5661162941747326,
253 | -0.3880444860614265,
254 | 1.8135627535942385,
255 | -0.2766991301515813,
256 | 2.913603784550382,
257 | 4.111215695780565,
258 | 2.015277101913836,
259 | 2.2752258566035004,
260 | 1.73787117011666,
261 | 0.8397768311201528,
262 | 2.856584568453247,
263 | 3.1334298165072467,
264 | 2.5540905852775326,
265 | 1.283442940804922,
266 | 1.1170825726335645,
267 | 3.1058559859229478,
268 | 3.858719807608227,
269 | 1.2702859041225625,
270 | -0.06795559289248754,
271 | 0.9842824013279381,
272 | 3.0816303863513683,
273 | 1.6107872206306568,
274 | 3.490901641888225,
275 | -0.9286431243068205,
276 | 2.4843813532581063,
277 | 2.0171562158368475,
278 | 3.5457411117333475,
279 | 0.20377390180683297,
280 | 1.1386755424689001,
281 | 1.5846684231020272,
282 | 1.444482379728466,
283 | 0.8961596153787899,
284 | 1.5347058166312924,
285 | 0.553491806650217,
286 | 1.5630243232366383,
287 | 0.02627548034679683,
288 | 1.408695602852081,
289 | 4.273769226171176,
290 | 0.7479071339699841,
291 | 2.9262968341913425,
292 | 1.764046869509698,
293 | 2.420768785032239,
294 | 1.7128268268926747,
295 | 0.30869335112730867,
296 | 3.756076547833911,
297 | 1.1470735235273697,
298 | 2.3319186688055447,
299 | 1.4359715717524066,
300 | 2.0164866466837092,
301 | 0.5617860815255695,
302 | 3.250288977965843,
303 | 2.595799008717896,
304 | 2.516543384472706,
305 | 2.949865096669039,
306 | 2.5903071834654683,
307 | 1.5942879820625426,
308 | 3.008864857520584,
309 | 2.838178853735018,
310 | 0.21730154658388745,
311 | 2.4606218892209606,
312 | 3.6304882339853037,
313 | 2.596546765093882,
314 | 2.3926595004477607,
315 | 2.9322161930017634,
316 | 1.6256060780193693,
317 | 1.240724906279075,
318 | 0.1104421226189336,
319 | 1.6537717127608933,
320 | -0.04484330469960929,
321 | 1.9722602030189287,
322 | 0.556166905081231,
323 | 3.7332038961653864,
324 | 1.2038437944038325,
325 | 1.4559495581637414,
326 | 2.3116821836983896,
327 | 3.100930678251502,
328 | 2.8113654329199367,
329 | 0.9728213305442048,
330 | 3.619644314947672,
331 | 4.151626406226346,
332 | 2.05787204578069,
333 | 2.5406975498508046,
334 | 1.888124090887733,
335 | 0.6840451515246686,
336 | 2.2795766197948617,
337 | 3.2070093779609374,
338 | 0.7311878049131035,
339 | 1.8896353621645683,
340 | 2.8037421644009073,
341 | 1.2382440344429244,
342 | 0.768037487237573,
343 | 1.6994847758222944,
344 | 3.0557837386463196,
345 | 2.3176509665010827,
346 | 2.024770437344937,
347 | 1.4057848820267524,
348 | 0.9352620520209849,
349 | -0.4222668339577629,
350 | 1.9698673808217695,
351 | 2.085718299641306,
352 | 1.5946525289334947,
353 | 2.1734651592540204,
354 | -0.27111078601554484,
355 | 2.0574929553834664,
356 | 0.40447335128996054,
357 | 3.587737208395782,
358 | 2.180748555856563,
359 | 1.3251320363200185,
360 | 0.5583035425199661,
361 | 3.52484561018949,
362 | 1.7406996192990234,
363 | 2.372795718679365,
364 | 1.5280388793186288,
365 | 1.477046197636669,
366 | 1.8631505650207825,
367 | 4.121237273176616,
368 | 1.381763411809243,
369 | 1.2466009178571835,
370 | 1.4175554162441855,
371 | 2.08426606878413,
372 | 0.9628625992344577,
373 | 1.5302470818501053,
374 | 2.617921714292243,
375 | 2.0475346697286754,
376 | 1.6721931992940329,
377 | 2.015083016276819,
378 | 1.602946451757259,
379 | 3.4175363481192313,
380 | 1.9684011169976288,
381 | 3.3416730890515067,
382 | 3.634718718329693,
383 | 2.7449829287781977,
384 | 2.5521970303043204,
385 | 1.8535103583299786,
386 | 2.4837568367872978,
387 | 2.4280421484417176,
388 | 1.0145787809590394,
389 | 2.994803238446809,
390 | 3.031989718547572,
391 | 1.6142990395475707,
392 | 1.8185839882665342,
393 | 3.174659695401056,
394 | 1.0089450416246355,
395 | 1.8005793504007783,
396 | 2.4592980462169747,
397 | 3.045729092536873,
398 | 0.8114356839967107,
399 | 3.4497743320518284,
400 | 0.5420014213123594,
401 | 0.9604658732033851,
402 | 0.8231517390179206,
403 | 1.909812809958391,
404 | 1.017897451595904,
405 | 2.3402902008910145
406 | ]
407 | ],
408 | "ymdat": [
409 | [
410 | 21.82038219052063,
411 | 49.975955779190926,
412 | 19.276575657402223,
413 | 28.753192265354457,
414 | 17.49978522674554,
415 | 40.055320910573755,
416 | 54.835438551163115,
417 | 22.024145480767782,
418 | 11.80644641025265,
419 | 15.949233167087147,
420 | 13.719267859447015,
421 | 22.911758662443752,
422 | 9.410700038311115,
423 | 36.896503116275696,
424 | 11.736689554541677,
425 | 13.47919477880806,
426 | 23.75494574612701,
427 | 33.23890611180403,
428 | 16.246831596435143,
429 | 17.086646436124408,
430 | 15.056210778612774,
431 | 9.297788023616206,
432 | 25.787377778241616,
433 | 23.508148207378206,
434 | 21.563759840715715,
435 | 26.984027572400404,
436 | 16.407085238622372,
437 | 43.62179111834604,
438 | 17.117927857487164,
439 | 1.8515773486216243,
440 | 35.42251733773925,
441 | 33.623612395668914,
442 | 4.094619065846722,
443 | 6.758486571904081,
444 | 18.633354926308904,
445 | 14.401485633063219,
446 | 24.10773006734984,
447 | 18.994017602143604,
448 | 10.392384112826388,
449 | 40.97851113271272,
450 | 32.332092417908974,
451 | 30.72592343393059,
452 | 31.47995515506708,
453 | 56.64648237174675,
454 | 28.745298192637545,
455 | 8.243869409820716,
456 | 26.413387460897273,
457 | 8.420233401459777,
458 | 32.08163450846512,
459 | 18.11651641423544,
460 | 21.662142362765728,
461 | 32.63809194485312,
462 | 23.702851261189938,
463 | 20.69154115621013,
464 | 13.956060581564085,
465 | 27.927148866390745,
466 | 25.2312095955475,
467 | 21.301821893725457,
468 | 8.884433499291587,
469 | 12.411714659563291,
470 | 21.993254266895526,
471 | 17.524788327317935,
472 | 53.81139764555536,
473 | 33.89166508381495,
474 | 20.497087464982474,
475 | 19.817082648417355,
476 | 20.261154390372017,
477 | 12.169042689363351,
478 | 33.43250503183893,
479 | 11.073168390847469,
480 | 28.753498187294987,
481 | 15.665854216630681,
482 | 24.21197854641842,
483 | 3.3060335851844553,
484 | 16.331857756567132,
485 | 23.155655409808933,
486 | 27.10176390523562,
487 | 18.47037964040584,
488 | 8.054504809299011,
489 | 26.528496826255267,
490 | 8.48978226765763,
491 | 32.625390117284816,
492 | 34.035292601514314,
493 | 86.83363748713404,
494 | 2.3533169202440134,
495 | 20.158648058560015,
496 | 13.862614982774083,
497 | 39.471139954720165,
498 | 34.25724910135015,
499 | 16.188291283903645,
500 | 23.28445261953703,
501 | 16.82814792598575,
502 | 26.094199040715463,
503 | 40.08924268684723,
504 | 8.149078550553586,
505 | 29.66355428852332,
506 | 17.121883038337796,
507 | 41.77990918355217,
508 | 30.987929780344942,
509 | 33.35309564906497,
510 | 23.418431302074872,
511 | 19.121840774980218,
512 | 23.819490680786704,
513 | 12.411688955121045,
514 | 21.862602898660953,
515 | 15.332895052185505,
516 | 21.14466072767647,
517 | 16.456670432937113,
518 | 25.921447098972127,
519 | 44.60324194956124,
520 | 10.141371991041838,
521 | 17.475404098961636,
522 | 12.62111437219627,
523 | 17.29191285888236,
524 | 13.895534589260585,
525 | 50.92958167866882,
526 | 5.823634648126632,
527 | 46.91068561975163,
528 | 24.35246267471942,
529 | 18.171434920047506,
530 | 20.82684785067222,
531 | 26.697206786107007,
532 | 19.54904879782474,
533 | 20.623587646186262,
534 | 41.97192789689322,
535 | 36.366492268580636,
536 | 54.36732000382837,
537 | 19.09014538030402,
538 | 57.598156945467316,
539 | 30.685913161196492,
540 | 30.43935067872708,
541 | 31.811931858597145,
542 | 11.584617993871987,
543 | 20.311799947502923,
544 | 25.659657360955418,
545 | 38.96851477468402,
546 | 18.775096276841474,
547 | 6.266805993730996,
548 | 16.009519374065853,
549 | 20.61383111547197,
550 | 36.00099523097948,
551 | 21.575382044893438,
552 | 36.2179133378303,
553 | 25.995906767665932,
554 | 20.624224781130465,
555 | 33.52714835248783,
556 | 3.5841400431821535,
557 | 31.811722915023836,
558 | 9.624383939370265,
559 | 13.86114716858814,
560 | 30.414671173876325,
561 | 26.855448489597386,
562 | 12.740193625855179,
563 | 27.360449879267676,
564 | 37.41053916293403,
565 | 33.95991914686377,
566 | 28.845822064405066,
567 | 23.60821140707702,
568 | 23.49879553095469,
569 | 28.016184575226507,
570 | 26.999406267077404,
571 | 41.284577083469664,
572 | 23.301276402197438,
573 | 13.088364686808742,
574 | 24.838707878850624,
575 | 24.740754584643597,
576 | 18.924089965671524,
577 | 6.488334146641673,
578 | 19.735716272239106,
579 | 20.467604725356058,
580 | 60.75532102277243,
581 | 33.48478411344634,
582 | 38.70673421525028,
583 | 15.241769714111337,
584 | 41.562829786456966,
585 | 18.753797731011737,
586 | 24.7925985700743,
587 | 36.813588983837654,
588 | 37.77477508116713,
589 | 29.728577318068464,
590 | 21.086095641324647,
591 | 7.407700033348016,
592 | 12.911524861885606,
593 | 21.864201384556036,
594 | 50.425507878571494,
595 | 39.872370345090445,
596 | 8.279187331573457,
597 | 44.478251080404206,
598 | 13.353304516285041,
599 | 44.09196102771181,
600 | 33.46428065808478,
601 | 14.244936126457995,
602 | 8.461522630226588,
603 | 10.997030304640129,
604 | 13.172069662908402,
605 | 7.04557940708292,
606 | 32.198719463253745,
607 | 25.118111931960176,
608 | 19.837285497260304,
609 | 56.842205882446876
610 | ]
611 | ]
612 | }
--------------------------------------------------------------------------------
/causing/examples/input/example2.json:
--------------------------------------------------------------------------------
1 | {
2 | "xdat": [
3 | [
4 | 2.8872869691061602,
5 | 1.923436019214106,
6 | 4.785026931424977,
7 | 1.5430166916415569,
8 | 2.6736792144640185,
9 | 1.7401035154707398,
10 | 3.3758664973419217,
11 | 2.1218526337110184,
12 | 2.6500242287369096,
13 | 3.2966602028589476,
14 | 4.200911925211615,
15 | 1.4310047612935157,
16 | 4.854028741791787,
17 | 3.493961807966228,
18 | 2.869288568402771,
19 | 2.596879247501283,
20 | 2.0263377372073608,
21 | 2.532533218572503,
22 | 2.2820785332228883,
23 | 4.2213933066552505,
24 | 2.2227999905821543,
25 | 2.4114743520286543,
26 | 2.942381145922457,
27 | 3.0795798842600206,
28 | 1.8167989405733076,
29 | 1.4512575542517088,
30 | 3.912256171757456,
31 | 3.412670735564499,
32 | 2.304230997962419,
33 | 0.7112281165759713,
34 | 2.212758471472195,
35 | 1.9714833280983022,
36 | 3.0933081068260373,
37 | 2.470805833831886,
38 | 3.7802448586640867,
39 | 2.79918530449522,
40 | 2.519391413372405,
41 | 1.9647378761789605,
42 | 2.4972656287527957,
43 | 3.7898902024041283,
44 | 2.075002378029681,
45 | 5.210035319426028,
46 | 1.599763814234508,
47 | 2.7609026210900796,
48 | 3.2173406802207793,
49 | 2.6476147188864747,
50 | 3.0858755266228397,
51 | 3.1066519708560043,
52 | 2.802968785886549,
53 | 4.346933859556485,
54 | 3.3451739807671483,
55 | 3.557644416067242,
56 | 2.4047148350193743,
57 | 3.7328321909133715,
58 | 4.331252678012974,
59 | 2.2699670626370727,
60 | 2.5142442071775224,
61 | 4.076914216230647,
62 | 0.40464257762082045,
63 | 3.1669281829423115,
64 | 4.0389596412374775,
65 | 1.191426140039237,
66 | 3.7586409441262836,
67 | 2.4998871918615406,
68 | 0.6557068408092563,
69 | 2.8920823107737323,
70 | 1.49721232937859,
71 | 3.4887786612651634,
72 | 2.446821476108088,
73 | 4.057507525214147,
74 | 2.130682143294284,
75 | 2.9249089067318836,
76 | 2.8928450354571593,
77 | 5.098822017803357,
78 | 2.65946206614633,
79 | 2.4720948927464113,
80 | 1.7053831777164132,
81 | 3.2140990318960836,
82 | 4.126269575524226,
83 | 3.401535844811228,
84 | 3.7655853172760128,
85 | 1.6468725457769033,
86 | 3.5738584993611338,
87 | 2.7798628731285846,
88 | 3.645188978621543,
89 | 1.9952806924726025,
90 | 4.899738557080213,
91 | 3.216860817678221,
92 | 3.499970383255115,
93 | 2.373408919020704,
94 | 1.997115783987647,
95 | 2.218689776415458,
96 | 3.204277735537852,
97 | 3.536092005094851,
98 | 1.9250025366322525,
99 | 0.7821452408708565,
100 | 3.6469302206281182,
101 | 2.677664203879725,
102 | 2.8274358144735015,
103 | 0.7115781974058732,
104 | 2.8879561501492454,
105 | 3.955313813089303,
106 | 3.45473818292903,
107 | 5.061927453612517,
108 | 3.062460465192962,
109 | 3.002842437780612,
110 | 2.5464461674841923,
111 | 3.3734825020035344,
112 | 2.186884007640653,
113 | 2.89844249021185,
114 | 3.445713200789419,
115 | 1.724871360740863,
116 | 3.1078318128236835,
117 | 3.852236887650466,
118 | 2.8431479090574925,
119 | 4.188819261366114,
120 | 1.5277366136014627,
121 | 3.8660408408090556,
122 | 2.106610472737535,
123 | 2.4510293875211007,
124 | 3.001462948847881,
125 | 2.09857755095916,
126 | 2.4944514415718055,
127 | 4.2318542067430736,
128 | 4.758176140420122,
129 | 4.538161757938014,
130 | 3.7946416510491887,
131 | 2.0930331217905254,
132 | 2.908823602380252,
133 | 0.9080129653456019,
134 | 2.731887381170233,
135 | 2.0180658260146975,
136 | 2.40603677745438,
137 | 4.225176625455613,
138 | 2.1664383556553113,
139 | 2.7729114286394254,
140 | 3.6441244592704134,
141 | 4.390163761705033,
142 | 2.2182410399027823,
143 | 0.170542007314733,
144 | 3.3051991650580543,
145 | 3.4320711298075115,
146 | 2.501928484246964,
147 | 3.119178411883016,
148 | 2.9445662409692055,
149 | 4.5889307845912795,
150 | 1.1876853032251635,
151 | 1.536671603685592,
152 | 2.6208023317844744,
153 | 2.1983178065939715,
154 | 2.96889984080992,
155 | 2.5824522778006074,
156 | 3.270149615184717,
157 | 2.3778831437196666,
158 | 2.739032565895155,
159 | 1.9266673795035667,
160 | 1.673923343601349,
161 | 2.795795376691757,
162 | 3.2579314850568326,
163 | 1.4710137133918215,
164 | 1.8502340173256802,
165 | 2.7887085658978172,
166 | 3.8311648452832605,
167 | 0.8159150339221504,
168 | 3.7311102235595213,
169 | 2.2472652273470786,
170 | 6.2592559170283915,
171 | 4.655363170578773,
172 | 0.9484913453096051,
173 | 2.140850520427705,
174 | 2.767983030562516,
175 | 3.9927580131174896,
176 | 2.116166313265303,
177 | 2.9395931404512505,
178 | 4.066938240964659,
179 | 3.211657486472749,
180 | 3.7648748965769148,
181 | 2.5507756730565037,
182 | 2.483665572184565,
183 | 1.379213703600541,
184 | 2.8861545302601717,
185 | 4.815526730641361,
186 | 2.5734428378111573,
187 | 2.216556176346062,
188 | 3.2759071317142463,
189 | 3.2824437653576974,
190 | 4.2115136836422185,
191 | 2.1770417008769942,
192 | 1.549904523402743,
193 | 3.31282611297537,
194 | 3.4763530654671584,
195 | 1.4348939038366062,
196 | 2.571267249401294,
197 | 4.363585550849811,
198 | 4.039451329698665,
199 | 3.3959077027379285,
200 | 3.371804663869714,
201 | 3.4513005749478496,
202 | 3.621954815294834,
203 | 3.842496009671126
204 | ]
205 | ],
206 | "ymdat": [
207 | [
208 | 2.9486814185520944,
209 | 2.513383675944758,
210 | 4.515379374423381,
211 | 1.1839801743693585,
212 | 2.666444577203399,
213 | 2.7712486630972446,
214 | 2.409002661227712,
215 | 3.1746755981642014,
216 | 2.5485522375269096,
217 | 1.4979140962804196,
218 | 3.505007592574164,
219 | 2.0431758854180635,
220 | 4.748523038758064,
221 | 5.179608154779938,
222 | 2.2696913202744518,
223 | 3.3281195158372068,
224 | 2.139934421660751,
225 | 2.9101018169377553,
226 | 3.5669862413625855,
227 | 4.910551786868566,
228 | 1.0991025453101066,
229 | 2.258733936022483,
230 | 2.4047669589323615,
231 | 2.4143880231355412,
232 | 1.164778645790447,
233 | -0.344171293335233,
234 | 3.436695091313358,
235 | 3.156376468676733,
236 | 1.7628919718764466,
237 | -1.2652809759687724,
238 | 3.9258509839046094,
239 | 1.593487971556471,
240 | 1.5824149531733775,
241 | 1.3056096255686729,
242 | 5.1582090930989155,
243 | 4.2868533520681025,
244 | 2.676389806825718,
245 | 1.1201171886204384,
246 | 2.1163533413596674,
247 | 3.3123744404621855,
248 | 1.948752608943241,
249 | 5.5539152422838045,
250 | 1.8484202725206245,
251 | 3.833778502374519,
252 | 2.870186255666854,
253 | 3.5465736963896184,
254 | 3.0913524478934327,
255 | 2.0571741594674573,
256 | 3.9672010828596065,
257 | 5.762328493927705,
258 | 4.126140801510282,
259 | 5.594224736475578,
260 | 4.2210217766259825,
261 | 3.4211454983681318,
262 | 3.997802704891334,
263 | 2.8898793793396136,
264 | 4.561608216578854,
265 | 3.544814916235046,
266 | 1.1016034762722202,
267 | 1.6815708422008007,
268 | 4.606014807846555,
269 | 1.3610181815681028,
270 | 4.4205225323653865,
271 | 3.5966799662334887,
272 | -0.25130521273306794,
273 | 1.7822493470083007,
274 | 1.4071979206338654,
275 | 3.394512338698792,
276 | 2.5242715607543444,
277 | 4.862014004363578,
278 | 3.229548381550742,
279 | 1.9231398484002424,
280 | 2.516556466617752,
281 | 3.9182651259011836,
282 | 0.7060029320196912,
283 | 2.5641310024232387,
284 | 0.9340749290405553,
285 | 4.449096434872146,
286 | 3.8880766235619606,
287 | 3.774357937626448,
288 | 4.611659996023895,
289 | 1.4994494969253929,
290 | 3.517372101918964,
291 | 2.1849248455227963,
292 | 4.59995634269724,
293 | 0.7136960027492203,
294 | 5.211627705088949,
295 | 0.6809809769073962,
296 | 3.3936243120869585,
297 | 2.3643627442299,
298 | 2.7601836024488273,
299 | 2.150415083443156,
300 | 0.8594907825555675,
301 | 3.601013607356468,
302 | 2.5815168410690594,
303 | 0.825176956446396,
304 | 2.6675514285012016,
305 | 0.5596363230686974,
306 | 2.0959755256496737,
307 | 0.9195654055056771,
308 | 3.4219879460641076,
309 | 2.2178774624079827,
310 | 3.6262623597163133,
311 | 6.647392730222813,
312 | 2.172881054022989,
313 | 3.3689027970322423,
314 | 2.9397896806455144,
315 | 2.6044073624440025,
316 | 3.291622245529817,
317 | 1.201513456362616,
318 | 4.126496864054856,
319 | 3.1421960113419063,
320 | 3.6711309818767077,
321 | 3.4726065834131536,
322 | 2.8487622616388797,
323 | 4.568156273552153,
324 | 1.615003138211266,
325 | 3.3665343343567713,
326 | 2.537919808110008,
327 | 1.8292512485916252,
328 | 3.2337989726995024,
329 | 1.9114807889808343,
330 | 3.467941390163674,
331 | 6.198120129201332,
332 | 4.70861240857948,
333 | 3.9172938367567705,
334 | 2.860840870827083,
335 | 1.5147096895656527,
336 | 3.068973795697625,
337 | 0.28086743000534575,
338 | 2.991173263162835,
339 | 2.0511430132953286,
340 | 2.2384226640106135,
341 | 3.200866785994462,
342 | 0.19361527897099418,
343 | 2.696172688423677,
344 | 3.23769829263132,
345 | 5.103788864320897,
346 | 2.019777303030251,
347 | 0.25956811709961336,
348 | 5.5000364974123315,
349 | 2.6494854204409637,
350 | 3.2682693715627273,
351 | 2.9781437723285307,
352 | 3.9763581685256684,
353 | 3.973076058589834,
354 | 0.4444721038371683,
355 | 3.135146339710915,
356 | 3.6772492403146315,
357 | 1.9504210094916226,
358 | 2.369676046028671,
359 | 4.074107685129584,
360 | 3.550595085456436,
361 | 3.9890652571847207,
362 | 3.5960651547190268,
363 | 2.5120713526201373,
364 | 2.534545188770521,
365 | 3.183705412231074,
366 | 3.742940895087492,
367 | 1.2225012176837444,
368 | 1.5993331043817487,
369 | 3.3336557543369594,
370 | 2.449782359193413,
371 | 1.5347572415031268,
372 | 2.895876718035587,
373 | 1.4120152325805013,
374 | 6.086110859466199,
375 | 5.70602306106435,
376 | 2.5247507738775115,
377 | 2.8723680078408313,
378 | 3.8946733238030316,
379 | 3.369118925731219,
380 | 0.6437384737368583,
381 | 3.0549942729782953,
382 | 5.391910502687995,
383 | 4.140080687403162,
384 | 3.0729305021394553,
385 | 1.6805269998378827,
386 | 3.7993071898115387,
387 | 0.9071266347656909,
388 | 3.5599684874473594,
389 | 5.146754138038862,
390 | 1.6447228525956166,
391 | 3.4734231352792593,
392 | 1.8119840163015264,
393 | 2.3681924446898512,
394 | 2.767006643720069,
395 | 3.95157019722898,
396 | 0.8231663081653723,
397 | 1.9731073618481496,
398 | 1.7778840491701187,
399 | 0.7206223646322524,
400 | 3.2792084300890227,
401 | 3.0179619357641836,
402 | 3.999317774406029,
403 | 3.3120530150165903,
404 | 3.259169219280227,
405 | 2.4719379726820585,
406 | 5.583992891076802,
407 | 3.789303896478031
408 | ]
409 | ]
410 | }
--------------------------------------------------------------------------------
/causing/examples/input/example3.json:
--------------------------------------------------------------------------------
1 | {
2 | "xdat": [
3 | [
4 | 2.8872869691061602,
5 | 1.923436019214106,
6 | 4.785026931424977,
7 | 1.5430166916415569,
8 | 2.6736792144640185,
9 | 1.7401035154707398,
10 | 3.3758664973419217,
11 | 2.1218526337110184,
12 | 2.6500242287369096,
13 | 3.2966602028589476,
14 | 4.200911925211615,
15 | 1.4310047612935157,
16 | 4.854028741791787,
17 | 3.493961807966228,
18 | 2.869288568402771,
19 | 2.596879247501283,
20 | 2.0263377372073608,
21 | 2.532533218572503,
22 | 2.2820785332228883,
23 | 4.2213933066552505,
24 | 2.2227999905821543,
25 | 2.4114743520286543,
26 | 2.942381145922457,
27 | 3.0795798842600206,
28 | 1.8167989405733076,
29 | 1.4512575542517088,
30 | 3.912256171757456,
31 | 3.412670735564499,
32 | 2.304230997962419,
33 | 0.7112281165759713,
34 | 2.212758471472195,
35 | 1.9714833280983022,
36 | 3.0933081068260373,
37 | 2.470805833831886,
38 | 3.7802448586640867,
39 | 2.79918530449522,
40 | 2.519391413372405,
41 | 1.9647378761789605,
42 | 2.4972656287527957,
43 | 3.7898902024041283,
44 | 2.075002378029681,
45 | 5.210035319426028,
46 | 1.599763814234508,
47 | 2.7609026210900796,
48 | 3.2173406802207793,
49 | 2.6476147188864747,
50 | 3.0858755266228397,
51 | 3.1066519708560043,
52 | 2.802968785886549,
53 | 4.346933859556485,
54 | 3.3451739807671483,
55 | 3.557644416067242,
56 | 2.4047148350193743,
57 | 3.7328321909133715,
58 | 4.331252678012974,
59 | 2.2699670626370727,
60 | 2.5142442071775224,
61 | 4.076914216230647,
62 | 0.40464257762082045,
63 | 3.1669281829423115,
64 | 4.0389596412374775,
65 | 1.191426140039237,
66 | 3.7586409441262836,
67 | 2.4998871918615406,
68 | 0.6557068408092563,
69 | 2.8920823107737323,
70 | 1.49721232937859,
71 | 3.4887786612651634,
72 | 2.446821476108088,
73 | 4.057507525214147,
74 | 2.130682143294284,
75 | 2.9249089067318836,
76 | 2.8928450354571593,
77 | 5.098822017803357,
78 | 2.65946206614633,
79 | 2.4720948927464113,
80 | 1.7053831777164132,
81 | 3.2140990318960836,
82 | 4.126269575524226,
83 | 3.401535844811228,
84 | 3.7655853172760128,
85 | 1.6468725457769033,
86 | 3.5738584993611338,
87 | 2.7798628731285846,
88 | 3.645188978621543,
89 | 1.9952806924726025,
90 | 4.899738557080213,
91 | 3.216860817678221,
92 | 3.499970383255115,
93 | 2.373408919020704,
94 | 1.997115783987647,
95 | 2.218689776415458,
96 | 3.204277735537852,
97 | 3.536092005094851,
98 | 1.9250025366322525,
99 | 0.7821452408708565,
100 | 3.6469302206281182,
101 | 2.677664203879725,
102 | 2.8274358144735015,
103 | 0.7115781974058732,
104 | 2.8879561501492454,
105 | 3.955313813089303,
106 | 3.45473818292903,
107 | 5.061927453612517,
108 | 3.062460465192962,
109 | 3.002842437780612,
110 | 2.5464461674841923,
111 | 3.3734825020035344,
112 | 2.186884007640653,
113 | 2.89844249021185,
114 | 3.445713200789419,
115 | 1.724871360740863,
116 | 3.1078318128236835,
117 | 3.852236887650466,
118 | 2.8431479090574925,
119 | 4.188819261366114,
120 | 1.5277366136014627,
121 | 3.8660408408090556,
122 | 2.106610472737535,
123 | 2.4510293875211007,
124 | 3.001462948847881,
125 | 2.09857755095916,
126 | 2.4944514415718055,
127 | 4.2318542067430736,
128 | 4.758176140420122,
129 | 4.538161757938014,
130 | 3.7946416510491887,
131 | 2.0930331217905254,
132 | 2.908823602380252,
133 | 0.9080129653456019,
134 | 2.731887381170233,
135 | 2.0180658260146975,
136 | 2.40603677745438,
137 | 4.225176625455613,
138 | 2.1664383556553113,
139 | 2.7729114286394254,
140 | 3.6441244592704134,
141 | 4.390163761705033,
142 | 2.2182410399027823,
143 | 0.170542007314733,
144 | 3.3051991650580543,
145 | 3.4320711298075115,
146 | 2.501928484246964,
147 | 3.119178411883016,
148 | 2.9445662409692055,
149 | 4.5889307845912795,
150 | 1.1876853032251635,
151 | 1.536671603685592,
152 | 2.6208023317844744,
153 | 2.1983178065939715,
154 | 2.96889984080992,
155 | 2.5824522778006074,
156 | 3.270149615184717,
157 | 2.3778831437196666,
158 | 2.739032565895155,
159 | 1.9266673795035667,
160 | 1.673923343601349,
161 | 2.795795376691757,
162 | 3.2579314850568326,
163 | 1.4710137133918215,
164 | 1.8502340173256802,
165 | 2.7887085658978172,
166 | 3.8311648452832605,
167 | 0.8159150339221504,
168 | 3.7311102235595213,
169 | 2.2472652273470786,
170 | 6.2592559170283915,
171 | 4.655363170578773,
172 | 0.9484913453096051,
173 | 2.140850520427705,
174 | 2.767983030562516,
175 | 3.9927580131174896,
176 | 2.116166313265303,
177 | 2.9395931404512505,
178 | 4.066938240964659,
179 | 3.211657486472749,
180 | 3.7648748965769148,
181 | 2.5507756730565037,
182 | 2.483665572184565,
183 | 1.379213703600541,
184 | 2.8861545302601717,
185 | 4.815526730641361,
186 | 2.5734428378111573,
187 | 2.216556176346062,
188 | 3.2759071317142463,
189 | 3.2824437653576974,
190 | 4.2115136836422185,
191 | 2.1770417008769942,
192 | 1.549904523402743,
193 | 3.31282611297537,
194 | 3.4763530654671584,
195 | 1.4348939038366062,
196 | 2.571267249401294,
197 | 4.363585550849811,
198 | 4.039451329698665,
199 | 3.3959077027379285,
200 | 3.371804663869714,
201 | 3.4513005749478496,
202 | 3.621954815294834,
203 | 3.842496009671126
204 | ]
205 | ],
206 | "ymdat": [
207 | [
208 | 2.9486814185520944,
209 | 1.5643995019419075,
210 | 3.8181630953107675,
211 | -0.2557294149369711,
212 | 2.5681735114302957,
213 | 2.471343783806664,
214 | 4.660774205481619,
215 | 1.9691122177048468,
216 | 1.998003933954049,
217 | 3.0403659359711814,
218 | 5.91400443764403,
219 | 0.2658085530303025,
220 | 5.0110271352451,
221 | 3.016446046024285,
222 | 3.1179450266888877,
223 | 3.4958382250044266,
224 | 3.190570034180418,
225 | 4.56911353898084,
226 | 1.9486285601012483,
227 | 3.6892940066596496,
228 | 2.789855157191232,
229 | 3.5082671264006025,
230 | 2.852366737177732,
231 | 3.884086363409452,
232 | 1.4405103717339003,
233 | 1.543293663928536,
234 | 3.6740632197951903,
235 | 3.2652476867129883,
236 | 3.258998362038116,
237 | -1.8246517241948537,
238 | 2.9758262899333756,
239 | 2.0364049303599185,
240 | 2.1139293146991207,
241 | 2.67879304193169,
242 | 3.95176903545137,
243 | 3.1652456637468505,
244 | 3.624129651261569,
245 | 3.382062526780004,
246 | 2.502879981334183,
247 | 3.290383695951844,
248 | 2.307338401881303,
249 | 7.176301241884286,
250 | 0.6659630340124022,
251 | 2.1337570857498234,
252 | 3.049726566777013,
253 | 2.5708759786707263,
254 | 2.8874117897503084,
255 | 2.3240662614894565,
256 | 3.834760713443012,
257 | 5.9454085955818075,
258 | 2.7459501859858997,
259 | 5.168826529532296,
260 | 3.2653366801885464,
261 | 3.4843196952052944,
262 | 2.9498701919231265,
263 | 1.4347170678704955,
264 | 4.090503635745429,
265 | 3.4532751288443766,
266 | 1.7296148393441564,
267 | 2.2966795097236905,
268 | 4.712773598424665,
269 | 2.4482930989724343,
270 | 2.3141339042041342,
271 | 1.16016844073432,
272 | 1.3636480214969848,
273 | 2.808227623052394,
274 | 3.4592504051605584,
275 | 3.875372341462055,
276 | 1.5259703832894007,
277 | 3.398699269380522,
278 | 2.0037237036098294,
279 | 2.958895098962748,
280 | 0.2989551648771904,
281 | 3.974723919134424,
282 | 2.141173183687305,
283 | 3.386270423521602,
284 | 3.9707909484090536,
285 | 2.95652842068491,
286 | 4.809014766965124,
287 | 2.2164380122188376,
288 | 2.0960322203245956,
289 | 0.15189046920629834,
290 | 3.602744896245628,
291 | 2.4669694711035266,
292 | 4.436824107445079,
293 | 1.0373353392974671,
294 | 4.964726898564631,
295 | 2.958507480100587,
296 | 4.14916584086813,
297 | 2.231107234820795,
298 | 2.112981634711213,
299 | 1.9672517642114862,
300 | 2.3868976095272028,
301 | 2.8524740059391576,
302 | 1.6054616157367865,
303 | 1.5710560339362676,
304 | 5.464357369689663,
305 | 3.7045543957293505,
306 | 4.580863886577676,
307 | 1.688491928247433,
308 | 2.6921776239306086,
309 | 4.45265078605661,
310 | 2.734052354081108,
311 | 5.825940628293769,
312 | 3.2228696905611582,
313 | 3.9647456885240744,
314 | 2.6583147181319386,
315 | 4.33562973259637,
316 | 2.4893764946828734,
317 | 1.6548380066668886,
318 | 3.253880531024228,
319 | 1.8870521086720797,
320 | 1.4390734927304838,
321 | 2.276430786333944,
322 | 1.5352826733318783,
323 | 3.7214793181087544,
324 | -0.9489266622055197,
325 | 2.994443302753691,
326 | 2.4433190813621284,
327 | 2.1243186387466806,
328 | 1.6049819676088293,
329 | 0.7482370764490036,
330 | 1.498402830436671,
331 | 2.274478526825745,
332 | 4.5201621027813,
333 | 5.143417667711427,
334 | 5.022927912412393,
335 | 3.255748076926915,
336 | 4.520056092023544,
337 | 1.9686191131229334,
338 | 1.148648614806266,
339 | 0.9367141758147841,
340 | 2.7397915908302015,
341 | 5.6335175000600834,
342 | 2.348803298051457,
343 | 2.593554411761902,
344 | 4.799828630080503,
345 | 6.194137954871157,
346 | 1.8512624616386968,
347 | 0.6923691409186945,
348 | 3.2519438740112196,
349 | 3.4124788477671717,
350 | 3.6906540002080597,
351 | 2.0914679217351573,
352 | 3.0975984786502293,
353 | 4.322282285287827,
354 | 1.3451582125588888,
355 | 1.4093001625390897,
356 | 2.9909070522737697,
357 | 2.9968654872254716,
358 | 5.20256156125959,
359 | 3.743146224558327,
360 | 2.7645586143646526,
361 | 2.926190501540802,
362 | 1.3305817833723705,
363 | 3.2923076829740876,
364 | 3.0626572764871915,
365 | 1.8997802674482687,
366 | 3.4341745470925797,
367 | 1.5038451373832906,
368 | 2.462349190165779,
369 | 2.961970512452176,
370 | 1.7247281353019903,
371 | -0.0701160647457647,
372 | 5.499748328956942,
373 | 2.113429365207714,
374 | 5.483645964241033,
375 | 3.715321684895784,
376 | 1.3494326779258243,
377 | 2.4341472624507676,
378 | 2.2905454365903757,
379 | 2.614804084986206,
380 | 3.1594552310582973,
381 | 3.713177747785976,
382 | 3.3289752206059573,
383 | 2.6048475499946107,
384 | 3.5759395809097807,
385 | 1.7171895853276655,
386 | 3.496595650720497,
387 | -0.2949349997438686,
388 | 2.424258331405327,
389 | 5.377414589144412,
390 | 3.159766428006025,
391 | 2.855140937779442,
392 | 2.3692780529833937,
393 | 3.877122514443179,
394 | 2.4087136036114387,
395 | 2.744036899937371,
396 | 0.9099370410745223,
397 | 3.098426167091282,
398 | 3.5861738999296042,
399 | 2.1048236649167147,
400 | 4.12942365700744,
401 | 4.070527935050184,
402 | 3.4282722026102546,
403 | 1.5493803518664258,
404 | 2.298313360501771,
405 | 5.401125256562746,
406 | 5.242906952434235,
407 | 4.299450361955542
408 | ]
409 | ]
410 | }
--------------------------------------------------------------------------------
/causing/examples/models.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """Model Examples."""
3 |
4 | import json
5 | from pathlib import Path
6 |
7 | import numpy as np
8 | import sympy
9 | from sympy import symbols
10 |
11 | from causing.model import Model
12 |
13 | data_path = Path(__file__.split("causing")[0]) / "causing" / "examples" / "input"
14 |
15 |
16 | def example():
17 | """model example 1"""
18 |
19 | X1, X2, Y1, Y2, Y3 = symbols(["X1", "X2", "Y1", "Y2", "Y3"])
20 | equations = ( # equations in topological order (Y1, Y2, ...)
21 | X1,
22 | X2 + 2 * Y1**2,
23 | Y1 + Y2,
24 | )
25 | m = Model(
26 | xvars=[X1, X2], # exogenous variables in desired order
27 | yvars=[Y1, Y2, Y3], # endogenous variables in topological order
28 | equations=equations,
29 | final_var=Y3, # final variable of interest, for mediation analysis
30 | )
31 |
32 | with open(data_path / "example.json") as f:
33 | input_data = json.load(f)
34 | xdat = np.array(input_data["xdat"])
35 |
36 | return m, xdat
37 |
38 |
39 | def example2():
40 | """model example 2, no regularization required, no latent variables"""
41 |
42 | X1, Y1 = symbols(["X1", "Y1"])
43 | equations = (X1,)
44 | m = Model(
45 | equations=equations,
46 | xvars=[X1],
47 | yvars=[Y1],
48 | final_var=Y1,
49 | )
50 |
51 | with open(data_path / "example2.json") as f:
52 | input_data = json.load(f)
53 | xdat = np.array(input_data["xdat"])
54 |
55 | return m, xdat
56 |
57 |
58 | def example3():
59 | X1, Y1, Y2, Y3 = symbols(["X1", "Y1", "Y2", "Y3"])
60 | equations = (
61 | 2 * X1,
62 | -X1,
63 | Y1 + Y2,
64 | )
65 | m = Model(
66 | equations=equations,
67 | xvars=[X1],
68 | yvars=[Y1, Y2, Y3],
69 | final_var=Y3,
70 | )
71 |
72 | with open(data_path / "example3.json") as f:
73 | input_data = json.load(f)
74 | xdat = np.array(input_data["xdat"])
75 |
76 | return m, xdat
77 |
78 |
79 | def education():
80 | """Education
81 |
82 | The dataset contains following variables in this order, the variables 0.
83 | to 4. being time varying and variables 5. to 9. being time invariant:
84 |
85 | 0. PERSONID = Person id (ranging from 1 to 2,178) # not used by us
86 | 1. EDUC = Education (years of schooling)
87 | 2. LOGWAGE = Log of hourly wage, at most recent job, in real 1993 dollars # we use wage instead of log wage
88 | 3. POTEXPER = Potential experience (= AGE - EDUC - 5)
89 | 4. TIMETRND = Time trend (starting at 1 in 1979 and incrementing by year) # not used by us
90 | 5. ABILITY = Ability (cognitive ability measured by test score)
91 | 6. MOTHERED = Mother's education (highest grade completed, in years)
92 | 7. FATHERED = Father's education (highest grade completed, in years)
93 | 8. BRKNHOME = Dummy variable for residence in a broken home at age 14
94 | 9. SIBLINGS = Number of siblings
95 |
96 | Model identified without regularization if wage instead of logwage and all observations. # yyyy
97 |
98 | ToDo: Automatic Hessian gives wrong results for this example: # yyyy
99 | Algebraic and numeric Hessian allclose: True.
100 | Automatic and numeric Hessian allclose: False.
101 | Automatic and algebraic Hessian allclose: False.
102 | No problem if ABILITY has zero effect
103 | """
104 |
105 | (
106 | FATHERED,
107 | MOTHERED,
108 | SIBLINGS,
109 | BRKNHOME,
110 | ABILITY,
111 | AGE,
112 | EDUC,
113 | POTEXPER,
114 | WAGE,
115 | ) = symbols(
116 | [
117 | "FATHERED",
118 | "MOTHERED",
119 | "SIBLINGS",
120 | "BRKNHOME",
121 | "ABILITY",
122 | "AGE",
123 | "EDUC",
124 | "POTEXPER",
125 | "WAGE",
126 | ]
127 | )
128 |
129 | equations = (
130 | # EDUC
131 | 13
132 | + 0.1 * (FATHERED - 12)
133 | + 0.1 * (MOTHERED - 12)
134 | - 0.1 * SIBLINGS
135 | - 0.5 * BRKNHOME,
136 | # POTEXPER
137 | sympy.Max(AGE - EDUC - 5, 0),
138 | # WAGE
139 | 7 + 1 * (EDUC - 12) + 0.5 * POTEXPER + 1 * ABILITY,
140 | )
141 | m = Model(
142 | equations=equations,
143 | xvars=[FATHERED, MOTHERED, SIBLINGS, BRKNHOME, ABILITY, AGE],
144 | yvars=[EDUC, POTEXPER, WAGE],
145 | final_var=WAGE,
146 | )
147 |
148 | # load and transform data
149 | from numpy import array, concatenate, loadtxt
150 |
151 | xymdat = loadtxt(data_path / "education.csv", delimiter=",").reshape(-1, 10)
152 | xymdat = xymdat.T # observations in columns
153 | # xymdat = xymdat[:, 0:200] # just some of the 17,919 observations
154 | xdat = xymdat[[7, 6, 9, 8, 5]] # without PERSONID, TIMETRND
155 | age = array(xymdat[3, :] + xymdat[1, :] + 5).reshape(
156 | 1, -1
157 | ) # age = POTEXPER + EDUC + 5
158 | xdat = concatenate((xdat, age))
159 |
160 | return m, xdat
161 |
162 |
163 | def heaviside():
164 | """Minimal example exercise correct Heaviside(0) handling"""
165 |
166 | X1, Y1 = symbols(["X1", "Y1"])
167 | m = Model(
168 | xvars=[X1],
169 | yvars=[Y1],
170 | equations=(sympy.Max(X1, 0),),
171 | final_var=Y1,
172 | )
173 |
174 | xdat = np.array([[-1, -2, 3, 4, 5, 6]])
175 | return m, xdat
176 |
--------------------------------------------------------------------------------
/causing/graph.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """Create direct, total and mediation Graphviz graph from dot_str"""
3 | import re
4 | import subprocess
5 | from typing import Iterable
6 | from itertools import chain
7 | from pathlib import Path
8 | from functools import cache
9 |
10 | import numpy as np
11 | import networkx
12 |
13 | from causing.model import Model
14 | from causing import utils
15 |
16 |
17 | DOT_COMMAND = "dot"
18 |
19 |
20 | @cache
21 | def dot_version() -> list[int]:
22 | full_output = subprocess.check_output(
23 | [DOT_COMMAND, "-V"], encoding="utf-8", stderr=subprocess.STDOUT
24 | )
25 | match = re.search(r"(\d+[.])+\d+", full_output)
26 | assert match
27 | version = match.group(0)
28 | return [int(x) for x in version.split(".")]
29 |
30 |
31 | def fix_svg_scale(svg_code):
32 | """Work around graphviz SVG generation bug
33 |
34 | Graphviz divides the numbers in the viewBox attribute by the scale instead
35 | of multiplying it. We work around it my multiplying with the scale twice.
36 | See https://github.com/realrate/RealRate-Private/issues/631
37 | and https://gitlab.com/graphviz/graphviz/-/issues/1406
38 | """
39 | # find scaling factor
40 | scale_match = re.search(r"scale\(([0-9.]+)", svg_code)
41 | assert scale_match
42 | factor = float(scale_match.group(1)) ** 2
43 |
44 | # edit SVG tag
45 | orig_svg_tag = next(re.finditer(r"", svg_code, flags=re.DOTALL)).group(0)
46 | attrs = {
47 | match.group(1): match.group(2)
48 | for match in re.finditer(r'(\w+)="(.*?)"', orig_svg_tag)
49 | }
50 | new_svg_tag = "