Taweret.mix.trees

class Taweret.mix.trees.Trees(model_dict: dict, **kwargs)[source]

Bases: BaseMixer

Constructor for the Trees mixing class, which implements a mean-mixing strategy. The weight functions are modeled using Bayesian Additive Regression Trees (BART). Please read the installation page of the documentation to ensure the BART-BMM Ubuntu package is downloaded and installed.

\[f_\dagger(x) = \sum_{k = 1}^K w_k(x)\;f_k(x)\]

Example:

# Initialize trees class
mix = Trees(model_dict = model_dict)

# Set prior information
mix.set_prior(k=2.5,ntree=30,overallnu=5,
overallsd=0.01,inform_prior=False)

# Train the model
fit = mix.train(X=x_train, y=y_train, ndpost = 10000,
nadapt = 2000, nskip = 2000, adaptevery = 500, minnumbot = 4)

# Get predictions and posterior weight functions.
ppost, pmean, pci, pstd = mix.predict(X = x_test, ci = 0.95)
wpost, wmean, wci, wstd = mix.predict_weights(X=x_test,ci = 0.95)

Parameters:

param dict model_dict:

Dictionary of models where each item is an instance of BaseModel.

param dict kwargs:

Additional arguments to pass to the constructor.

Returns:

returns:

None.

evaluate()[source]

Evaluate the mixed-model to get a point prediction. This method is not applicable to BART-based mixing.

evaluate_weights()[source]

Evaluate the weight functions to get a point prediction. This method is not applicable to BART-based mixing.

property map

Return the map values for parameters in the model. This method is not applicable to BART-based mixing.

property posterior

Returns the posterior distribution of the error standard deviation, which is learned during the training process.

Parameters:

param:

None.

Returns:

returns:

The posterior of the error standard deviation .

rtype:

np.ndarray

predict(X: ndarray, ci: float = 0.95)[source]

Obtain the posterior predictive distribution of the mixed-model at a set of inputs X.

Parameters:

param np.ndarray X:

design matrix of testing inputs.

param float ci:

credible interval width, must be a value within the interval (0,1).

Returns:

returns:

The posterior prediction draws and summaries.

rtype:

np.ndarray, np.ndarray, np.ndarray, np.ndarray

return value:

the posterior predictive distribution evaluated at the specified test points

return value:

the posterior mean of the mixed-model at each input in X.

return value:

the pointwise credible intervals at each input in X.

return value:

the posterior standard deviation of the mixed-model at each input in X.

predict_weights(X: ndarray, ci: float = 0.95)[source]

Obtain posterior distribution of the weight functions at a set of inputs X.

Parameters:

param np.ndarray X:

design matrix of testing inputs.

param float ci:

credible interval width, must be a value within the interval (0,1).

Returns:

returns:

The posterior weight function draws and summaries.

rtype:

np.ndarray, np.ndarray, np.ndarray, np.ndarray

return value:

the posterior draws of the weight functions at each input in X.

return value:

posterior mean of the weight functions at each input in X.

return value:

pointwise credible intervals for the weight functions.

return value:

posterior standard deviation of the weight functions at each input in X.

property prior

Returns a dictionary of the hyperparameter settings used in the various prior distributions.

Parameters:

param:

None.

Returns:

returns:

A dictionary of the hyperparameters used in the model.

rtype:

dict

prior_predict()[source]

Return the prior predictive distribution of the mixed-model. This method is not applicable to BART-based mixing.

set_prior(ntree: int = 1, ntreeh: int = 1, k: float = 2, power: float = 2.0, base: float = 0.95, sighat: float = 1, nu: int = 10, inform_prior: bool = True)[source]

Sets the hyperparameters in the tree and terminal node priors. Also specifies if an informative or non-informative prior will be used when mixing EFTs.

Parameters:

param int ntree:

The number of trees used in the sum-of-trees model for the weights.

param int ntreeh:

The number of trees used in the product-of-trees model for the error standard deviation. Set to 1 for homoscedastic variance assumption.

param float k:

The tuning parameter in the prior variance of the terminal node parameter prior. This is a value greater than zero.

param float power:

The power parameter in the tree prior.

param float base:

The base parameter in the tree prior.

param float overallsd:

An initial estimate of the error standard deviation. This value is used to calibrate the scale parameter in variance prior.

param float overallnu:

The shape parameter in the error variance prior.

param bool inform_prior:

Controls if the informative or non-informative prior is used. Specify true for the informative prior.

param np.ndarray tauvec:

A K-dimensional array (where K is the number of models) that contains the prior standard deviation of the terminal node parameter priors. This is used when specifying different priors for the different model weights.

param np.ndarray betavec:

A K-dimensional array (where K is the number of models) that contains the prior mean of the terminal node parameter priors. This is used when specifying different priors for the different model weights.

Returns:

returns:

None.

train(X: ndarray, y: ndarray, **kwargs)[source]

Train the mixed-model using a set of observations y at inputs x.

Parameters:

param np.ndarray X:

input parameter values of dimension (n x p).

param np.ndarray y:

observed data at inputs X of dimension (n x 1).

param dict kwargs:

dictionary of arguments

Returns:

returns:

A dictionary which contains relevant information to the model such as values of tuning parameters. The MCMC results are written to a text file and stored in a temporary directory as defined by the fpath key in the results dictionary.

rtype:

dict