Skip to content

Commit

Permalink
docs(README): add a more detailed README
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithWittmann committed Oct 22, 2023
1 parent 691197c commit 478d3d2
Showing 1 changed file with 102 additions and 16 deletions.
118 changes: 102 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,41 @@

Causal discovery made easy.

## Dev usage

### Setup
We recommend using poetry to manage the dependencies. To install poetry follow the instructions on https://python-poetry.org/docs/#installation.

Install dependencies
## Installation
Currently we only support python 3.11. To install causy run
```bash
poetry install
pip install causy
```

Execute tests
```bash
poetry run python -m unittest discover -s tests
```
## Usage
Causy can be used via CLI or via code.

### Usage via CLI

Run causy with one of the default algorithms
```bash
poetry run causy execute --help
poetry run causy execute tests/fixtures/toy_data_larger.json --algorithm PC
causy execute --help
causy execute your_data.json --algorithm PC --output-file output.json
```

Customize your causy pipeline by ejecting and modifying the pipeline file.
The data you can use is a json file with a list of dictionaries. Each dictionary represents a data point. The keys of the dictionary are the variable names and the values are the values of the variables. The values can be either numeric or categorical.

```json
[
{"a": 1, "b": 0.3},
{"a": 0.5, "b": 0.2}
]
```

You can customize your causy pipeline by ejecting and modifying the pipeline file.
```bash
poetry run causy eject PC pc.json
causy eject PC pc.json
# edit pc.json
poetry run causy execute tests/fixtures/toy_data_larger.json --pipeline pc.json
causy execute tests/fixtures/toy_data_larger.json --pipeline pc.json
```

This might be useful if you want to use a custom algorithm or if you want to customize the pipeline of a default algorithm.


### Usage via Code

Expand All @@ -58,3 +63,84 @@ for edge in edges:
)

```

Use a custom algorithm

```python
from causy.exit_conditions import ExitOnNoActions
from causy.graph import graph_model_factory, Loop
from causy.independence_tests import (
CalculateCorrelations,
CorrelationCoefficientTest,
PartialCorrelationTest,
ExtendedPartialCorrelationTestMatrix,
)
from causy.orientation_tests import (
ColliderTest,
NonColliderTest,
FurtherOrientTripleTest,
OrientQuadrupleTest,
FurtherOrientQuadrupleTest,
)
from causy.utils import retrieve_edges

CustomPC = graph_model_factory(
pipeline_steps=[
CalculateCorrelations(),
CorrelationCoefficientTest(threshold=0.1),
PartialCorrelationTest(threshold=0.01),
ExtendedPartialCorrelationTestMatrix(threshold=0.01),
ColliderTest(),
Loop(
pipeline_steps=[
NonColliderTest(),
FurtherOrientTripleTest(),
OrientQuadrupleTest(),
FurtherOrientQuadrupleTest(),
],
exit_condition=ExitOnNoActions(),
),
]
)

model = CustomPC()

model.create_graph_from_data(
[
{"a": 1, "b": 0.3},
{"a": 0.5, "b": 0.2}
]
)
model.create_all_possible_edges()
model.execute_pipeline_steps()
edges = retrieve_edges(model.graph)

for edge in edges:
print(
f"{edge[0].name} -> {edge[1].name}: {model.graph.edges[edge[0]][edge[1]]}"
)
```

### Supported algorithms
Currently causy supports the following algorithms:
- PC (Peter-Clark)
- PC - the original PC algorithm without any modifications ```causy.algorithms.PC```
- ParallelPC - a parallelized version of the PC algorithm ```causy.algorithms.ParallelPC```

### Supported pipeline steps
Detailed information about the pipeline steps can be found in the [API Documentation](https://causy-dev.github.io/causy/causy.html).

## Dev usage

### Setup
We recommend using poetry to manage the dependencies. To install poetry follow the instructions on https://python-poetry.org/docs/#installation.

Install dependencies
```bash
poetry install
```

Execute tests
```bash
poetry run python -m unittest discover -s tests
```

0 comments on commit 478d3d2

Please sign in to comment.