Skip to main content

Whydra

Быстрая библиотека для поиска причинно-следственных связей (causal discovery): реализации PC-stable, FCI-stable и RAI с поддержкой параллельных вычислений.

Установка

pip install whydra

Требуется Python 3.10+.

Для сохранения изображений графов (whydra.evaluation.graph_utils.draw_graph) в системе должен быть установлен Graphviz:

  • Linux: sudo apt-get install graphviz
  • Windows: Скачайте инсталлятор с сайта Graphviz, установите и добавьте путь к bin в PATH.

Быстрый старт

import numpy as np
from whydra import StandalonePCStable

rng = np.random.default_rng(0)
x1, x2 = rng.normal(size=(2, 1000))
x3 = x1 + x2 + rng.normal(scale=0.5, size=1000)
data = np.column_stack([x1, x2, x3])  # (n_samples, n_features)

graph = StandalonePCStable(alpha=0.05, indep_test="fisherz", n_jobs=4).run(data)
print(graph)  # GeneralGraph из causal-learn: X1 --> X3, X2 --> X3

Доступные алгоритмы: StandalonePCStable, StandaloneFCIStable, StandaloneRAIStable, StandaloneRAIOptimized. Тесты независимости: fisherz (непрерывные данные) и chisq (дискретные).

Лицензия

Whydra распространяется по лицензии Apache License 2.0.

Бенчмарки

Для запуска бенчмарков склонируйте репозиторий и установите пакет вместе с зависимостями для бенчмарков (Hydra и др.):

git clone https://github.com/sb-ai-lab/Whydra.git
cd Whydra
pip install -e ".[bench]"

Точные версии библиотек, на которых проводились замеры, зафиксированы в requirements.txt (pip install -r requirements.txt).

Как запускать

  1. Прописываем в configs/config.yaml
defaults:
  - _self_
  # выбираем нужный алгоритм 
  - algorithm: rai_stable
  # выбираем нужные датасет
  - benchmark: feedback

# Общие настройки
output_dir: "results"
output_filename: "results.csv"
output_filename_for_bootstrap: "results_by_bootstraps.csv"

# Сохранить промежуточные файлы и графы
keep_intermediate_files: False
# Продолжить расчет с уже посчитанными графами в algo_results/{benchmark_name}
resume: False

# включаем бутстрап 
bootstrap: True
# количество итераций бутстрапа
n_bootstraps: 1
# сид для бутстрапинга
seed: 42

# Настройки визуализации
save_plots: true
plots_dir: "plots"
  1. После этого запускаем
python main.py

После выполнения скрипта в папке output_filename появятся метрики в файле output_filename. А сами изображения графов появятся в plots_dir

В поле algorithm можно выбрать алгоритм:

pc_stable
fci_stable
rai_stable

Для запуска параллельной версии алгоритмов только для pc_stable, fci_stable, rai_stable необходимо заполнить количество параллельных потоков в соответствующем файле алгоритма. При отсутствии переменной или при значении 1 расчет запускается в последовательном режиме.

n_jobs: 6

В поле benchmark можно выбрать следующие бенчмарки:

tetrad_discrete
tetrad_linear
# оба содержат в себе по 10 бенчмарков
# в configs/benchmark/tetrad_discrete.yaml
# и в configs/benchmark/tetrad_linear.yaml

bnlearn
# содержит в себе в configs/benchmark/bnlearn.yaml   
# следующие бенчмарки 
  - alarm
  - child
  - insurance
  - water

также есть два дополнительных бенчмарка меньшего размера:

feedback  
lucas

они использовались как вспомогательные во время разработки.

Данные к бенчмаркам feedback и lucas:

https://drive.google.com/file/d/1CrjmgghvCyx0l5RsABnn53Kiyl-LfxuP/view?usp=sharing

Их нужно распаковать и прописать в конфиге пути

configs/benchmark/feedback.yaml

там нужен путь к папке

example-causal-datasets/simulated/feedbacks/  (увидите как в конфиге)
configs/benchmark/lucas.yaml

нужен путь к папке

lucas/data/   (увидите как в конфиге)

Данные к бенчмаркам bnlearn:

https://drive.google.com/file/d/1t3DUjOpOn7Zztt252mGGHowxC3j2n8x7/view?usp=sharing

Их нужно распаковать и прописать в конфиге пути

configs/benchmark/bnlearn.yaml

Запускать алгоритм можно командой:

python main.py algorithm=pc_stable benchmark=bnlearn 

Данные к бенчмаркам Tetrad

https://drive.google.com/file/d/1PEUl6F9y2urkgHGR-YdPDbPe7UsFHmwm/view?usp=sharing

Их нужно распаковать и прописать пути в конфигах:

configs/benchmark/tetrad_discrete.yaml
configs/benchmark/tetrad_linear.yaml

Запускаются командами:

python main.py benchmark=tetrad_discrete algorithm=pc_stable
python main.py benchmark=tetrad_linear algorithm=pc_stable

Metadata

Release files for whydra 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whydra 0.1.0
File Size Uploaded Provenance Actions
whydra-0.1.0.tar.gz 47.8 kB With provenance Details for whydra-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for whydra 0.1.0
File Interpreter ABI Platform Actions
whydra-0.1.0-py3-none-any.whl Python 3 none any Details for whydra-0.1.0-py3-none-any.whl

Total release size: 113.8 kB

Release files / whydra-0.1.0.tar.gz

Download URL whydra-0.1.0.tar.gz
Size 47.8 kB
Tags Source
SHA-256 checksum
How to use checksums
55b6952bd7102565d194ec01960a66c94cf16c4ce6b538e96db0c7b6ac34d983
BLAKE2b-256 checksum
How to use checksums
d9ff77ab3d3b97aa9c26063002f99884d4f06ba06b41c7ec31c50371dcdcb786
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Release files / whydra-0.1.0-py3-none-any.whl

Download URL whydra-0.1.0-py3-none-any.whl
Size 66.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bec0f22e5d9e72dc35587396cd02ee9225c0ad6dcf078693fcfe9f34e657f3d0
BLAKE2b-256 checksum
How to use checksums
50db248d0be420fc462ad238cbdd8c67665f66ea1b9fae1b92a6d8d0ef895a8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Security for whydra 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for whydra-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page