genetic algorithm polynomial fitting

5 ビュー (過去 30 日間)
Eugenio Caredda
Eugenio Caredda 2022 年 1 月 5 日
回答済み: Hari 2024 年 4 月 2 日
I am trying to use the gapolyfitn to my data from a simulation of a servovalve's behavior.
The simulation stops after 1st generation, and I'm not very sure if I'm using the function right. I have 3 sets of data, that stands for spool position, differential pressure and flow. I want to represent pressure in function of the other two, so I placed my data in indepvar and the pressure data in depvar.
I'm using the example script in the function folder, that uses the function to fit the function sin(5xy) with the following code
indepvar = randMat([0.00001; 0.00001], [0.99999; 0.99999], [0; 0], 1000);
depvar= sin(5 .* indepvar(:,1) .* indepvar(:,2));
[polymodel, Best, IndAll] = gapolyfitn(indepvar, depvar, maxTerms, maxPower, options);
So as far as I understand it, randMat is creating a matrix 1000x2 as fake experimental data (so as points where the code will evaluate the function 5xy). So i tried to substitute randMat with my spool position and flow values from simulink simulation of the servovalve, and then to substitute the pressure data in the depvar variable as follow:
indepvar = [simout_xs simout_q];
depvar = simout_p12;
But then I get the problem where it will only do one generation. I still got the polynomial coefficient though, so I write a function to multiply them with different flow and spool position
for ll=1:5
var(1)=simout_q(ll);
for tt=1:length(simout_xs)
var(2)=simout_xs(tt);
for ii=1:13
iterm(ii)=polymodel.Coefficients(ii)*var(1)^polymodel.ModelTerms(ii,1)*var(2)^polymodel.ModelTerms(ii,2);
end
for ii=1:13
item(tt,ll)=item(tt,ll)+iterm(ii);
item(tt,ll)=-item(tt,ll);
end
end
figure(ll)
item1=item(:,ll);
plot(item1,indepvar)
end
and I though this should have tried to wrote the pressure graph of the new data, but instead is trying to represent spool position of new data, so I'm kinda confused if I'm doing things right or not

回答 (1 件)

Hari
Hari 2024 年 4 月 2 日
Hi Eugenio Caredda,
I understand that you are using the "gapolyfitn" function for polynomial fitting of simulation data from a servovalve's behavior, aiming to model pressure as a function of spool position and flow. You are facing the issue that simulation stops after the first generation.
I assume that your data ("simout_xs" for spool position, "simout_q" for flow, and "simout_p12" for differential pressure) is correctly formatted and ready for analysis.
To troubleshoot the issue you are facing you can consider the following steps:
  1. Algorithm Configuration: The stopping after the first generation might be due to the configuration of the options parameter in "gapolyfitn". Check the "options" for parameters like "PopulationSize", "MaxGenerations", causing the algorithm to stop prematurely.
  2. Result Interpretation and Visualization: After fitting, when you try to visualize the results, ensure you're plotting the dependent variable (pressure) against the predicted values correctly. Your loop for calculating item seems to aim at recreating the pressure values, but the plot command might be inverted. It should likely be "plot(indepvar, item1)" to match the independent variables with the calculated pressure values.
  3. Data Preparation: Ensure your independent variables (indepvar) and dependent variable (depvar) are correctly assigned. Your approach seems correct by setting "indepvar = [simout_xs simout_q]" and "depvar = simout_p12". This step is crucial for the algorithm to understand the relationship you're trying to model.
References for further assistance:
Hope this helps!

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by