# Causal Discovery via Quantile Partial Effect

### QPE-k (Kernel-based QPE with Least Square Basis Test)

QPE-k is an algorithm for bivariate causal discovery.

```python
import numpy
from qpek import qpe_k
qpe_12, score_12, qpe_21, score_21 = qpe_k(
    x1=x1, # NDArray shaped (n, )
    x1=x2, # NDArray shaped (n, )
    basis_funcs=[
        lambda y: numpy.ones_like(y),
        lambda y: y,
        lambda y: y**3,
        lambda y: numpy.tanh(y),
    ],
)
is_x1_to_x2 = score_12 > score_21
```

> Requirements: `numpy`.

To reproduce results, run:

```shell
python -m reproduce.run_qpek
```

### QPE-f (Flow-based QPE with Neural Basis Test)

QPE-f is an algorithm for bivariate causal discovery.

```python
import torch
from qpef import qpe_f, UMNNConditionalTransform, FixedBasisNeuralQPE
qpe_12, score_12, qpe_21, score_21 = qpe_f(
    x1=x1, # NDArray shaped (n, )
    x1=x2, # NDArray shaped (n, )
    transform_cls=UMNNConditionalTransform,
    transforms=1,
    neural_qpe_cls=FixedBasisNeuralQPE,
    neural_qpe_kwargs={
        'basis_funcs': [
            lambda y: torch.ones_like(y),
            lambda y: y,
        ],
    },
)
is_x1_to_x2 = score_12 > score_21
```

> Requirements: `numpy`, `torch`, `zuko`.

To reproduce results, run:

```shell
python -m reproduce.run_qpef_hyper # hyper QPE
python -m reproduce.run_qpef_hyper # lowrank QPE
python -m reproduce.run_qpef_poly # constant QPE
python -m reproduce.run_qpef_fixed # affine QPE
```

we only provide some basic results, while you can modify these scripts for hyperparameter tuning.

### FICO (Fisher Information Causal Ordering)

FICO is an algorithm for multivariate causal ordering.

```python
from fico import fico
order = fico(
    X=X, # NDArray shaped (n, d)
    eta_G=0.001,
)
order, graph = fico(
    X=X, # NDArray shaped (n, d)
    eta_G=0.001,
    alpha=0.05,
    return_graph=True,
)
```

> Requirements: `numpy`, `scikit-learn`, `causal-learn`.

To reproduce results, run:

```shell
python -m reproduce.run_fico
```