CompactRegressionGP
Compact Gaussian process regression model class
Description
CompactRegressionGP is a compact Gaussian process
regression (GPR) model. The compact model consumes less memory than a full model,
because it does not include the data used for training the GPR model.
Because the compact model does not include the training data, you cannot perform some
tasks, such as cross-validation, using the compact model. However, you can use the
compact model for making predictions or calculate regression loss for new data (use
predict and loss).
Creation
Create a CompactRegressionGP object from a full RegressionGP model object by using compact.
Properties
Fitting
This property is read-only.
Method used to estimate the basis function coefficients, β; noise standard deviation, σ; and kernel parameters, θ, of the GPR model, returned as a character vector. It can be one of the following.
| Fit Method | Description |
|---|---|
'none' | No estimation. fitrgp uses the initial
parameter values as the parameter values. |
'exact' | Exact Gaussian process regression. |
'sd' | Subset of data points approximation. |
'sr' | Subset of regressors approximation. |
'fic' | Fully independent conditional approximation. |
This property is read-only.
Explicit basis function used in the GPR model, returned as a character vector or a function handle. It can be one of the following. If n is the number of observations, the basis function adds the term H*β to the model, where H is the basis matrix and β is a p-by-1 vector of basis coefficients.
| Explicit Basis | Basis Matrix |
|---|---|
'none' | Empty matrix. |
'constant' |
H is an n-by-1 vector of 1s, where n is the number of observations. |
'linear' |
X is the expanded predictor data after
the software creates dummy variables for the categorical variables.
For details about creating dummy variables, see
|
'pureQuadratic' |
where
For this basis option, |
| Function handle | Function handle, where X is an n-by-d matrix of predictors, d is the number of predictors after the software creates dummy variables for the categorical variables, and H is an n-by-p matrix of basis functions. |
Data Types: char | function_handle
This property is read-only.
Categorical predictor
indices, returned as a vector of positive integers. CategoricalPredictors
contains index values indicating that the corresponding predictors are categorical. The index
values are between 1 and p, where p is the number of
predictors used to train the model. If none of the predictors are categorical, then this
property is empty ([]).
Data Types: single | double
This property is read-only.
Estimated coefficients for the explicit basis functions, returned as a vector. You can
define the explicit basis function by using the BasisFunction
name-value pair argument in fitrgp.
Data Types: double
This property is read-only.
Estimated noise standard deviation of the GPR model, returned as a scalar value.
Data Types: double
This property is read-only.
Parameters used for training the GPR model, returned as a GPParams
object.
Kernel Function
This property is read-only.
Form of the covariance function used in the GPR model, returned as a character vector containing the name of the built-in covariance function or a function handle. It can be one of the following.
| Function | Description |
|---|---|
'squaredexponential' | Squared exponential kernel. |
'matern32' | Matern kernel with parameter 3/2. |
'matern52' | Matern kernel with parameter 5/2. |
'ardsquaredexponential' | Squared exponential kernel with a separate length scale per predictor. |
'ardmatern32' | Matern kernel with parameter 3/2 and a separate length scale per predictor. |
'ardmatern52' | Matern kernel with parameter 5/2 and a separate length scale per predictor. |
| Function handle | A function handle that fitrgp can call like
this:Kmn = kfcn(Xm,Xn,theta)
where Xm is an
m-by-d matrix,
Xn is an
n-by-d matrix, and
Kmn is an
m-by-n matrix of kernel
products such that
Kmn(i,j) is
the kernel product between Xm(i,:)
and Xn(j,:). d
is the number of predictor variables after the software creates dummy
variables for the categorical variables. For details about creating
dummy variables, see CategoricalPredictors.
theta is the
r-by-1 unconstrained parameter vector for
kfcn. |
Data Types: char | function_handle
This property is read-only.
Information about the parameters of the kernel function used in the GPR model, returned as a structure with the following fields.
| Field Name | Description |
|---|---|
Name | Name of the kernel function. This option corresponds to the
KernelFunction property. |
KernelParameters | Vector of the estimated kernel parameters. For more information, see
the KernelParameters name-value argument of
fitrgp. |
KernelParameterNames | Names associated with the elements of the
KernelParameters field of
KernelInformation. When the GPR model uses an
ARD kernel, the length scale parameters listed in
KernelParameterNames correspond to the predictors
listed in the ExpandedPredictorNames
property. |
Data Types: struct
Prediction
This property is read-only.
Method that predict uses to make predictions from
the GPR model, returned as a character vector. It can be one of the following.
PredictMethod | Description |
|---|---|
'exact' | Exact Gaussian process regression |
'bcd' | Block Coordinate Descent |
'sd' | Subset of Data points approximation |
'sr' | Subset of Regressors approximation |
'fic' | Fully Independent Conditional approximation |
This property is read-only.
Weights used to make predictions from the trained GPR model, returned as a numeric
vector. predict computes the predictions for a new
predictor matrix Xnew by
using the product
is the matrix of kernel products between and active set vector A and α is a vector of weights.
Data Types: double
Transformation applied to the predicted response, returned as a character vector describing
how the response values predicted by the model are transformed. In RegressionGP, ResponseTransform is
'none' by default, and RegressionGP does not use ResponseTransform when
making predictions.
Active Set Selection
This property is read-only.
Subset of training data used to make predictions from the GPR model, returned as a matrix.
predict computes the predictions for a new predictor
matrix Xnew by
using the product
is the matrix of kernel products between and active set vector A and α is a vector of weights.
ActiveSetVectors is equal to the training data
X for exact GPR fitting and a subset of the training data
X for sparse GPR methods. When there are categorical predictors
in the model, ActiveSetVectors contains dummy variables for the
corresponding predictors.
Data Types: double
This property is read-only.
Method used to select the active set for sparse methods
('sd','sr', or 'fic'),
returned as a character vector. It can be one of the following.
ActiveSetMethod | Description |
|---|---|
'sgma' | Sparse greedy matrix approximation |
'entropy' | Differential entropy-based selection |
'likelihood' | Subset of regressors log likelihood-based selection |
'random' | Random selection |
The selected active set is used in parameter estimation or prediction,
depending on the choice of FitMethod and PredictMethod in
fitrgp.
This property is read-only.
Size of the active set for sparse methods
('sd','sr', or 'fic'),
returned as an integer value.
Data Types: double
Training Data
This property is read-only.
Predictor variable names, returned as a cell array of character vectors. The order of the elements of PredictorNames corresponds to the order in which the predictor names appear in the training data.
Data Types: cell
This property is read-only.
Expanded predictor names, returned as a cell array of character vectors. If the model uses encoding for categorical variables, then ExpandedPredictorNames includes the names that describe the expanded variables. Otherwise, ExpandedPredictorNames is the same as PredictorNames.
Data Types: cell
This property is read-only.
Response variable name, returned as a character vector.
Data Types: char
This property is read-only.
Means of predictors used for training the GPR model if the training data is standardized, returned as a 1-by-d vector. If the training data is not standardized, PredictorLocation is empty.
If PredictorLocation is not empty, then the predict method centers the predictor values by subtracting the respective element of PredictorLocation from every column of X.
If there are categorical predictors, then PredictorLocation includes a 0 for each dummy variable corresponding to those predictors. The dummy variables are not centered or scaled.
Data Types: double
This property is read-only.
Standard deviations of predictors used for training the GPR model if the training data is standardized, returned as a 1-by-d vector. If the training data is not standardized, PredictorScale is empty.
If PredictorScale is not empty, the predict method scales the predictors by dividing every column of X by the respective element of PredictorScale (after centering using PredictorLocation).
If there are categorical predictors, then PredictorLocation includes a 1 for each dummy variable corresponding to those predictors. The dummy variables are not centered or scaled.
Data Types: double
Object Functions
gather | Gather properties of Statistics and Machine Learning Toolbox object from GPU |
lime | Local interpretable model-agnostic explanations (LIME) |
loss | Regression error for Gaussian process regression model |
partialDependence | Compute partial dependence |
plotPartialDependence | Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots |
predict | Predict response of Gaussian process regression model |
shapley | Shapley values |
Examples
Generate example training data.
rng(1) % For reproducibility
n = 100000;
X = linspace(0,1,n)';
X = [X,X.^2];
y = 1 + X*[1;2] + sin(20*X*[1;-2]) + 0.2*randn(n,1);Train a GPR model using the subset of regressors ("sr") approximation method and predict using the subset of data ("sd") method. Use 50 points in the active set and sparse greedy matrix approximation ("sgma") method for active set selection. Because the scales of the first and second predictors are different, it is good practice to standardize the data.
gprMdl = fitrgp(X,y,KernelFunction="squaredExponential", ... FitMethod="sr",PredictMethod="sd",Basis="none",ActiveSetSize=50, ... ActiveSetMethod="sgma",Standardize=1,KernelParameters=[1;1]);
fitrgp accepts any combination of fitting, prediction, and active set selection methods. In some cases it might not be possible to compute the standard deviations of the predicted responses, hence the prediction intervals. See Tips. And, in some cases, using the exact method might be expensive because of the size of the training data.
Create a compact GPR object.
cgprMdl = compact(gprMdl);
Generate the test data.
n = 4000; Xnew = linspace(0,1,n)'; Xnew = [Xnew,Xnew.^2]; ynew = 1 + Xnew*[1;2] + sin(20*Xnew*[1;-2]) + 0.2*randn(n,1);
Use the compact object to predict the response in test data and the prediction intervals.
[ypred,~,yci] = predict(cgprMdl,Xnew);
Plot the true response, predicted response, and prediction intervals.
figure plot(ynew,Color="#D95319") hold on plot(ypred,Color="#0072BD") plot(yci(:,1),"k--") plot(yci(:,2),"k--") legend("True responses","GPR predictions","95% prediction limits", ... Location="best") xlabel("x") ylabel("y") hold off

Compute the mean squared error loss on the test data using the trained GPR model.
L = loss(cgprMdl,Xnew,ynew)
L = 0.0497
Extended Capabilities
Usage notes and limitations:
The
predictfunction supports code generation.
For more information, see Introduction to Code Generation for Statistics and Machine Learning Functions.
Usage notes and limitations:
The following object functions fully support GPU arrays:
The object functions execute on a GPU if at least one of the following applies:
The model was fitted with GPU arrays.
The predictor data that you pass to the object function is a GPU array.
The response data that you pass to the object function is a GPU array.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2015bYou can fit a CompactRegressionGP object with GPU arrays by using
fitrgp to fit a RegressionGP object to gpuArray data, and then
passing the object to compact. Most CompactRegressionGP object functions support GPU
array input arguments so that the functions can execute on a GPU. The object
functions that do not support GPU array inputs are lime
and shapley.
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)