bartz 0.4.1__py3-none-any.whl → 0.6.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/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
  #
@@ -22,13 +22,15 @@
22
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  # SOFTWARE.
24
24
 
25
+ """Functions to preprocess data."""
26
+
25
27
  import functools
26
28
 
27
29
  import jax
28
30
  from jax import numpy as jnp
29
31
 
30
32
  from . import jaxext
31
- from . import grove
33
+
32
34
 
33
35
  @functools.partial(jax.jit, static_argnums=(1,))
34
36
  def quantilized_splits_from_matrix(X, max_bins):
@@ -54,12 +56,15 @@ def quantilized_splits_from_matrix(X, max_bins):
54
56
  The number of actually used values in each row of `splits`.
55
57
  """
56
58
  out_length = min(max_bins, X.shape[1]) - 1
57
- # return _quantilized_splits_from_matrix(X, out_length)
58
- @functools.partial(jaxext.autobatch, max_io_nbytes=2 ** 29)
59
+
60
+ @functools.partial(jaxext.autobatch, max_io_nbytes=2**29)
59
61
  def quantilize(X):
62
+ # wrap this function because autobatch needs traceable args
60
63
  return _quantilized_splits_from_matrix(X, out_length)
64
+
61
65
  return quantilize(X)
62
66
 
67
+
63
68
  @functools.partial(jax.vmap, in_axes=(0, None))
64
69
  def _quantilized_splits_from_matrix(x, out_length):
65
70
  huge = jaxext.huge_value(x)
@@ -67,21 +72,28 @@ def _quantilized_splits_from_matrix(x, out_length):
67
72
  actual_length -= 1
68
73
  if jnp.issubdtype(x.dtype, jnp.integer):
69
74
  midpoints = u[:-1] + jaxext.ensure_unsigned(u[1:] - u[:-1]) // 2
70
- indices = jnp.arange(midpoints.size, dtype=jaxext.minimal_unsigned_dtype(midpoints.size - 1))
75
+ indices = jnp.arange(
76
+ midpoints.size, dtype=jaxext.minimal_unsigned_dtype(midpoints.size - 1)
77
+ )
71
78
  midpoints = jnp.where(indices < actual_length, midpoints, huge)
72
79
  else:
73
80
  midpoints = (u[1:] + u[:-1]) / 2
74
81
  indices = jnp.linspace(-1, actual_length, out_length + 2)[1:-1]
75
- indices = jnp.around(indices).astype(jaxext.minimal_unsigned_dtype(midpoints.size - 1))
76
- # indices calculation with float rather than int to avoid potential
77
- # overflow with int32, and to round to nearest instead of rounding down
82
+ indices = jnp.around(indices).astype(
83
+ jaxext.minimal_unsigned_dtype(midpoints.size - 1)
84
+ )
85
+ # indices calculation with float rather than int to avoid potential
86
+ # overflow with int32, and to round to nearest instead of rounding down
78
87
  decimated_midpoints = midpoints[indices]
79
88
  truncated_midpoints = midpoints[:out_length]
80
- splits = jnp.where(actual_length > out_length, decimated_midpoints, truncated_midpoints)
89
+ splits = jnp.where(
90
+ actual_length > out_length, decimated_midpoints, truncated_midpoints
91
+ )
81
92
  max_split = jnp.minimum(actual_length, out_length)
82
93
  max_split = max_split.astype(jaxext.minimal_unsigned_dtype(out_length))
83
94
  return splits, max_split
84
95
 
96
+
85
97
  @functools.partial(jax.jit, static_argnums=(1,))
86
98
  def uniform_splits_from_matrix(X, num_bins):
87
99
  """
@@ -110,6 +122,7 @@ def uniform_splits_from_matrix(X, num_bins):
110
122
  max_split = jnp.full(*splits.shape, jaxext.minimal_unsigned_dtype(num_bins - 1))
111
123
  return splits, max_split
112
124
 
125
+
113
126
  @functools.partial(jax.jit, static_argnames=('method',))
114
127
  def bin_predictors(X, splits, **kw):
115
128
  """
@@ -135,9 +148,11 @@ def bin_predictors(X, splits, **kw):
135
148
  A matrix with `p` predictors and `n` observations, where each predictor
136
149
  has been replaced by the index of the bin it falls into.
137
150
  """
