Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ cython_debug/

**.csv
tests/test_hmc.py
tests/bench_bart.py
4 changes: 1 addition & 3 deletions pymc_bart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# If removed, the PGBART step method will not be detected by PyMC.
import bartrs # registers PGBART with PyMC.
import bartrs

# Fix precommit complaining about unused import
if bartrs:
pass

Expand Down
7 changes: 5 additions & 2 deletions pymc_bart/bart.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pytensor.tensor.sharedvar import TensorSharedVariable
from pytensor.tensor.variable import TensorVariable

from .utils import TensorLike, _sample_posterior
from .utils import TensorLike, _get_posterior_sampler, _sample_posterior

__all__ = ["BART"]

Expand Down Expand Up @@ -62,7 +62,10 @@ def rng_fn( # pylint: disable=W0237
else:
return np.full(Y.shape[0], Y.mean())
else:
return _sample_posterior(cls.all_trees, cls.X, rng=rng).squeeze().T
shape = size[0] if size is not None else 1
sampler = _get_posterior_sampler(cls)
pred = _sample_posterior(sampler, X, rng=rng, size=shape)
return pred.squeeze().T


bart = BARTRV()
Expand Down
15 changes: 10 additions & 5 deletions pymc_bart/pymc_bart.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
try:
from bartrs.bartrs import PyBartSettings, PySampler, TreeArrays
from bartrs.bartrs import PosteriorSampler, PyBartSettings, PySampler, TreeArrays
except Exception as e:
print(f"Warning: Could not import PyBartSettings, PySampler, or TreeArrays due to: {e}")
PyBartSettings = PySampler = TreeArrays = None
print(f"""Warning: Could not import PyBartSettings,
PySampler, TreeArrays, or PosteriorSampler due to: {e}""")
PyBartSettings = PySampler = TreeArrays = PosteriorSampler = None

for cls in (PyBartSettings, PySampler, TreeArrays):
for cls in (PyBartSettings, PySampler, TreeArrays, PosteriorSampler):
if cls is not None:
cls.__module__ = "pymc_bart.pymc_bart"

__all__ = [name for name in ("PyBartSettings", "PySampler", "TreeArrays") if globals().get(name)]
__all__ = [
name
for name in ("PyBartSettings", "PySampler", "TreeArrays", "PosteriorSampler")
if globals().get(name)
]
Loading
Loading