djinnml 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
djinnml-1.1.0/LICENSE ADDED
@@ -0,0 +1,66 @@
1
+ Copyright (c) 2018, Lawrence Livermore National Security, LLC.
2
+ Copyright (c) 2024-2026, Ben Whewell (PyTorch rewrite).
3
+
4
+ Produced at the Lawrence Livermore National Laboratory
5
+
6
+ LLNL-CODE-754815
7
+
8
+ OCEC-18-117
9
+
10
+ All rights reserved.
11
+
12
+ This file is part of DJINN.
13
+
14
+ For details, see: github.com/LLNL/djinn
15
+
16
+ Please also read DJINN/LICENSE, DJINN/NOTICE, and DJINN/RELEASE.
17
+
18
+ Redistribution and use in source and binary forms, with or without
19
+ modification, are permitted provided that the following conditions are met:
20
+
21
+ * Redistributions of source code must retain the above copyright notice,
22
+ this list of conditions and the disclaimer below.
23
+
24
+ * Redistributions in binary form must reproduce the above copyright notice,
25
+ this list of conditions and the disclaimer (as noted below) in the
26
+ documentation and/or other materials provided with the distribution.
27
+
28
+ * Neither the name of the LLNS/LLNL nor the names of its contributors may
29
+ be used to endorse or promote products derived from this software without
30
+ specific prior written permission.
31
+
32
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35
+ ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
36
+ LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
37
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
42
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43
+ POSSIBILITY OF SUCH DAMAGE.
44
+
45
+ Additional BSD Notice
46
+
47
+ 1. This notice is required to be provided under our contract with the U.S.
48
+ Department of Energy (DOE). This work was produced at Lawrence
49
+ Livermore National Laboratory under Contract No. DE-AC52-07NA27344 with
50
+ the DOE.
51
+
52
+ 2. Neither the United States Government nor Lawrence Livermore National
53
+ Security, LLC nor any of their employees, makes any warranty, express
54
+ or implied, or assumes any liability or responsibility for the
55
+ accuracy, completeness, or usefulness of any information, apparatus,
56
+ product, or process disclosed, or represents that its use would not
57
+ infringe privately-owned rights.
58
+
59
+ 3. Also, reference herein to any specific commercial products, process,
60
+ or services by trade name, trademark, manufacturer or otherwise does
61
+ not necessarily constitute or imply its endorsement, recommendation,
62
+ or favoring by the United States Government or Lawrence Livermore
63
+ National Security, LLC. The views and opinions of authors expressed
64
+ herein do not necessarily state or reflect those of the United
65
+ States Government or Lawrence Livermore National Security, LLC, and
66
+ shall not be used for advertising or product endorsement purposes.
djinnml-1.1.0/NOTICE ADDED
@@ -0,0 +1,19 @@
1
+ 1. This notice is required to be provided under our contract with the U.S.
2
+ Department of Energy (DOE). This work was produced at Lawrence Livermore
3
+ National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE.
4
+
5
+ 2. Neither the United States Government nor Lawrence Livermore National
6
+ Security, LLC nor any of their employees, makes any warranty, express or
7
+ implied, or assumes any liability or responsibility for the accuracy,
8
+ completeness, or usefulness of any information, apparatus, product, or
9
+ process disclosed, or represents that its use would not infringe
10
+ privately-owned rights.
11
+
12
+ 3. Also, reference herein to any specific commercial products, process,
13
+ or services by trade name, trademark, manufacturer or otherwise does not
14
+ necessarily constitute or imply its endorsement, recommendation, or favoring
15
+ by the United States Government or Lawrence Livermore National Security, LLC.
16
+ The views and opinions of authors expressed herein do not necessarily state
17
+ or reflect those of the United States Government or Lawrence Livermore
18
+ National Security, LLC, and shall not be used for advertising or product
19
+ endorsement purposes.
djinnml-1.1.0/PKG-INFO ADDED
@@ -0,0 +1,346 @@
1
+ Metadata-Version: 2.4
2
+ Name: djinnml
3
+ Version: 1.1.0
4
+ Summary: Deep Jointly-Informed Neural Networks
5
+ Author-email: Ben Whewell <ben.whewell@pm.me>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Repository, https://github.com/bwhewe-13/DJINN
8
+ Project-URL: Upstream, https://github.com/LLNL/djinn
9
+ Project-URL: Homepage, https://github.com/bwhewe-13/DJINN
10
+ Keywords: regression,neural networks,pytorch
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Requires-Python: <4,>=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ License-File: NOTICE
26
+ Requires-Dist: torch>=1.8
27
+ Requires-Dist: scipy
28
+ Requires-Dist: scikit-learn>=1.0
29
+ Provides-Extra: testing
30
+ Requires-Dist: pytest>=7; extra == "testing"
31
+ Requires-Dist: pytest-cov; extra == "testing"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7; extra == "dev"
34
+ Requires-Dist: pytest-cov; extra == "dev"
35
+ Requires-Dist: pytest-xdist; extra == "dev"
36
+ Requires-Dist: black==26.1.0; extra == "dev"
37
+ Requires-Dist: isort; extra == "dev"
38
+ Requires-Dist: flake8; extra == "dev"
39
+ Requires-Dist: pre-commit; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+
43
+ Deep Jointly-Informed Neural Networks
44
+ ======================================
45
+ **DJINN: Deep jointly-informed neural networks**
46
+
47
+
48
+ [![Tests](https://github.com/bwhewe-13/DJINN/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/bwhewe-13/DJINN/actions/workflows/tests.yml)
49
+ [![Formatting](https://github.com/bwhewe-13/DJINN/actions/workflows/formatting.yml/badge.svg?branch=master)](https://github.com/bwhewe-13/DJINN/actions/workflows/formatting.yml)
50
+ [![codecov](https://codecov.io/gh/bwhewe-13/DJINN/branch/master/graph/badge.svg)](https://codecov.io/gh/bwhewe-13/DJINN)
51
+ [![Docs](https://github.com/bwhewe-13/DJINN/actions/workflows/docs.yml/badge.svg?branch=master)](https://github.com/bwhewe-13/DJINN/actions/workflows/docs.yml)
52
+ [![License: BSD](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/bwhewe-13/DJINN/blob/master/LICENSE)
53
+ ![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)
54
+
55
+
56
+ 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
57
+
58
+
59
+ DJINN is an easy-to-use algorithm for training deep neural networks on supervised regression tasks.
60
+ For additional information, refer to the paper "Deep neural network initialization with decision trees", cited below.
61
+
62
+
63
+
64
+ Getting Started
65
+ ---------------
66
+ Original DJINN required TensorFlow. This fork is implemented with PyTorch.
67
+
68
+ Requirements:
69
+
70
+ - Python 3.10+
71
+ - PyTorch
72
+ - scikit-learn
73
+
74
+ Install from source:
75
+
76
+ ```bash
77
+ git clone https://github.com/bwhewe-13/DJINN.git
78
+ cd DJINN
79
+ python -m pip install --upgrade pip
80
+ python -m pip install .
81
+ ```
82
+
83
+ Try it out using the examples in [examples](https://github.com/bwhewe-13/DJINN/tree/master/examples):
84
+
85
+ ```bash
86
+ cd examples
87
+ python djinn_regression.py
88
+ python djinn_classification.py
89
+ python djinn_multiout.py
90
+ ```
91
+
92
+ Notes:
93
+
94
+ - The scikit-learn version used when training a DJINN model should match the
95
+ version used when loading/evaluating that saved model.
96
+ - Some example workflows may require `matplotlib`:
97
+
98
+ ```bash
99
+ python -m pip install matplotlib
100
+ ```
101
+
102
+
103
+ Development
104
+ -----------
105
+ Set up a local development environment:
106
+
107
+ ```bash
108
+ python -m pip install --upgrade pip
109
+ python -m pip install -e .[dev]
110
+ ```
111
+
112
+ Run quality checks and tests:
113
+
114
+ ```bash
115
+ black --check djinn tests examples
116
+ isort --check-only djinn tests examples
117
+ flake8
118
+ pytest
119
+ ```
120
+
121
+ Enable pre-commit hooks (optional, recommended):
122
+
123
+ ```bash
124
+ pre-commit install
125
+ pre-commit run --all-files
126
+ ```
127
+
128
+ Build docs locally:
129
+
130
+ ```bash
131
+ python -m pip install sphinx
132
+ cd docs
133
+ make html
134
+ ```
135
+
136
+ ### Documentation
137
+ To view the DJINN documentation:
138
+
139
+ ```
140
+ cd docs
141
+ make html
142
+ ```
143
+ Open docs/_build/html/index.html in a browser
144
+
145
+
146
+ Source Repo Verification
147
+ ------------------------
148
+
149
+ These tests verify that this PyTorch fork produces results consistent with
150
+ the original TensorFlow DJINN implementation.
151
+
152
+ The verification suite has two layers:
153
+
154
+ - **`compare_results.py`** — an exploratory reporting script that prints a
155
+ human-readable comparison of two JSON result files. Useful for investigating
156
+ differences interactively.
157
+ - **`tests/test_tf_comparison.py`** — pytest tests that formally gate the
158
+ comparison. These use asymmetric thresholds: they only fail when PT is
159
+ *worse* than TF, not when PT is better. This avoids false failures caused
160
+ by TF's known convergence instability on certain seeds.
161
+
162
+ ### One-time setup
163
+
164
+ Run `setup_envs.sh` from the repo root to create both virtual environments:
165
+
166
+ ```bash
167
+ bash setup_envs.sh
168
+ ```
169
+
170
+ This clones the TF repo into `repos/DJINN-tf/` and installs both environments:
171
+
172
+ - `venvs/tf-djinn/` — TensorFlow implementation
173
+ - `venvs/pt-djinn/` — PyTorch implementation (installed from the current repo)
174
+
175
+ ### Step 1: Unit tests (run in both envs)
176
+
177
+ These tests check API compatibility, output shapes, determinism, and
178
+ save/load correctness. Run them independently in each environment:
179
+
180
+ ```bash
181
+ # TensorFlow env — shared contract only
182
+ source venvs/tf-djinn/bin/activate
183
+ pytest tests/test_unit_shared.py -v
184
+ deactivate
185
+
186
+ # PyTorch env — shared contract + PT-specific behaviour
187
+ source venvs/pt-djinn/bin/activate
188
+ pytest tests/test_unit_shared.py tests/test_unit.py -v
189
+ deactivate
190
+ ```
191
+
192
+ Any test that fails in one environment but passes in the other reveals
193
+ a **behavioral divergence** between the two implementations.
194
+
195
+ ### Step 2: Collect benchmark results
196
+
197
+ Run the benchmark script once in each environment. This trains DJINN
198
+ across 20 random seeds and saves the metrics to JSON. The TF results
199
+ are committed to the repo as a baseline; only the PT results need to
200
+ be regenerated on each comparison run.
201
+
202
+ #### TF baseline (`results_tf.json`)
203
+
204
+ `results_tf.json` is committed to the repo root and should be treated as
205
+ stable. Only regenerate it if the TF implementation, datasets, or collection
206
+ methodology change. It was generated with:
207
+
208
+ - **TensorFlow version:** 2.21.0
209
+ - **Command:** `python run_and_collect.py --impl tf --out results_tf.json --ntrees 3 --epochs 100 --seeds 20`
210
+
211
+ To regenerate:
212
+
213
+ ```bash
214
+ source venvs/tf-djinn/bin/activate
215
+ python run_and_collect.py --impl tf --out results_tf.json --ntrees 3 --epochs 100 --seeds 20
216
+ git add results_tf.json
217
+ git commit -m "Regenerate TF baseline (TF 2.21.0, ntrees=3, epochs=100, seeds=20)"
218
+ deactivate
219
+ ```
220
+
221
+ ```bash
222
+ # TensorFlow env — generate committed baseline (one-time)
223
+ source venvs/tf-djinn/bin/activate
224
+ python run_and_collect.py --impl tf --out results_tf.json --ntrees 3 --epochs 100
225
+ deactivate
226
+
227
+ # PyTorch env — regenerate on each comparison run
228
+ source venvs/pt-djinn/bin/activate
229
+ python run_and_collect.py --impl pt --out results_pt.json --ntrees 3 --epochs 100
230
+ deactivate
231
+ ```
232
+
233
+ ### Step 3: Compare results
234
+
235
+ **Exploratory report** (human-readable, no pass/fail gates):
236
+
237
+ ```bash
238
+ python compare_results.py --tf results_tf.json --pt results_pt.json
239
+
240
+ # Optional: generate distribution plots (requires matplotlib)
241
+ python compare_results.py --tf results_tf.json --pt results_pt.json --plot
242
+ ```
243
+
244
+ **Formal pytest comparison** (used in CI):
245
+
246
+ ```bash
247
+ source venvs/pt-djinn/bin/activate
248
+ pytest tests/test_tf_comparison.py -m comparison -v
249
+ ```
250
+
251
+ ### Interpreting `compare_results.py` output
252
+
253
+ `compare_results.py` is an exploratory tool. Its PASS/WARN/FAIL labels use
254
+ two-sided statistical tests and are intended to guide investigation, not to
255
+ formally gate correctness. See `test_tf_comparison.py` for the authoritative
256
+ pass/fail criteria used in CI.
257
+
258
+ | Color / Status | Meaning |
259
+ |----------------|---------|
260
+ | Green `PASS` | Distributions are not significantly different (KS + Mann-Whitney p > 0.05) |
261
+ | Yellow `WARN` | Marginal difference — worth investigating but not necessarily a bug |
262
+ | Red `FAIL` | Statistically significant difference or metric below performance floor |
263
+
264
+ A `FAIL` in `compare_results.py` does **not** necessarily mean the PT
265
+ implementation is wrong. PT often scores better than TF (higher R**2, lower
266
+ MSE, lower variance across seeds), which also triggers a FAIL under two-sided
267
+ tests. Use the pytest suite to determine whether a difference is a real
268
+ regression.
269
+
270
+ ### Acceptance thresholds
271
+
272
+ These are the criteria used in `tests/test_tf_comparison.py`. All checks are
273
+ **asymmetric**: PT is only required to be at least as good as TF, not
274
+ identical to it.
275
+
276
+ | Check | Threshold |
277
+ |-------|-----------|
278
+ | Network architecture | Exact match |
279
+ | Prediction shape | Exact match |
280
+ | Prediction dtype | Must be float (float32 vs float64 acceptable) |
281
+ | Same-seed determinism | rtol=1e-4 |
282
+ | Save/load round-trip | rtol=1e-5 |
283
+ | PT median R² not below TF | PT median ≥ TF median − 0.05 |
284
+ | PT R² not stochastically worse | One-sided Mann-Whitney p > 0.05 |
285
+ | PT R² variance | PT std ≤ TF std × 2 |
286
+ | PT multi-output median R² | PT median ≥ TF median − 0.02 |
287
+ | PT multi-output variance | PT std ≤ TF std × 3 |
288
+ | BMA uncertainty > 0 | Required for all seeds |
289
+ | BMA uncertainty ratio PT/TF | Between 0.05× and 10× |
290
+ | BMA output shape | Exact match between implementations |
291
+ | Batch size | Exact match (data-driven, should be identical) |
292
+ | Learning rate | In range [1e-6, 1.0] |
293
+
294
+ ### Notes
295
+
296
+ - The two implementations will **never produce identical outputs** —
297
+ TF and PyTorch have different RNGs and optimizer defaults.
298
+ - The goal is that PT is at least as good as TF, not that they are numerically
299
+ identical.
300
+ - PT consistently converges more reliably than TF (lower R² variance across
301
+ seeds), particularly on multi-output tasks.
302
+ - Use at least 100 epochs for meaningful comparison results.
303
+ - `results_tf.json` is committed to the repo root and must not be deleted or
304
+ regenerated casually — it was produced with TensorFlow 2.21.0 using
305
+ `--ntrees 3 --epochs 100 --seeds 20`. Regenerate only when the TF
306
+ implementation or datasets change, and update the commit message with the
307
+ TF version and command used.
308
+ - `results_pt.json` should never be committed — add it to `.gitignore`.
309
+
310
+ ---
311
+
312
+ Source Repo
313
+ -----------
314
+
315
+ DJINN is available at https://github.com/LLNL/DJINN
316
+
317
+
318
+ Citing DJINN
319
+ -----------
320
+ If you use DJINN in your research, please cite the following paper:
321
+
322
+ 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.
323
+ doi: 10.1109/TNNLS.2018.2869694,
324
+ URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8478232&isnumber=8695188
325
+
326
+
327
+
328
+
329
+ Release
330
+ -----------
331
+ Copyright (c) 2018, Lawrence Livermore National Security, LLC.
332
+
333
+ Produced at the Lawrence Livermore National Laboratory
334
+
335
+ Written by K. Humbird (humbird1@llnl.gov), L. Peterson (peterson76@llnl.gov).
336
+
337
+ LLNL-CODE-754815 OCEC-18-117
338
+
339
+ All rights reserved.
340
+
341
+ Unlimited Open Source- BSD Distribution.
342
+
343
+ For release details and restrictions, please read the RELEASE, LICENSE, and NOTICE files, linked below:
344
+ - [RELEASE](https://github.com/bwhewe-13/DJINN/blob/master/RELEASE)
345
+ - [LICENSE](https://github.com/bwhewe-13/DJINN/blob/master/LICENSE)
346
+ - [NOTICE](https://github.com/bwhewe-13/DJINN/blob/master/NOTICE)