138
- @functools.partial(jaxext.autobatch, max_io_nbytes=2 ** 29)
151
+
152
+ @functools.partial(jaxext.autobatch, max_io_nbytes=2**29)
139
153
  @jax.vmap
140
154
  def bin_predictors(x, splits):
141
155
  dtype = jaxext.minimal_unsigned_dtype(splits.size)
142
156
  return jnp.searchsorted(splits, x, **kw).astype(dtype)
157
+
143
158
  return bin_predictors(X, splits)
@@ -1,22 +1,20 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: bartz
3
- Version: 0.4.1
3
+ Version: 0.6.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: equinox>=0.12.2
9
+ Requires-Dist: jax>=0.4.35
10
+ Requires-Dist: jaxlib>=0.4.35
11
+ Requires-Dist: jaxtyping>=0.3.2
12
+ Requires-Dist: numpy>=1.25.2
13
+ Requires-Dist: scipy>=1.11.4
8
14
  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
15
+ Project-URL: Documentation, https://gattocrucco.github.io/bartz/docs-dev
16
+ Project-URL: Homepage, https://github.com/Gattocrucco/bartz
17
+ Project-URL: Issues, https://github.com/Gattocrucco/bartz/issues
20
18
  Description-Content-Type: text/markdown
21
19
 
22
20
  [![PyPI](https://img.shields.io/pypi/v/bartz)](https://pypi.org/project/bartz/)
@@ -42,6 +40,7 @@ On CPU, bartz runs at the speed of dbarts (the fastest implementation I know of)
42
40
  - [Documentation (development version)](https://gattocrucco.github.io/bartz/docs-dev)
43
41
  - [Repository](https://github.com/Gattocrucco/bartz)
44
42
  - [Code coverage](https://gattocrucco.github.io/bartz/coverage)
43
+ - [Benchmarks](https://gattocrucco.github.io/bartz/benchmarks)
45
44
  - [List of BART packages](https://gattocrucco.github.io/bartz/docs-dev/pkglist.html)
46
45
 
47
46
  ## Citing bartz
@@ -49,4 +48,3 @@ On CPU, bartz runs at the speed of dbarts (the fastest implementation I know of)
49
48
  Article: Petrillo (2024), "Very fast Bayesian Additive Regression Trees on GPU", [arXiv:2410.23244](https://arxiv.org/abs/2410.23244).
50
49
 
51
50
  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=4de980d640f694e4b65fb17d7c5fe605e15c10f730ee842d39e45501ae8b6829,21606
3
+ bartz/__init__.py,sha256=b57b8ecb9f97ced8a543fa65e191ebda4addd79ef12a8fb357e4f6b23ac2ca72,1434
4
+ bartz/_version.py,sha256=0816378ec0bef470a6ede67a08a0feb182c27a3a8e275a5858f40ce0b1885dc2,22
5
+ bartz/debug.py,sha256=6e06cccfe1c5d6858e62200cd679b73a528af27780d33ba6c164a3a6d96660a5,5356
6
+ bartz/grove.py,sha256=955f03269f373e7bc4f917c6d2ba598e363e8f910adea7f2195693c8443ad381,9636
7
+ bartz/jaxext.py,sha256=ac9aff86e4fb9ff43b5d98995df2b9416a715c82f87270eb1c547fae8973c6dd,13122
8
+ bartz/mcmcloop.py,sha256=e2ad8ae5fb0a49ad3c874e25b6bf2ea966f4d678c0b99bf575393cbe388514bf,17695
9
+ bartz/mcmcstep.py,sha256=5ef4303dfe06be65c3bdfaf44217c74c3e6244444b03dcc5d6eacdee8c9b1d34,72891
10
+ bartz/prepcovars.py,sha256=0db7601a7a73cba508ed4d8c1ca9ac07baacd4f756978bbc80cf173c9257a5ed,5894
11
+ bartz-0.6.0.dist-info/WHEEL,sha256=ec89e25a684ec3ad8fb2a9be806e47666a27f7dcdcf9b55bff3f1d3ed5e60e0a,78
12
+ bartz-0.6.0.dist-info/METADATA,sha256=c35ffe8f0dab8de368e277041105f64650b26f9f4582015cb1b334f88a0e72d6,2846
13
+ bartz-0.6.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.7.8
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -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.
@@ -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,,
@@ -1,4 +0,0 @@
1
- Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.2
3
- Root-Is-Purelib: true
4
- Tag: py3-none-any