API Specification¶
This page covers the API specification for the following classes:
Locally Growing Random Tree Node¶
-
class
lgrt4gps.lgrtn.LGRTN(dx, dy, kerns=(), GP_engine='sklearn', div_method='center', wo_ratio=100, max_pts=100, inf_method='moe', optimize_hyps=False, lazy_training=False, sct=None, multi_processing=False, bounds=None, **kwargs)¶ Locally Growing Random Tree Node inherits from BTN
New in version 0.0.1.
- Attributes
- dxint
input dimension
- dyint
output dimension
kernelslist (length: dy)list of kernel instances (one for each output dimension), read only
- GP_enginestr, optional
Default is ‘’ for simple high-speed GP or ‘GPy’ using the GPy package
- div_methodstring, optional
Method to divide a dataset. Choices are ‘median’, ‘mean’, ‘center’
- wo_ratiofloat, optional
width/overlap ratio. must be > 1
- max_ptsint, optional
maximum number of points per leaf
- inf_methodstring, optional
Method to combine local predictions Choices ‘moe’ (Mixture of Experts)
- optimize_hypsbool
Turn hyperparameter optimization on or off
- lazy_trainingbool
Wait with training until prediction is called
- multi_processingbool
enables parrallel processing (for 1e5 datapoints overhead is too big)
Methods
add_data(x, y)Adds data points to the node (or its children)
check_parent_child()Checks if all parent relations are set
fit([optimize_hyps])Prepares the model for prediction
Recursively gathers training data from all leaves
get_root()Iteratively finds root of the tree
pprint([index, delimiter])Pretty-print the binary tree.
predict(xt[, return_std])Predicts posterior mean and standard deviation based on all leaf GPs
validate()Check if the binary tree is malformed.
-
property
X¶ input training data, read only
- Returns
- Xnumpy array (ntr x dx)
input training data
-
property
Y¶ output training data, read only
- Returns
- Ynumpy array (ntr x dy)
output training data
-
_compute_musig(xt, return_std)¶ Calls gp from GPy to make predictions
- Parameters
- xtnumpy array (n x dx)
test inputs
- return_stdbool (default: False)
whether std dev is computed or not
- Returns
- munumpy array (n x dy)
posterior mean
- signumpy array (n x dy)
posterior variance
-
_distribute_data(x, y)¶ Distributes data to children
- Parameters
- xnumpy array (n x dx)
- ynumpy array (n x dy)
-
_divide(x, y)¶ The current node grows two children and distributes its data
The node grows two children and distributes the new data (x,y) and its own data to the children
- Parameters
- xnumpy array (n x dx)
- ynumpy array (n x dy)
-
_get_divider(x)¶ Computes parameters required for division of data set
Computes dimension with widest spread
Computes division values ‘median’, ‘mean’, or ‘center’
3. Computes overlap region Parameters ———- x : numpy array (n x dx)
- Returns
- dimint (1…dx)
dividing dimension
- valfloat
dividing value
- ofloat
overlap
-
_predict_local(xt, log_p, return_std)¶ Local prediction function
If current node is leaf, compute posterior estimates. If is not leaf, recurse further if any child has non-zero probability
- Parameters
- xtnumpy array (n x dx)
input test points
- log_p :
log probability to reach the leaf
- return_stdbool (default: False)
whether std dev is computed or not
-
_prob_left(x)¶ Computes probabilities of for left child
- Parameters
- xnumpy array (n x dx)
- Returns
- prob_left: numpy array (n,)
probabilities for left child
-
_setup_gps(optimize_hyps=None)¶ Prepare gp models (one for each output)
-
add_data(x, y)¶ Adds data points to the node (or its children)
Three options exist: 1. node is not a leaf: distribute data to children 2. node is a leaf, but full: grow two children and distribute 3. node is a leaf is not full: add data to node
- Parameters
- xnumpy array (n x dx)
input data to be added
- ynumpy array (n x dx)
output data to be added
-
fit(optimize_hyps=None)¶ Prepares the model for prediction
For lazy training it enforces generation of GPs and trains the hyperparameters if needed
-
get_child_xy()¶ Recursively gathers training data from all leaves
- Returns
- childXnumpy array (ntr x dx)
Input training data concatenated from all children
- childYnumpy array (ntr x dy)
Output training data concatenated from all children
-
property
gps¶ list of GP instances (one for each output dimension), read only
- Returns
- gpslist
list of GP instances
-
property
is_full¶ True if current node reached maximum capacity
- Returns
- is_fullbool
-
property
kernels¶ list of kernel instances (one for each output dimension), read only
- Returns
- kernelslist
-
predict(xt, return_std=False)¶ Predicts posterior mean and standard deviation based on all leaf GPs
Starts the recursive call to prediction functions of leaves and combines the predictions according to the chosen inference method
- Parameters
- xtnumpy array (n x dx)
test inputs
- return_stdbool (default: False)
whether std dev is computed or not
- Returns
- ——-
- munumpy array (n x dy)
posterior mean
- signumpy array (n x dy)
posterior standard deviation
Binary Tree Node¶
-
class
lgrt4gps.btn.BTN(parent=None, value=0, **kwargs)¶ Binary Tree Node inherits from Node in package binarytree
New in version 0.0.1.
- Attributes
- _parentBTN
parent
- strstr
string to describe the node
Methods
Checks if all parent relations are set
get_root()Iteratively finds root of the tree
pprint([index, delimiter])Pretty-print the binary tree.
validate()Check if the binary tree is malformed.
-
check_parent_child()¶ Checks if all parent relations are set
- Returns
- correctbool
True if relations of all subtrees are correct False if there is a missing link
-
get_root()¶ Iteratively finds root of the tree
- Returns
- rootBTN
root of the tree
-
property
is_leaf¶ Returns True if current node is a leaf, False otherwise
- Returns
- is_leafbool
-
property
is_root¶ Returns True if current node is a root, False otherwise
- Returns
- is_rootbool
-
property
parent¶ Get parent of current node
- Returns
- parentBTN