From f1750493c5f047e7025ab8d264ece87602929d43 Mon Sep 17 00:00:00 2001 From: aloctavodia Date: Sat, 8 Jul 2023 20:59:12 -0300 Subject: [PATCH 1/2] improve docstrings --- docs/api_reference.rst | 2 +- pymc_bart/bart.py | 8 +++++++- pymc_bart/pgbart.py | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/api_reference.rst b/docs/api_reference.rst index 3ba2f6f..50801b4 100644 --- a/docs/api_reference.rst +++ b/docs/api_reference.rst @@ -13,4 +13,4 @@ methods in the current release of PyMC-BART. ============================= .. automodule:: pymc_bart - :members: BART, PGBART, plot_pdp, plot_variable_importance, plot_convergence + :members: BART, PGBART, plot_pdp, plot_variable_importance, plot_convergence, ContinuousSplitRule, OneHotSplitRule, SubsetSplitRule \ No newline at end of file diff --git a/pymc_bart/bart.py b/pymc_bart/bart.py index e8b514f..a3b4915 100644 --- a/pymc_bart/bart.py +++ b/pymc_bart/bart.py @@ -16,6 +16,7 @@ from multiprocessing import Manager from typing import List, Optional, Tuple +import warnings import numpy as np import numpy.typing as npt @@ -81,7 +82,7 @@ class BART(Distribution): Number of trees. response : str How the leaf_node values are computed. Available options are ``constant``, ``linear`` or - ``mix``. Defaults to ``constant``. + ``mix``. Defaults to ``constant``. Options ``linear`` and ``mix`` are still experimental. alpha : float Controls the prior probability over the depth of the trees. Should be in the (0, 1) interval. @@ -127,6 +128,11 @@ def __new__( separate_trees: Optional[bool] = False, **kwargs, ): + if response in ["linear", "mix"]: + warnings.warn( + "Options linear and mix are experimental and still not well tested\n" + + "Use with caution." + ) manager = Manager() cls.all_trees = manager.list() diff --git a/pymc_bart/pgbart.py b/pymc_bart/pgbart.py index 46cff75..652da16 100644 --- a/pymc_bart/pgbart.py +++ b/pymc_bart/pgbart.py @@ -381,6 +381,8 @@ def competence(var, has_grad): class RunningSd: + """Welford's online algorithm for computing the variance/standard deviation""" + def __init__(self, shape: tuple) -> None: self.count = 0 # number of data points self.mean = np.zeros(shape) # running mean @@ -430,6 +432,9 @@ def compute_prior_probability(alpha: int, beta: int) -> List[float]: """ Calculate the probability of the node being a leaf node (1 - p(being split node)). + This is the recommend prior in Chipman Et al. BART: Bayesian additive regression trees, + `link `__ + Parameters ---------- alpha : float From e830359a06ff97d97cc545b03c293a90b5a156c2 Mon Sep 17 00:00:00 2001 From: aloctavodia Date: Sat, 8 Jul 2023 21:08:05 -0300 Subject: [PATCH 2/2] move chipman reference --- pymc_bart/bart.py | 3 +++ pymc_bart/pgbart.py | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pymc_bart/bart.py b/pymc_bart/bart.py index a3b4915..86d6314 100644 --- a/pymc_bart/bart.py +++ b/pymc_bart/bart.py @@ -112,6 +112,9 @@ class BART(Distribution): The parameters ``alpha`` and ``beta`` parametrize the probability that a node at depth :math:`d \: (= 0, 1, 2,...)` is non-terminal, given by :math:`\alpha(1 + d)^{-\beta}`. The default values are :math:`\alpha = 0.95` and :math:`\beta = 2`. + + This is the recommend prior by Chipman Et al. BART: Bayesian additive regression trees, + `link `__ """ def __new__( diff --git a/pymc_bart/pgbart.py b/pymc_bart/pgbart.py index 652da16..459684d 100644 --- a/pymc_bart/pgbart.py +++ b/pymc_bart/pgbart.py @@ -432,9 +432,6 @@ def compute_prior_probability(alpha: int, beta: int) -> List[float]: """ Calculate the probability of the node being a leaf node (1 - p(being split node)). - This is the recommend prior in Chipman Et al. BART: Bayesian additive regression trees, - `link `__ - Parameters ---------- alpha : float