Deep Jointly-Informed Neural Networks
DJINN: Deep jointly-informed neural networks
Fork notice: This repository is a fork and continuation of LLNL's DJINN project (Deep Jointly-Informed Neural Networks) originally developed by Kelli D. Humbird (humbird1@llnl.gov). The original project is available at https://github.com/LLNL/djinn and is distributed under the license found in LICENSE. This fork is maintained by Ben Whewell (ben.whewell@pm.me) — https://github.com/bwhewe-13/DJINN
DJINN is an easy-to-use algorithm for training deep neural networks on supervised regression tasks. For additional information, refer to the paper "Deep neural network initialization with decision trees", cited below.
Getting Started
Original DJINN required TensorFlow. This fork is implemented with PyTorch.
Requirements:
- Python 3.10+
- PyTorch
- scikit-learn 1.6+
Install from PyPI (the import name is djinn):
python -m pip install djinnml
Or install from source:
git clone https://github.com/bwhewe-13/DJINN.git
cd DJINN
python -m pip install --upgrade pip
python -m pip install .
The examples are Jupyter notebooks in docs/examples, and they're also on the examples page of the docs with download and Colab links. They cover regression, classification, multiple outputs, uncertainty, scikit-learn pipelines and how the trees become networks.
Using DJINN with scikit-learn
DJINN_Regressor and DJINN_Classifier are scikit-learn estimators, so they
work with Pipeline, cross_val_score, GridSearchCV and clone:
from sklearn.model_selection import GridSearchCV
from djinn import DJINN_Regressor
model = DJINN_Regressor(n_trees=3, learning_rate=0.005, epochs=300, random_state=0)
search = GridSearchCV(model, {"max_tree_depth": [3, 4, 5]}, cv=5)
search.fit(X, y)
search.best_estimator_.save("best_model")
If learning_rate is left as None, fit() searches for a learning rate,
number of epochs and batch size first. That search trains about 2,000 epochs,
so set learning_rate when fitting many models, e.g. in a grid search.
Notes:
- The scikit-learn version used when training a DJINN model should match the version used when loading/evaluating that saved model.
- The example notebooks also need
jupyter,matplotlibandpandas.
Development
Set up a local development environment:
python -m pip install --upgrade pip
python -m pip install -e .[dev]
Run quality checks and tests:
black --check djinn tests docs/examples
isort --check-only djinn tests
flake8
pytest
Enable pre-commit hooks (optional, recommended):
pre-commit install
pre-commit run --all-files
Build docs locally (nbsphinx also needs pandoc):
python -m pip install -e .[docs]
python -m sphinx -M html docs docs/_build
Documentation
The documentation is hosted at https://www.ben-whewell.com/DJINN/. It covers
how DJINN works, a user guide, the API and the example notebooks. To build it
locally, see above and open docs/_build/html/index.html.
Release notes are in CHANGELOG.md.
Source Repo Verification
These tests verify that this PyTorch fork produces results consistent with the original TensorFlow DJINN implementation.
The verification suite has two layers:
compare_results.py— an exploratory reporting script that prints a human-readable comparison of two JSON result files. Useful for investigating differences interactively.tests/test_tf_comparison.py— pytest tests that formally gate the comparison. These use asymmetric thresholds: they only fail when PT is worse than TF, not when PT is better. This avoids false failures caused by TF's known convergence instability on certain seeds.
One-time setup
Run setup_envs.sh from the repo root to create both virtual environments:
bash setup_envs.sh
This clones the TF repo into repos/DJINN-tf/ and installs both environments:
venvs/tf-djinn/— TensorFlow implementationvenvs/pt-djinn/— PyTorch implementation (installed from the current repo)
Step 1: Unit tests (run in both envs)
These tests check API compatibility, output shapes, determinism, and save/load correctness. Run them independently in each environment:
# TensorFlow env — shared contract only
source venvs/tf-djinn/bin/activate
pytest tests/test_unit_shared.py -v
deactivate
# PyTorch env — shared contract + PT-specific behaviour
source venvs/pt-djinn/bin/activate
pytest tests/test_unit_shared.py tests/test_unit.py -v
deactivate
Any test that fails in one environment but passes in the other reveals a behavioral divergence between the two implementations.
Step 2: Collect benchmark results
Run the benchmark script once in each environment. This trains DJINN across 20 random seeds and saves the metrics to JSON. The TF results are committed to the repo as a baseline; only the PT results need to be regenerated on each comparison run.
TF baseline (results_tf.json)
results_tf.json is committed to the repo root and should be treated as
stable. Only regenerate it if the TF implementation, datasets, or collection
methodology change. It was generated with:
- TensorFlow version: 2.21.0
- Command:
python run_and_collect.py --impl tf --out results_tf.json --ntrees 3 --epochs 100 --seeds 20
To regenerate:
source venvs/tf-djinn/bin/activate
python run_and_collect.py --impl tf --out results_tf.json --ntrees 3 --epochs 100 --seeds 20
git add results_tf.json
git commit -m "Regenerate TF baseline (TF 2.21.0, ntrees=3, epochs=100, seeds=20)"
deactivate
# TensorFlow env — generate committed baseline (one-time)
source venvs/tf-djinn/bin/activate
python run_and_collect.py --impl tf --out results_tf.json --ntrees 3 --epochs 100
deactivate
# PyTorch env — regenerate on each comparison run
source venvs/pt-djinn/bin/activate
python run_and_collect.py --impl pt --out results_pt.json --ntrees 3 --epochs 100
deactivate
Step 3: Compare results
Exploratory report (human-readable, no pass/fail gates):
python compare_results.py --tf results_tf.json --pt results_pt.json
# Optional: generate distribution plots (requires matplotlib)
python compare_results.py --tf results_tf.json --pt results_pt.json --plot
Formal pytest comparison (used in CI):
source venvs/pt-djinn/bin/activate
pytest tests/test_tf_comparison.py -m comparison -v
Interpreting compare_results.py output
compare_results.py is an exploratory tool. Its PASS/WARN/FAIL labels use
two-sided statistical tests and are intended to guide investigation, not to
formally gate correctness. See test_tf_comparison.py for the authoritative
pass/fail criteria used in CI.
| Color / Status | Meaning |
|---|---|
Green PASS |
Distributions are not significantly different (KS + Mann-Whitney p > 0.05) |
Yellow WARN |
Marginal difference — worth investigating but not necessarily a bug |
Red FAIL |
Statistically significant difference or metric below performance floor |
A FAIL in compare_results.py does not necessarily mean the PT
implementation is wrong. PT often scores better than TF (higher R**2, lower
MSE, lower variance across seeds), which also triggers a FAIL under two-sided
tests. Use the pytest suite to determine whether a difference is a real
regression.
Acceptance thresholds
These are the criteria used in tests/test_tf_comparison.py. All checks are
asymmetric: PT is only required to be at least as good as TF, not
identical to it.
| Check | Threshold |
|---|---|
| Network architecture | Exact match |
| Prediction shape | Exact match |
| Prediction dtype | Must be float (float32 vs float64 acceptable) |
| Same-seed determinism | rtol=1e-4 |
| Save/load round-trip | rtol=1e-5 |
| PT median R² not below TF | PT median ≥ TF median − 0.05 |
| PT R² not stochastically worse | One-sided Mann-Whitney p > 0.05 |
| PT R² variance | PT std ≤ TF std × 2 |
| PT multi-output median R² | PT median ≥ TF median − 0.02 |
| PT multi-output variance | PT std ≤ TF std × 3 |
| BMA uncertainty > 0 | Required for all seeds |
| BMA uncertainty ratio PT/TF | Between 0.05× and 10× |
| BMA output shape | Exact match between implementations |
| Batch size | Exact match (data-driven, should be identical) |
| Learning rate | In range [1e-6, 1.0] |
Notes
- The two implementations will never produce identical outputs — TF and PyTorch have different RNGs and optimizer defaults.
- The goal is that PT is at least as good as TF, not that they are numerically identical.
- PT consistently converges more reliably than TF (lower R² variance across seeds), particularly on multi-output tasks.
- Use at least 100 epochs for meaningful comparison results.
results_tf.jsonis committed to the repo root and must not be deleted or regenerated casually — it was produced with TensorFlow 2.21.0 using--ntrees 3 --epochs 100 --seeds 20. Regenerate only when the TF implementation or datasets change, and update the commit message with the TF version and command used.results_pt.jsonshould never be committed — add it to.gitignore.
Source Repo
DJINN is available at https://github.com/LLNL/DJINN
Citing DJINN
If you use DJINN in your research, please cite the following paper:
K. D. Humbird, J. L. Peterson and R. G. Mcclarren, "Deep Neural Network Initialization With Decision Trees," in IEEE Transactions on Neural Networks and Learning Systems, vol. 30, no. 5, pp. 1286-1295, May 2019. doi: 10.1109/TNNLS.2018.2869694, URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8478232&isnumber=8695188
Citation metadata for the paper and this PyTorch implementation is in CITATION.cff; GitHub's "Cite this repository" button exports it as BibTeX or APA.
Release
Copyright (c) 2018, Lawrence Livermore National Security, LLC.
Produced at the Lawrence Livermore National Laboratory
Written by K. Humbird (humbird1@llnl.gov), L. Peterson (peterson76@llnl.gov).
LLNL-CODE-754815 OCEC-18-117
All rights reserved.
Unlimited Open Source- BSD Distribution.
For release details and restrictions, please read the RELEASE, LICENSE, and NOTICE files, linked below:
Metadata
Release files for djinnml 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| djinnml-1.2.1.tar.gz | 53.4 kB | With provenance | Details for djinnml-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| djinnml-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for djinnml-1.2.1-py3-none-any.whl |
Total release size: 87.3 kB
Release files / djinnml-1.2.1.tar.gz
| Download URL | djinnml-1.2.1.tar.gz |
|---|---|
| Size | 53.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e872d6677b4aec1c9166af2085c487e1fe1ead1ebfc5c6182dc120693eed3523
|
|
BLAKE2b-256 checksum How to use checksums |
fd503dd595d15864d908b6531ce88c4b7da2f6c4b12db92a8a576bf3dc1042c1
|
| 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 11, 2026.
Transparency logRelease files / djinnml-1.2.1-py3-none-any.whl
| Download URL | djinnml-1.2.1-py3-none-any.whl |
|---|---|
| Size | 33.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c1750c242a847778fba7e642a7188fbef04aa2fa784ea2994cf54187cc5be86
|
|
BLAKE2b-256 checksum How to use checksums |
b548e430c8953071264763542c1c608f806126e44ad8105abf4998b351369578
|
| 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 11, 2026.
Transparency logSecurity for djinnml 1.2.1
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
Both files in this release have been uploaded with provenance metadata.
Attestation for djinnml-1.2.1.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 11, 2026.
Transparency logA 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.