Clear Filters
Clear Filters

How to train a GPR model using 'fitrgp' with multiple input sequences?

17 views (last 30 days)
I'd like to train a gpr model using multiple input sequences. In dynamic neural networks there is an option to use 'catsamples' to avoid appending time sequences together. Is there an equivalent way to do this for a GPR model?
Reference on using catsamples for dynamic neural networks:

Answers (1)

Pratyush Swain
Pratyush Swain on 27 Nov 2023
Hi Katy,
I understand you want to train a gpr model using multiple input sequences.When training a gpr model with multiple input sequences, we can directly use a matrix or a table to represent our input data,where each row of the matrix or table corresponds to a different input sequence.
If the input sequences have varying sizes, please follow the given workflow to combine the matrices into a table:
% Sample input matrices
matrix1 = rand(5, 3);
matrix2 = rand(4, 4);
matrix3 = rand(6, 2);
%Sample output matrices
o1 = rand(5,1);
o2 = rand(4,1);
o3 = rand(6,1);
% Combine all input matrices into a cell array
allMatrices = {matrix1, matrix2, matrix3};
% Combine all output matrices into a cell array
outputMatrices = {o1,o2,o3};
% Find the maximum number of columns among all matrices
maxCols = max(cellfun(@(x) size(x, 2), allMatrices));
% Please note cellfun applies function to each content(matrix) in a cell
% array
% Pad each matrix with NaN values to make them all have the same number of columns
paddedMatrices = cellfun(@(x) [x, nan(size(x, 1), maxCols - size(x, 2))], allMatrices, 'UniformOutput', false);
% Observe the sizes of matrices now after operation.
disp(paddedMatrices)
{5×4 double} {4×4 double} {6×4 double}
% Convert the padded matrices into a table
combinedTable = vertcat(paddedMatrices{:});
% Assign variable names to the columns
tableVariableNames = strcat("Col_", arrayfun(@num2str, 1:maxCols, 'UniformOutput', false));
% Conversion into table
combinedTable = array2table(combinedTable, 'VariableNames', tableVariableNames);
% Finally apply 'fitrgp' function
model = fitrgp(combinedTable,vertcat(outputMatrices{:}))
model =
RegressionGP PredictorNames: {'Col_1' 'Col_2' 'Col_3' 'Col_4'} ResponseName: 'Y' CategoricalPredictors: [] ResponseTransform: 'none' NumObservations: 15 KernelFunction: 'SquaredExponential' KernelInformation: [1×1 struct] BasisFunction: 'Constant' Beta: 0.4974 Sigma: 0.0023 PredictorLocation: [] PredictorScale: [] Alpha: [4×1 double] ActiveSetVectors: [4×4 double] PredictMethod: 'Exact' ActiveSetSize: 4 FitMethod: 'Exact' ActiveSetMethod: 'Random' IsActiveSetVector: [4×1 logical] LogLikelihood: 1.9480 ActiveSetHistory: [] BCDInformation: []
For more information please refer to the following:
Hope this helps.

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!