GPyTorch Gaussian Process Regression Learner
Source:R/learner_gpytorch_regr_gpytorch.R
mlr_learners_regr.gpytorch.RdExact Gaussian process regression with a constant mean, a scaled kernel, and a Gaussian likelihood.
The hyperparameters are fitted by maximizing the exact marginal log likelihood with the Adam optimizer.
Uses reticulate to interface with the gpytorch Python package.
The features and the target are standardized to zero mean and unit variance before the model is fitted, and the predictions are transformed back to the original scale. The standard error is the posterior standard deviation of the latent function, i.e. it does not include the observation noise.
Custom mlr3 parameters
gpytorch has no ready-made training function, so all parameters are defined by this learner.
kernelis the base kernel that is wrapped in aScaleKernel."rbf"is theRBFKernel, and"matern_0.5","matern_1.5", and"matern_2.5"are theMaternKernelwith the respective smoothness parameternu.lris the learning rate of the Adam optimizer.n_iteris the number of optimizer steps.deviceis the torch device on which the model is fitted and predictions are computed."auto"selects"cuda"if available and"cpu"otherwise.
Installation
This learner relies on reticulate to handle Python dependencies.
It is not necessary to install any Python package manually in advance or specify a Python environment
via reticulate::use_python(), reticulate::use_virtualenv(), reticulate::use_condaenv(),
or reticulate::use_miniconda().
By calling $train() or $predict(), the required Python packages (gpytorch and torch) will be installed
automatically, if not already.
Reticulate will then configure and initialize an ephemeral environment satisfying those requirements,
unless an existing environment (e.g., "r-reticulate") in reticulate's
Order of Discovery
contains all the necessary packages.
You may also manually install gpytorch into a Python environment and specify the environment via
reticulate::use_*() before calling $train() or $predict(), for example:
reticulate::virtualenv_create("gpytorch", packages = c("torch", "gpytorch"))
reticulate::use_virtualenv("gpytorch", required = TRUE)Saving a Learner
In order to save a LearnerRegrGPyTorch for later usage,
it is necessary to call the $marshal() method on the Learner
before writing it to disk, as the object will otherwise not be saved correctly.
After loading a marshaled LearnerRegrGPyTorch into R again,
you then need to call $unmarshal() to transform it into a useable state.
Meta Information
Task type: “regr”
Predict Types: “response”, “se”
Feature Types: “integer”, “numeric”
Required Packages: mlr3, mlr3extralearners, reticulate
Parameters
| Id | Type | Default | Levels | Range |
| kernel | character | rbf | rbf, matern_0.5, matern_1.5, matern_2.5 | - |
| lr | numeric | 0.1 | \([0, \infty)\) | |
| n_iter | integer | 50 | \([1, \infty)\) | |
| device | character | auto | auto, cpu, cuda | - |
References
Gardner, R J, Pleiss, Geoff, Weinberger, Q K, Bindel, David, Wilson, Gordon A (2018). “GPyTorch: Blackbox Matrix-Matrix Gaussian Process Inference with GPU Acceleration.” In Advances in Neural Information Processing Systems, volume 31.
See also
as.data.table(mlr_learners)for a table of available Learners in the running session (depending on the loaded packages).Chapter in the mlr3book: https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html#sec-learners
mlr3learners for a selection of recommended learners.
mlr3cluster for unsupervised clustering learners.
mlr3pipelines to combine learners with pre- and postprocessing steps.
mlr3tuning for tuning of hyperparameters, mlr3tuningspaces for established default tuning spaces.
Super classes
mlr3::Learner -> mlr3::LearnerRegr -> LearnerRegrGPyTorch
Methods
Inherited methods
mlr3::Learner$base_learner()mlr3::Learner$configure()mlr3::Learner$encapsulate()mlr3::Learner$format()mlr3::Learner$help()mlr3::Learner$predict()mlr3::Learner$predict_newdata()mlr3::Learner$print()mlr3::Learner$reset()mlr3::Learner$selected_features()mlr3::Learner$train()mlr3::LearnerRegr$predict_newdata_fast()
LearnerRegrGPyTorch$marshal()
Marshal the learner's model.
Arguments
...(any)
Additional arguments passed tomlr3::marshal_model().
LearnerRegrGPyTorch$unmarshal()
Unmarshal the learner's model.
Arguments
...(any)
Additional arguments passed tomlr3::unmarshal_model().