Conin supports constrained inference and learning for hidden Markov models, Bayesian networks, dynamic Bayesian networks, and Markov networks. It includes native model classes, reusable constraint declarations, HMM learning utilities, examples, and interfaces to optional backends such as pgmpy, Pyomo-compatible solvers, and Toulbar2.
Install Conin from a local checkout with:
python -m pip install -e .
Optional extras are available for documentation, tests, and the optional backends:
python -m pip install -e .[docs]
python -m pip install -e .[test]
python -m pip install -e .[pgmpy] # BIF files, pgmpy model conversion
python -m pip install -e .[toulbar2] # Toulbar2 inference
python -m pip install -e .[torch] # the MVR algorithms
python -m pip install -e .[regex] # mvr_regex
Conin 2.0 reorganised the package (models in conin.graphical_models,
constrained models in conin.constrained_models, algorithms by backend under
conin.algorithms.inference, conin.algorithms.learning,
conin.algorithms.sampling and conin.algorithms.scoring). Old import paths
were removed without aliases; see
CHANGELOG.md for the migration table.
Optional backends and solver requirements are described in the backend requirements page in the documentation.
The documentation is published on Read the Docs:
https://conin.readthedocs.io/en/latest/
Useful starting points include:
- Quickstart and installation
- Selected examples
- Backend and optional dependency guide
- Model conversion and I/O
- HMM learning
- API reference
- Architecture and design notes (for contributors)
To build the documentation locally:
python -m pip install -e .[docs]
python -m sphinx -b html doc/sphinx doc/sphinx/_build/html
The generated HTML is written to doc/sphinx/_build/html.
As an alternative to the documentation, the Jupyter notebooks in
doc/notebooks/ walk through Conin with runnable examples:
HMM_basics,BN_basics,DBN_basicsandMN_basics: building each model typeconstraints: declaring constraintsinference: MAP queries with every inference methodMVR/: the MVR (mediation variable) algorithms, starting withoverview(these need thetorchextra;regex_tutorialneeds theregexextra)
Some notebooks use the optional backends (pgmpy, pytoulbar2, a MIP solver).
Conin tests can be executed using pytest:
cd conin
pytest .
Tests that need an optional backend (pgmpy, pytoulbar2, torch, a MIP solver)
are skipped when it is not installed. The notebooks in doc/notebooks/ are
run with pytest --nbmake --nbmake-kernel=python3 doc/notebooks/*.ipynb doc/notebooks/MVR/*.ipynb.
If the pytest-cov package is installed, pytest can provide coverage statistics:
cd conin
pytest --cov=conin .
The following options list the lines that are missing from coverage tests:
cd conin
pytest --cov=conin --cov-report term-missing .
Note that pytest coverage includes coverage of test files themselves. This gives a somewhat skewed sense of coverage for the code base, but it helps identify tests that are omitted or not executed completely.
