gapolyfitn genetic algorithm function

1 次查看(过去 30 天)
I am trying to use the gapolyfitn function with data from a servovalve's simulink model. This is a sample script of the function used to fit a function, that uses the variables from indepvar and depvar (while my data are in the variables my_indepvar and my_depvar). My data, stored in the simout_* variables, represents differential pressure, flow and position of the spool of the servovalve, are time-based and are stored in the same way of the input of the example script (indepvar and depvar, respectively 1001x2 double and 1001x1double). Their values are in this range:
simout_xs -0.0016 , 0.0060
simout_q -3.04e-05 , 1.9e-04
simout_p12 -3.83e+06 , 1.72e+07
When I try to use my_deepvar with the indepvar data from the example script the genetic algorithm works, so it's able to fit the pressure data from simulink, but when I try to use my_indepvar the algorithm stops at the 1st generation, giving the warning "Duplicate data points have been detected and removed - corresponding values have been averaged".
%% gapolyfitn example script
%
% This script demonstrates the use of gapolyfitn to fit to the function
% sin(5xy) using 15 terms up to order 7
%
% Author: Richard Crozier
% Release Date: 06 OCT 2009
%
indepvar = randMat([0.00001; 0.00001], [0.99999; 0.99999], [0; 0], 1001);
my_indepvar = [simout_xs simout_q];
% get the function values
depvar = sin(5 .* indepvar(:,1) .* indepvar(:,2));
my_depvar = simout_p12;
% Choose 15 possible terms
maxTerms = 15;
% Choose a maximum possible power of 15
maxPower = 7;
% Print some output and progress information
options.VERBOSE = 1;
% Max number of generations set to 250
options.MAXGEN = 250;
options.DOSAVE = 0;
options.SAVEFILE = [cd '\testsav.mat'];
% options.LOADFILE = [cd '\testsav.mat'];
% multicore options, may actually slow things down for small polys,
% requires multicore package of functions
% options.MCORE = true;
% options.MCOREDIR = 'C:\';
% perform the polynomial fit using the GA
[polymodel, Best, IndAll] = gapolyfitn(indepvar, depvar, maxTerms, maxPower, options);
% plot the original function and the polynomial
figure;
[XI,YI] = meshgrid(0.00001:(0.9999-0.00001)/100:0.9999, 0.00001:(0.9999-0.00001)/100:0.9999);
[XI,YI,ZI] = griddata(indepvar(:,1),indepvar(:,2),depvar, XI, YI);
mesh(XI,YI,ZI)
hold on
[XI,YI,ZI] = griddata(indepvar(:,1),indepvar(:,2),polyvaln(polymodel,indepvar), XI, YI);
mesh(XI,YI,ZI)
hold off
% Generate model using all possible terms for comparison
alltmspolymodel = polyfitn(indepvar, depvar, maxPower)

回答(1 个)

ag
ag 2024-1-4
Hi Eugenio,
I understand that you are facing the warning message "Duplicate data points have been detected and removed - corresponding values have been averaged", while using the "gapolyfitn" function with the "my_indepvar" data.
The warning suggests that in your dataset "my_indepvar", there are rows with identical values. Removing duplicates and training the model on a clean and representative dataset, helps improve the accuracy on new, unseen data.
There are 3 ways to address this issue,
  • Remove duplicates- you can use "unique" to remove rows with identical values for both "x" and "y" columns, as shown below.
uIndepvar = unique(indepvar, 'rows');
  • Introduce randomness- you can randomly increase or decrease the corresponding values, to get rid of duplicates, as shown below.
rIndepvar = indepvar + randn(size(indepvar))/10000;
  • Average duplicates- this is automatically done by the fitting algorithm if duplicates are present in the data(as suggested by the warning).
For more details, please refer to the following MATLAB documentations:
Hope this helps!
Best Regards,
Aryan Gupta

产品

Community Treasure Hunt

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

Start Hunting!

Translated by