Elem: Create a Node Element Object

Description Usage Arguments Format Details Value Fields Methods Author(s) Examples

Description

Elem is a class of R6. It is the element of a node in a Tree or ORT object, storing some important information of the node/Tree.

Usage

1
Elem$new(param, splitInd = -1, splitVal = 0, numSamplesSeen = 0)

Arguments

param

A list which usually has names of minSamples, minGain, numClasses, x.rng, etc.

splitInd

A integer indicates which x variable is used to split on current node. Default NULL.

splitVal

A numeric indicates what value of the chosen x variable is used to split on current node. Means: x[splitInd] < splitVal. Default NULL.

numSamplesSeen

A integer indicates how many samples have come in current node for updating the ORT tree. Default 0.

Format

R6Class object.

Details

See details in description of each field or method.

Value

Object of R6Class, Object of Node Element.

Fields

x.rng

A data frame which indicates the range of every x variable in training data. It must be a shape of n*2 which n is the number of x variables, i.e. x.dim. And the first collumn must be the minimal values of x and the second as maximum. You can generate it via OnlineRandomForest::dataRange() for convenience.

x.dim

Number of x variables.

tests

A list of SuffStats. Candicate splits of current node.

numTests

A part of param indicates the number of SuffStats in tests

stats

A SuffStats object. The real splits of current node.

Methods

toString()

Print elem itself or the split of condition on current node.

pred()

Return the prediction of current leaf node. Will return an integer for classification or an numeric for regression.

update(x, y)

When a sample comes in current node, update ORT with the sample's x variables and y value.

  • x - The x variables of a sample. Note it is an numeric vector other than a scalar.

  • y - The y value of a sample.

updateSplit(xvar.index, xvar.value)

Replace the fields splitInd and splitVal of current node with xvar.index and xvar.value.

...

Other functions, usually not used.

Author(s)

Quan Gu

Examples

1
2
3
4
5
6
7
8
x.rng <- data.frame(min = c(1,3,5,7), max = c(2,4,6,8), row.names = paste0("x",1:4))
param <- list('minSamples'= 5, 'minGain'= 0.1, 'numClasses'= 3, 'x.rng'= x.rng)
elm <- Elem$new(param)
length(elm$tests)
elm$tests[c(1,8)]
elm$updateSplit(3, 5.2)
elm$toString()
elm$update(c(1.1, 3.2, 5.3, 7.4), 1)

ZJUguquan/OnlineRandomForest documentation built on May 20, 2019, 2:57 p.m.