How to train a GPR model using 'fitrgp' with multiple input sequences?
7 views (last 30 days)
Show older comments
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:
0 Comments
Answers (1)
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)
% 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{:}))
For more information please refer to the following:
Hope this helps.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!