bartz 0.4.1__py3-none-any.whl → 0.5.0__py3-none-any.whl
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.
- bartz/.DS_Store +0 -0
- bartz/BART.py +99 -39
- bartz/__init__.py +3 -11
- bartz/_version.py +1 -1
- bartz/debug.py +42 -16
- bartz/grove.py +20 -11
- bartz/jaxext.py +41 -16
- bartz/mcmcloop.py +119 -58
- bartz/mcmcstep.py +426 -173
- bartz/prepcovars.py +22 -9
- {bartz-0.4.1.dist-info → bartz-0.5.0.dist-info}/METADATA +12 -16
- bartz-0.5.0.dist-info/RECORD +13 -0
- bartz-0.5.0.dist-info/WHEEL +4 -0
- bartz-0.4.1.dist-info/LICENSE +0 -21
- bartz-0.4.1.dist-info/RECORD +0 -13
- bartz-0.4.1.dist-info/WHEEL +0 -4
bartz/prepcovars.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# bartz/src/bartz/prepcovars.py
|
|
2
2
|
#
|
|
3
|
-
# Copyright (c) 2024, Giacomo Petrillo
|
|
3
|
+
# Copyright (c) 2024-2025, Giacomo Petrillo
|
|
4
4
|
#
|
|
5
5
|
# This file is part of bartz.
|
|
6
6
|
#
|
|
@@ -28,7 +28,7 @@ import jax
|
|
|
28
28
|
from jax import numpy as jnp
|
|
29
29
|
|
|
30
30
|
from . import jaxext
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
|
|
33
33
|
@functools.partial(jax.jit, static_argnums=(1,))
|
|
34
34
|
def quantilized_splits_from_matrix(X, max_bins):
|
|
@@ -54,12 +54,15 @@ def quantilized_splits_from_matrix(X, max_bins):
|
|
|
54
54
|
The number of actually used values in each row of `splits`.
|
|
55
55
|
"""
|
|
56
56
|
out_length = min(max_bins, X.shape[1]) - 1
|
|
57
|
+
|
|
57
58
|
# return _quantilized_splits_from_matrix(X, out_length)
|
|
58
|
-
@functools.partial(jaxext.autobatch, max_io_nbytes=2
|
|
59
|
+
@functools.partial(jaxext.autobatch, max_io_nbytes=2**29)
|
|
59
60
|
def quantilize(X):
|
|
60
61
|
return _quantilized_splits_from_matrix(X, out_length)
|
|
62
|
+
|
|
61
63
|
return quantilize(X)
|
|
62
64
|
|
|
65
|
+
|
|
63
66
|
@functools.partial(jax.vmap, in_axes=(0, None))
|
|
64
67
|
def _quantilized_splits_from_matrix(x, out_length):
|
|
65
68
|
huge = jaxext.huge_value(x)
|
|
@@ -67,21 +70,28 @@ def _quantilized_splits_from_matrix(x, out_length):
|
|
|
67
70
|
actual_length -= 1
|
|
68
71
|
if jnp.issubdtype(x.dtype, jnp.integer):
|
|
69
72
|
midpoints = u[:-1] + jaxext.ensure_unsigned(u[1:] - u[:-1]) // 2
|
|
70
|
-
indices = jnp.arange(
|
|
73
|
+
indices = jnp.arange(
|
|
74
|
+
midpoints.size, dtype=jaxext.minimal_unsigned_dtype(midpoints.size - 1)
|
|
75
|
+
)
|
|
71
76
|
midpoints = jnp.where(indices < actual_length, midpoints, huge)
|
|
72
77
|
else:
|
|
73
78
|
midpoints = (u[1:] + u[:-1]) / 2
|
|
74
79
|
indices = jnp.linspace(-1, actual_length, out_length + 2)[1:-1]
|
|
75
|
-
indices = jnp.around(indices).astype(
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
indices = jnp.around(indices).astype(
|
|
81
|
+
jaxext.minimal_unsigned_dtype(midpoints.size - 1)
|
|
82
|
+
)
|
|
83
|
+
# indices calculation with float rather than int to avoid potential
|
|
84
|
+
# overflow with int32, and to round to nearest instead of rounding down
|
|
78
85
|
decimated_midpoints = midpoints[indices]
|
|
79
86
|
truncated_midpoints = midpoints[:out_length]
|
|
80
|
-
splits = jnp.where(
|
|
87
|
+
splits = jnp.where(
|
|
88
|
+
actual_length > out_length, decimated_midpoints, truncated_midpoints
|
|
89
|
+
)
|
|
81
90
|
max_split = jnp.minimum(actual_length, out_length)
|
|
82
91
|
max_split = max_split.astype(jaxext.minimal_unsigned_dtype(out_length))
|
|
83
92
|
return splits, max_split
|
|
84
93
|
|
|
94
|
+
|
|
85
95
|
@functools.partial(jax.jit, static_argnums=(1,))
|
|
86
96
|
def uniform_splits_from_matrix(X, num_bins):
|
|
87
97
|
"""
|
|
@@ -110,6 +120,7 @@ def uniform_splits_from_matrix(X, num_bins):
|
|
|
110
120
|
max_split = jnp.full(*splits.shape, jaxext.minimal_unsigned_dtype(num_bins - 1))
|
|
111
121
|
return splits, max_split
|
|
112
122
|
|
|
123
|
+
|
|
113
124
|
@functools.partial(jax.jit, static_argnames=('method',))
|
|
114
125
|
def bin_predictors(X, splits, **kw):
|
|
115
126
|
"""
|
|
@@ -135,9 +146,11 @@ def bin_predictors(X, splits, **kw):
|
|
|
135
146
|
A matrix with `p` predictors and `n` observations, where each predictor
|
|
136
147
|
has been replaced by the index of the bin it falls into.
|
|
137
148
|
"""
|
|
138
|
-
|
|
149
|
+
|
|
150
|
+
@functools.partial(jaxext.autobatch, max_io_nbytes=2**29)
|
|
139
151
|
@jax.vmap
|
|
140
152
|
def bin_predictors(x, splits):
|
|
141
153
|
dtype = jaxext.minimal_unsigned_dtype(splits.size)
|
|
142
154
|
return jnp.searchsorted(splits, x, **kw).astype(dtype)
|
|
155
|
+
|
|
143
156
|
return bin_predictors(X, splits)
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: bartz
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Super-fast BART (Bayesian Additive Regression Trees) in Python
|
|
5
|
-
License: MIT
|
|
6
5
|
Author: Giacomo Petrillo
|
|
7
|
-
Author-email: info@giacomopetrillo.com
|
|
6
|
+
Author-email: Giacomo Petrillo <info@giacomopetrillo.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Requires-Dist: jax>=0.4.35,<1
|
|
9
|
+
Requires-Dist: jaxlib>=0.4.35,<1
|
|
10
|
+
Requires-Dist: numpy>=1.25.2,<3
|
|
11
|
+
Requires-Dist: scipy>=1.11.4,<2
|
|
8
12
|
Requires-Python: >=3.10
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
-
Requires-Dist: jax (>=0.4.35,<1)
|
|
16
|
-
Requires-Dist: jaxlib (>=0.4.35,<1)
|
|
17
|
-
Requires-Dist: numpy (>=1.25.2,<3)
|
|
18
|
-
Requires-Dist: scipy (>=1.11.4,<2)
|
|
19
|
-
Project-URL: Bug Tracker, https://github.com/Gattocrucco/bartz/issues
|
|
13
|
+
Project-URL: Documentation, https://gattocrucco.github.io/bartz/docs-dev
|
|
14
|
+
Project-URL: Homepage, https://github.com/Gattocrucco/bartz
|
|
15
|
+
Project-URL: Issues, https://github.com/Gattocrucco/bartz/issues
|
|
20
16
|
Description-Content-Type: text/markdown
|
|
21
17
|
|
|
22
18
|
[](https://pypi.org/project/bartz/)
|
|
@@ -42,6 +38,7 @@ On CPU, bartz runs at the speed of dbarts (the fastest implementation I know of)
|
|
|
42
38
|
- [Documentation (development version)](https://gattocrucco.github.io/bartz/docs-dev)
|
|
43
39
|
- [Repository](https://github.com/Gattocrucco/bartz)
|
|
44
40
|
- [Code coverage](https://gattocrucco.github.io/bartz/coverage)
|
|
41
|
+
- [Benchmarks](https://gattocrucco.github.io/bartz/benchmarks)
|
|
45
42
|
- [List of BART packages](https://gattocrucco.github.io/bartz/docs-dev/pkglist.html)
|
|
46
43
|
|
|
47
44
|
## Citing bartz
|
|
@@ -49,4 +46,3 @@ On CPU, bartz runs at the speed of dbarts (the fastest implementation I know of)
|
|
|
49
46
|
Article: Petrillo (2024), "Very fast Bayesian Additive Regression Trees on GPU", [arXiv:2410.23244](https://arxiv.org/abs/2410.23244).
|
|
50
47
|
|
|
51
48
|
To cite the software directly, including the specific version, use [zenodo](https://doi.org/10.5281/zenodo.13931477).
|
|
52
|
-
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
bartz/.DS_Store,sha256=7191af46d7b8c0d4c03c502f94eb01353bc2e615d75c45b3af0e31ab238034b5,6148
|
|
2
|
+
bartz/BART.py,sha256=50faa27d82bc1c5ab6eb676a006bd7a95e2cbe10a541c5de7a100f068a76a820,17898
|
|
3
|
+
bartz/__init__.py,sha256=c3b1d04b62e52220f060d28f38403a536fcbe2cea06d0a4087dc0143b05cb1fd,1433
|
|
4
|
+
bartz/_version.py,sha256=d0f688d9e48e0a9e6490d7292a95126cb1dfebaacbf714331696322c6a44b723,22
|
|
5
|
+
bartz/debug.py,sha256=0ab2b06e53245b763d4c684653031c912ed794e328d2f427dbfb017c975840af,5359
|
|
6
|
+
bartz/grove.py,sha256=13d05ca6877b073cfc2d0e887fc03f74be35eadb6b587b83a0a0d41de1accb10,8494
|
|
7
|
+
bartz/jaxext.py,sha256=a439363fd44be9a26770a65dd30c3d140a877ec0ddcdd65ba8fed4471c629cd0,11552
|
|
8
|
+
bartz/mcmcloop.py,sha256=15f7de40d1b3a57183f90db2972b66ab7b455f4829cca22c5686736b154c1fac,9216
|
|
9
|
+
bartz/mcmcstep.py,sha256=48aaf9d4a32aa4b84a73b4ec365fe712204dd872e5df3de5cc3715a37e362430,60504
|
|
10
|
+
bartz/prepcovars.py,sha256=e76c05c5218a47096c368f28c2df0178b44b428d26ba9c15fa6dd6c09fd2f2a1,5849
|
|
11
|
+
bartz-0.5.0.dist-info/WHEEL,sha256=11319513b72fe7d4379f6f9f7984b3cca85f688201c09325839a04908e107b75,78
|
|
12
|
+
bartz-0.5.0.dist-info/METADATA,sha256=d875077205f7d03c4c4f8c84acfe3079c4808be32ea3ab358640fe581b6f3b46,2795
|
|
13
|
+
bartz-0.5.0.dist-info/RECORD,,
|
bartz-0.4.1.dist-info/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Giacomo Petrillo
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
bartz-0.4.1.dist-info/RECORD
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
bartz/BART.py,sha256=CbGzFWtYw5u38Z9-Hy3CbDXpKOOvPFAAkSqu2HZl8no,16862
|
|
2
|
-
bartz/__init__.py,sha256=CcWbDdelQoObG4MW7_jit0Y9fQumU2_Yv3LYtBi1Ag8,1480
|
|
3
|
-
bartz/_version.py,sha256=qBs4HqYsPn6yUHWEuCN4rGUC05gABbl800d8LBd8h9w,22
|
|
4
|
-
bartz/debug.py,sha256=9ZH-JfwZVu5OPhHBEyXQHAU5H9KIu1vxLK7yNv4m4Ew,5314
|
|
5
|
-
bartz/grove.py,sha256=x_6NK_l-hrXfy1PhssYNJkX41-w_WqjDziww0E7YRS8,8500
|
|
6
|
-
bartz/jaxext.py,sha256=UiAHw6pQMz8rjtn_JChFAIdPgUF393S5m-Dduyndnbo,11409
|
|
7
|
-
bartz/mcmcloop.py,sha256=lKDszvniNXka99X3e9RCrTgvEAZHA7ZbVXEgxUYvKMY,7634
|
|
8
|
-
bartz/mcmcstep.py,sha256=diI9vHXHMvu_Lk_bSJ-a038OnEbXDpNEikVPhRcxEys,54987
|
|
9
|
-
bartz/prepcovars.py,sha256=mMgfL-LGJ_8QpOL6iy7yfkL8A7FrT7Zfn5M3voyNwSQ,5818
|
|
10
|
-
bartz-0.4.1.dist-info/LICENSE,sha256=heuIJZQK9IexJYC-fYHoLUrgj8HG8yS3G072EvKh-94,1073
|
|
11
|
-
bartz-0.4.1.dist-info/METADATA,sha256=nOOpuP_b-eAJSR1sgyzJaGK4I1iuEWVFMJ9D3JMkY5M,2890
|
|
12
|
-
bartz-0.4.1.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
13
|
-
bartz-0.4.1.dist-info/RECORD,,
|
bartz-0.4.1.dist-info/WHEEL
DELETED