BaselearnerCustomCpp creates a custom base-learner factory by setting custom C++ functions. This factory object can be registered within a base-learner list and then used for training.

Format

S4 object.

Usage

BaselearnerCustomCpp$new(data_source, data_target, list(instantiate_ptr,
  train_ptr, predict_ptr))

Arguments

data_source [Data Object]

Data object which contains the source data.

data_target [Data Object]

Data object which gets the transformed source data.

instantiate_ptr [externalptr]

External pointer to the C++ instantiate data function.

train_ptr [externalptr]

External pointer to the C++ train function.

predict_ptr [externalptr]

External pointer to the C++ predict function.

Details

For an example see the extending compboost vignette or the function getCustomCppExample.

This class is a wrapper around the pure C++ implementation. To see the functionality of the C++ class visit https://schalkdaniel.github.io/compboost/cpp_man/html/classblearnerfactory_1_1_custom_cpp_blearner_factory.html.

Fields

This class doesn't contain public fields.

Methods

getData()

Get the data matrix of the target data which is used for modeling.

transformData(X)

Transform a data matrix as defined within the factory. The argument has to be a matrix with one column.

summarizeFactory()

Summarize the base-learner factory object.

Examples

# Sample data: data_mat = cbind(1, 1:10) y = 2 + 3 * 1:10 # Create new data object: data_source = InMemoryData$new(data_mat, "my_data_name") data_target = InMemoryData$new() # Source the external pointer exposed by using XPtr: Rcpp::sourceCpp(code = getCustomCppExample(silent = TRUE)) # Create new linear base-learner: custom_cpp_factory = BaselearnerCustomCpp$new(data_source, data_target, list(instantiate_ptr = dataFunSetter(), train_ptr = trainFunSetter(), predict_ptr = predictFunSetter())) # Get the transformed data: custom_cpp_factory$getData()
#> [,1] [,2] #> [1,] 1 1 #> [2,] 1 2 #> [3,] 1 3 #> [4,] 1 4 #> [5,] 1 5 #> [6,] 1 6 #> [7,] 1 7 #> [8,] 1 8 #> [9,] 1 9 #> [10,] 1 10
# Summarize factory: custom_cpp_factory$summarizeFactory()
#> Custom cpp base-learner Factory: #> - Name of the used data: my_data_name #> - Factory creates the following base-learner: custom_cpp
# Transform data manually: custom_cpp_factory$transformData(data_mat)
#> [,1] [,2] #> [1,] 1 1 #> [2,] 1 2 #> [3,] 1 3 #> [4,] 1 4 #> [5,] 1 5 #> [6,] 1 6 #> [7,] 1 7 #> [8,] 1 8 #> [9,] 1 9 #> [10,] 1 10