bartz 0.3.0__tar.gz → 0.4.1__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.
- bartz-0.4.1/PKG-INFO +52 -0
- bartz-0.4.1/README.md +30 -0
- {bartz-0.3.0 → bartz-0.4.1}/pyproject.toml +21 -16
- {bartz-0.3.0 → bartz-0.4.1}/src/bartz/__init__.py +3 -3
- bartz-0.4.1/src/bartz/_version.py +1 -0
- {bartz-0.3.0 → bartz-0.4.1}/src/bartz/jaxext.py +4 -23
- {bartz-0.3.0 → bartz-0.4.1}/src/bartz/mcmcstep.py +375 -306
- bartz-0.3.0/PKG-INFO +0 -77
- bartz-0.3.0/README.md +0 -54
- bartz-0.3.0/src/bartz/_version.py +0 -1
- {bartz-0.3.0 → bartz-0.4.1}/LICENSE +0 -0
- {bartz-0.3.0 → bartz-0.4.1}/src/bartz/BART.py +0 -0
- {bartz-0.3.0 → bartz-0.4.1}/src/bartz/debug.py +0 -0
- {bartz-0.3.0 → bartz-0.4.1}/src/bartz/grove.py +0 -0
- {bartz-0.3.0 → bartz-0.4.1}/src/bartz/mcmcloop.py +0 -0
- {bartz-0.3.0 → bartz-0.4.1}/src/bartz/prepcovars.py +0 -0
bartz-0.4.1/PKG-INFO
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: bartz
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Super-fast BART (Bayesian Additive Regression Trees) in Python
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Giacomo Petrillo
|
|
7
|
+
Author-email: info@giacomopetrillo.com
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
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
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
[](https://pypi.org/project/bartz/)
|
|
23
|
+
[](https://doi.org/10.5281/zenodo.13931477)
|
|
24
|
+
|
|
25
|
+
# BART vectoriZed
|
|
26
|
+
|
|
27
|
+
An implementation of Bayesian Additive Regression Trees (BART) in JAX.
|
|
28
|
+
|
|
29
|
+
If you don't know what BART is, but know XGBoost, consider BART as a sort of Bayesian XGBoost. bartz makes BART run as fast as XGBoost.
|
|
30
|
+
|
|
31
|
+
BART is a nonparametric Bayesian regression technique. Given training predictors $X$ and responses $y$, BART finds a function to predict $y$ given $X$. The result of the inference is a sample of possible functions, representing the uncertainty over the determination of the function.
|
|
32
|
+
|
|
33
|
+
This Python module provides an implementation of BART that runs on GPU, to process large datasets faster. It is also good on CPU. Most other implementations of BART are for R, and run on CPU only.
|
|
34
|
+
|
|
35
|
+
On CPU, bartz runs at the speed of dbarts (the fastest implementation I know of) if n > 20,000, but using 1/20 of the memory. On GPU, the speed premium depends on sample size; it is convenient over CPU only for n > 10,000. The maximum speedup is currently 200x, on an Nvidia A100 and with at least 2,000,000 observations.
|
|
36
|
+
|
|
37
|
+
[This Colab notebook](https://colab.research.google.com/github/Gattocrucco/bartz/blob/main/docs/examples/basic_simdata.ipynb) runs bartz with n = 100,000 observations, p = 1000 predictors, 10,000 trees, for 1000 MCMC iterations, in 5 minutes.
|
|
38
|
+
|
|
39
|
+
## Links
|
|
40
|
+
|
|
41
|
+
- [Documentation (latest release)](https://gattocrucco.github.io/bartz/docs)
|
|
42
|
+
- [Documentation (development version)](https://gattocrucco.github.io/bartz/docs-dev)
|
|
43
|
+
- [Repository](https://github.com/Gattocrucco/bartz)
|
|
44
|
+
- [Code coverage](https://gattocrucco.github.io/bartz/coverage)
|
|
45
|
+
- [List of BART packages](https://gattocrucco.github.io/bartz/docs-dev/pkglist.html)
|
|
46
|
+
|
|
47
|
+
## Citing bartz
|
|
48
|
+
|
|
49
|
+
Article: Petrillo (2024), "Very fast Bayesian Additive Regression Trees on GPU", [arXiv:2410.23244](https://arxiv.org/abs/2410.23244).
|
|
50
|
+
|
|
51
|
+
To cite the software directly, including the specific version, use [zenodo](https://doi.org/10.5281/zenodo.13931477).
|
|
52
|
+
|
bartz-0.4.1/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[](https://pypi.org/project/bartz/)
|
|
2
|
+
[](https://doi.org/10.5281/zenodo.13931477)
|
|
3
|
+
|
|
4
|
+
# BART vectoriZed
|
|
5
|
+
|
|
6
|
+
An implementation of Bayesian Additive Regression Trees (BART) in JAX.
|
|
7
|
+
|
|
8
|
+
If you don't know what BART is, but know XGBoost, consider BART as a sort of Bayesian XGBoost. bartz makes BART run as fast as XGBoost.
|
|
9
|
+
|
|
10
|
+
BART is a nonparametric Bayesian regression technique. Given training predictors $X$ and responses $y$, BART finds a function to predict $y$ given $X$. The result of the inference is a sample of possible functions, representing the uncertainty over the determination of the function.
|
|
11
|
+
|
|
12
|
+
This Python module provides an implementation of BART that runs on GPU, to process large datasets faster. It is also good on CPU. Most other implementations of BART are for R, and run on CPU only.
|
|
13
|
+
|
|
14
|
+
On CPU, bartz runs at the speed of dbarts (the fastest implementation I know of) if n > 20,000, but using 1/20 of the memory. On GPU, the speed premium depends on sample size; it is convenient over CPU only for n > 10,000. The maximum speedup is currently 200x, on an Nvidia A100 and with at least 2,000,000 observations.
|
|
15
|
+
|
|
16
|
+
[This Colab notebook](https://colab.research.google.com/github/Gattocrucco/bartz/blob/main/docs/examples/basic_simdata.ipynb) runs bartz with n = 100,000 observations, p = 1000 predictors, 10,000 trees, for 1000 MCMC iterations, in 5 minutes.
|
|
17
|
+
|
|
18
|
+
## Links
|
|
19
|
+
|
|
20
|
+
- [Documentation (latest release)](https://gattocrucco.github.io/bartz/docs)
|
|
21
|
+
- [Documentation (development version)](https://gattocrucco.github.io/bartz/docs-dev)
|
|
22
|
+
- [Repository](https://github.com/Gattocrucco/bartz)
|
|
23
|
+
- [Code coverage](https://gattocrucco.github.io/bartz/coverage)
|
|
24
|
+
- [List of BART packages](https://gattocrucco.github.io/bartz/docs-dev/pkglist.html)
|
|
25
|
+
|
|
26
|
+
## Citing bartz
|
|
27
|
+
|
|
28
|
+
Article: Petrillo (2024), "Very fast Bayesian Additive Regression Trees on GPU", [arXiv:2410.23244](https://arxiv.org/abs/2410.23244).
|
|
29
|
+
|
|
30
|
+
To cite the software directly, including the specific version, use [zenodo](https://doi.org/10.5281/zenodo.13931477).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# bartz/pyproject.toml
|
|
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
|
#
|
|
@@ -23,48 +23,53 @@
|
|
|
23
23
|
# SOFTWARE.
|
|
24
24
|
|
|
25
25
|
[build-system]
|
|
26
|
-
requires = ["poetry-core"]
|
|
26
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
27
27
|
build-backend = "poetry.core.masonry.api"
|
|
28
28
|
|
|
29
|
-
[
|
|
29
|
+
[project]
|
|
30
30
|
name = "bartz"
|
|
31
|
-
version = "0.
|
|
32
|
-
description = "
|
|
33
|
-
authors = [
|
|
31
|
+
version = "0.4.1"
|
|
32
|
+
description = "Super-fast BART (Bayesian Additive Regression Trees) in Python"
|
|
33
|
+
authors = [
|
|
34
|
+
{name = "Giacomo Petrillo", email = "info@giacomopetrillo.com"},
|
|
35
|
+
]
|
|
34
36
|
license = "MIT"
|
|
35
37
|
readme = "README.md"
|
|
38
|
+
requires-python = ">=3.10"
|
|
36
39
|
repository = "https://github.com/Gattocrucco/bartz"
|
|
37
40
|
packages = [
|
|
38
41
|
{ include = "bartz", from = "src" },
|
|
39
42
|
]
|
|
43
|
+
dependencies = [
|
|
44
|
+
"jax >=0.4.35,<1",
|
|
45
|
+
"jaxlib >=0.4.35,<1",
|
|
46
|
+
"numpy >=1.25.2,<3",
|
|
47
|
+
"scipy >=1.11.4,<2",
|
|
48
|
+
]
|
|
40
49
|
|
|
41
50
|
[tool.poetry.urls]
|
|
42
51
|
"Bug Tracker" = "https://github.com/Gattocrucco/bartz/issues"
|
|
43
52
|
|
|
44
|
-
[tool.poetry.dependencies]
|
|
45
|
-
python = "^3.10"
|
|
46
|
-
jax = "^0.4.23"
|
|
47
|
-
jaxlib = "^0.4.23"
|
|
48
|
-
numpy = "^1.25.2"
|
|
49
|
-
scipy = "^1.11.4"
|
|
50
|
-
|
|
51
53
|
[tool.poetry.group.dev.dependencies]
|
|
52
|
-
ipython = "
|
|
54
|
+
ipython = ">=8.22.2"
|
|
53
55
|
matplotlib = "^3.8.3"
|
|
54
56
|
appnope = "^0.1.4"
|
|
55
57
|
tomli = "^2.0.1"
|
|
56
58
|
packaging = "^24.0"
|
|
57
59
|
xgboost = "^2.0.3"
|
|
58
60
|
pre-commit = "^3.7.0"
|
|
61
|
+
scikit-learn = "^1.4.2"
|
|
62
|
+
matplotlib-label-lines = "^0.7.0"
|
|
63
|
+
polars = {version = "^1.0.0", extras = ["pandas", "pyarrow"]}
|
|
59
64
|
|
|
60
65
|
[tool.poetry.group.test.dependencies]
|
|
61
66
|
coverage = "^7.4.3"
|
|
62
67
|
pytest = "^8.1.1"
|
|
63
68
|
|
|
64
69
|
[tool.poetry.group.docs.dependencies]
|
|
65
|
-
Sphinx = "
|
|
70
|
+
Sphinx = ">=7.2.6,<9"
|
|
66
71
|
numpydoc = "^1.6.0"
|
|
67
|
-
myst-parser = "^
|
|
72
|
+
myst-parser = "^4.0.1"
|
|
68
73
|
|
|
69
74
|
[tool.pytest.ini_options]
|
|
70
75
|
testpaths = ["tests"]
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
11
|
# copies of the Software, and to permit persons to whom the Software is
|
|
12
12
|
# furnished to do so, subject to the following conditions:
|
|
13
|
-
#
|
|
13
|
+
#
|
|
14
14
|
# The above copyright notice and this permission notice shall be included in all
|
|
15
15
|
# copies or substantial portions of the Software.
|
|
16
|
-
#
|
|
16
|
+
#
|
|
17
17
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
18
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
19
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
# SOFTWARE.
|
|
24
24
|
|
|
25
25
|
"""
|
|
26
|
-
|
|
26
|
+
Super-fast BART (Bayesian Additive Regression Trees) in Python
|
|
27
27
|
|
|
28
28
|
See the manual at https://gattocrucco.github.io/bartz/docs
|
|
29
29
|
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.4.1'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# bartz/src/bartz/jaxext.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
|
#
|
|
@@ -45,27 +45,6 @@ def castto(func, type):
|
|
|
45
45
|
return func(*args, **kw).astype(type)
|
|
46
46
|
return newfunc
|
|
47
47
|
|
|
48
|
-
def pure_callback_ufunc(callback, dtype, *args, excluded=None, **kwargs):
|
|
49
|
-
""" version of `jax.pure_callback` that deals correctly with ufuncs,
|
|
50
|
-
see `<https://github.com/google/jax/issues/17187>`_ """
|
|
51
|
-
if excluded is None:
|
|
52
|
-
excluded = ()
|
|
53
|
-
shape = jnp.broadcast_shapes(*(
|
|
54
|
-
a.shape
|
|
55
|
-
for i, a in enumerate(args)
|
|
56
|
-
if i not in excluded
|
|
57
|
-
))
|
|
58
|
-
ndim = len(shape)
|
|
59
|
-
padded_args = [
|
|
60
|
-
a if i in excluded
|
|
61
|
-
else jnp.expand_dims(a, tuple(range(ndim - a.ndim)))
|
|
62
|
-
for i, a in enumerate(args)
|
|
63
|
-
]
|
|
64
|
-
result = jax.ShapeDtypeStruct(shape, dtype)
|
|
65
|
-
return jax.pure_callback(callback, result, *padded_args, vectorized=True, **kwargs)
|
|
66
|
-
|
|
67
|
-
# TODO when jax solves this, check version and piggyback on original if new
|
|
68
|
-
|
|
69
48
|
class scipy:
|
|
70
49
|
|
|
71
50
|
class special:
|
|
@@ -74,9 +53,11 @@ class scipy:
|
|
|
74
53
|
def gammainccinv(a, y):
|
|
75
54
|
a = jnp.asarray(a)
|
|
76
55
|
y = jnp.asarray(y)
|
|
56
|
+
shape = jnp.broadcast_shapes(a.shape, y.shape)
|
|
77
57
|
dtype = float_type(a.dtype, y.dtype)
|
|
58
|
+
dummy = jax.ShapeDtypeStruct(shape, dtype)
|
|
78
59
|
ufunc = castto(special.gammainccinv, dtype)
|
|
79
|
-
return
|
|
60
|
+
return jax.pure_callback(ufunc, dummy, a, y, vmap_method='expand_dims')
|
|
80
61
|
|
|
81
62
|
class stats:
|
|
82
63
|
|