Problem with HDL code generation of Regression Ensemble Predict block using Simulink and HDL coder
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I am trying to compare the performance of ANN vs Gradient boost algorithm to predict response.
I am using RegressionEnsemble Predict block for response prediction using Gradient boost in Simulink. I have a dataset called engine_dataset, which i have split into training data and test data. My simulink model reads input from workspace in timeseries and two RegressionEnsemble Predict blocks. the difference between actual response and predicted response is used to find regression. The simulink model is attached. The code I used for the model preparation and training is as follows:
% Load the engine_dataset
load engine_dataset
% Prepare the data
X = engineInputs.';
Y= engineTargets.';
% Split the data into training and testing sets
cv = cvpartition(size(X,1),'HoldOut',0.2);
Xtrain = X(cv.training,:);
Ytrain = Y(cv.training,:);
Xtest = X(cv.test,:);
Ytest = Y(cv.test,:);
% Train the Gradient Boosting model
Model1 = fitrensemble(Xtrain,Ytrain(:,1),'Method','LSBoost','NumLearningCycles',500,'Learners',templateTree('MaxNumSplits',10));
Model2 = fitrensemble(Xtrain,Ytrain(:,2),'Method','LSBoost','NumLearningCycles',500,'Learners',templateTree('MaxNumSplits',10));
Then I created a timeseries inputfor input and expected output:
sampleTime = 1;
numSteps = 1199;
time = sampleTime*(0:numSteps-1);
time = time';
simin = timeseries(X,time);
simout = timeseries(Y,time);
Then I created the attached Simulink Model and opened it from script:
model = 'Ensemblepredict_sml_model';
system_under_design = [model '/Gradient Boost Predict Model'];
baseline_output = [model '/yarr'];
open_system(model);
Then I did hdl set up and other optimizations. For this I referred this link:
hdlsetup(model);
loggingInfo = get_param(model, 'DataLoggingOverride');
sim_out = sim(model, 'SaveFormat', 'Dataset');
plotRegression(sim_out, baseline_output, system_under_design, 'Regression before conversion');
opts = fxpOptimizationOptions();
opts.addTolerance(system_under_design, 1, 'RelTol', 0.05);
opts.addTolerance(system_under_design, 1, 'AbsTol', 50)
opts.AllowableWordLengths = 8:32;
solution = fxpopt(model, system_under_design, opts);
best_solution = solution.explore;
At this point, there was a data type mismatch error, which was removed after I checked the 'Lock output data type against changes by the fixed-point tools'.
Then I proceeded with the steps as in Convert Neural Network Algorithms to Fixed-Point Using fxpopt and Generate HDL Code after making some changes like avoiding activation function.
set_param(model, 'DataLoggingOverride', loggingInfo);
Simulink.sdi.markSignalForStreaming([model '/yarr'], 1, 'on');
Simulink.sdi.markSignalForStreaming([model '/diff'], 1, 'on');
sim_out = sim(model, 'SaveFormat', 'Dataset');
plotRegression(sim_out, baseline_output, system_under_design, 'Regression after conversion');
systemname = 'Ensemblepredict_sml_model/Gradient Boost Predict Model';
workingdir = 'C:/Temp/hdlsrc';
checkhdl(systemname,'TargetDirectory',workingdir,'TargetLanguage','Verilog');
makehdl(systemname,'TargetDirectory',workingdir,'TargetLanguage','Verilog');
makehdltb(systemname,'TargetDirectory',workingdir,'TargetLanguage','Verilog');
The code exits by giving error report, with 24 errors.
The problem seems to be the presence of Data Store Read/Write block which are present inside the ensemble predict simulink block.
Can anyone suggest how to replace Data Store blocks? Are there any alternative ways to approach this problem?
Neeraja
0 comentarios
Respuestas (1)
Hamid Satarboroujeni
el 14 de Dic. de 2023
You can replace the Data Store Memory (DSM) blocks with a single Unit Delay block and wire it up as shown below:
You can then delete all DSM blocks inside and outside the For-Iterator Subsystem. I haven't tested this but it should work for HDL code generation.
I hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre Classification Ensembles en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!