BaselearnerTensor: Row-wise tensor product base learner

BaselearnerTensorR Documentation

Row-wise tensor product base learner

Description

This class combines base learners. The base learner is defined by a data matrix calculated as row-wise tensor product of the two data matrices given in the base learners to combine.

Arguments

blearner1

(⁠Baselearner*⁠)
First base learner.

blearner2

(⁠Baselearner*⁠)
Second base learner.

blearner_type

(character(1))
Type of the base learner (if not specified, blearner_type = "spline" is used). The unique id of the base learner is defined by appending blearner_type to the feature name: ⁠paste0(blearner1$getDataSource()getIdentifier(), "_", blearner2$getDataSource()getIdentifier(), "_", blearner_type)⁠.

anisotrop

(logical(1))
Defines how the penalty is added up. If anisotrop = TRUE, the marginal effects of the are penalized as defined in the underlying factories. If anisotrop = FALSE, an isotropic penalty is used, which means that both directions gets penalized equally.

Format

S4 object.

Usage

BaselearnerTensor$new(blearner1, blearner2, blearner_type)
BaselearnerTensor$new(blearner1, blearner2, blearner_type, anisotrop)

Fields

This class doesn't contain public fields.

Methods

  • ⁠$summarizeFactory()⁠: ⁠() -> ()⁠

  • ⁠$transfromData(newdata)⁠: list(InMemoryData) -> matrix()

  • ⁠$getMeta()⁠: ⁠() -> list()⁠

Inherited methods from Baselearner

  • ⁠$getData()⁠: ⁠() -> matrix()⁠

  • ⁠$getDF()⁠: ⁠() -> integer()⁠

  • ⁠$getPenalty()⁠: ⁠() -> numeric()⁠

  • ⁠$getPenaltyMat()⁠: ⁠() -> matrix()⁠

  • ⁠$getFeatureName()⁠: ⁠() -> character()⁠

  • ⁠$getModelName()⁠: ⁠() -> character()⁠

  • ⁠$getBaselearnerId()⁠: ⁠() -> character()⁠

Examples

# Sample data:
x1 = runif(100, 0, 10)
x2 = runif(100, 0, 10)
y = sin(x1) * cos(x2) + rnorm(100, 0, 0.2)
dat = data.frame(x1, x2, y)

# S4 wrapper

# Create new data object, a matrix is required as input:
ds1 = InMemoryData$new(cbind(x1), "x1")
ds2 = InMemoryData$new(cbind(x2), "x2")

# Create new linear base learner factory:
bl1 = BaselearnerPSpline$new(ds1, "sp", list(n_knots = 10, df = 5))
bl2 = BaselearnerPSpline$new(ds2, "sp", list(n_knots = 10, df = 5))

tensor = BaselearnerTensor$new(bl1, bl2, "row_tensor")

# Get the transformed data:
dim(tensor$getData())

# Get full meta data such as penalty term or matrix as well as knots:
str(tensor$getMeta())

# Transform "new data":
newdata = list(InMemoryData$new(cbind(runif(5)), "x1"),
  InMemoryData$new(cbind(runif(5)), "x2"))
str(tensor$transformData(newdata))

# R6 wrapper

cboost = Compboost$new(dat, "y")
cboost$addTensor("x1", "x2", df = 5)
cboost$train(50, 0)

table(cboost$getSelectedBaselearner())
plotTensor(cboost, "x1_x2_tensor")

schalkdaniel/compboost documentation built on April 15, 2023, 9:03 p.m.