Error generating code to implement RegressionGP Model using MATLAB Function in Simulink (The input to coder.const cannot be reduced to a constant: Unsupported value.)
5 views (last 30 days)
Show older comments
Michelle Geilenberg on 4 Aug 2020
Commented: Michelle Geilenberg on 6 Dec 2020
A strange problem occurs to me trying to integrate my trained RegressionGP in a Simulink Model using a MATLAB Function block, saveLearnerForCoder and loadLearnerForCoder.
I trained two GPs with the same size of predictors which is 75. I use the same script for training and optimization. The only difference are the measurements used for training. I use sequences of 25 datapoints from three sensors each.
The first GP works flawlessly in a matlab skript ans also in Simulink using a MATLAB Function block. The second GP works without problem in a MATLAB script. When I try to complie the same Simulink model with the second GP (change name of file in loadLearnerForCoder) I get the following error:
The input to coder.const cannot be reduced to a constant: Unsupported value. Function 'loadLearnerForCoder.m' (#76.1874.1895), line 41, column 68: "matFile.compactStruct" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'MATLAB Function2' (#55.201.239), line 10, column 7: "loadLearnerForCoder('gprMdl_V106_LUT')" Launch diagnostic report.
This is the function I use in both cases:
function [prediction, upperConf, lowerConf] = gpr_predict_V101(X) %#codegen
% Copyright 2019 The MathWorks, Inc.
prediction = 0.0;
confidence = [ 0.0 0.0 ];
upperConf = 0.0;
lowerConf = 0.0;
mdl = loadLearnerForCoder('gprMdl_V101_LUT');
[prediction, ~, confidence] = predict(mdl,X);
upperConf = confidence(:,1);
lowerConf = confidence(:,2);
The input data is preprocess the same way for both GPs and therefore has the same size. I checked all dimensions and compared the compacStruct created for both GP through saveLearnerForCoder and couldn't finde any difference besides the GP hyperparameters and ActiveSet used.
Does anyone know where else this error could come from?
Thanks in advance!
Denis Gurchenkov on 4 Aug 2020
Hi Michelle, there is nothing wrong with your code, the issue looks like a bug in the product. Can you please contact MathWorks technical support, just tell the support person to route the ticket to MATLAB Coder team (this is where I work). If you are able to provide your (failing) model to the technical support, we should be able to reproduce the issue in-house and figure out what is going on and hopefully provide you with some workaround.
More Answers (1)
Sriram Padavettan on 4 Dec 2020
Not sure if you figured it out yet, but are you using 2020A?
I had same issue and messed with it all day until I decided to try a different version and it worked - try 2020B.
Find more on Gaussian Process Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!