variableIndices variable in global optimization toolbox GA

4 Ansichten (letzte 30 Tage)
Petar
Petar am 18 Nov. 2014
Kommentiert: Alan Weiss am 20 Nov. 2014
Hi !
I have a question about a variable from global optimization toolbox genetic algorithm subroutine.
I am attempting to minimize a fitness function (RMSEP - Relative Mean Square Error of Prediction from Partial Least Squares) by selecting optimal subsets of my initial dataset, with a maximum of 6 variables in a subset. Basically I want to perform GA-PLS with the global optimization toolbox.
My fitness function gets processed normally, and it has as an output a single scalar, rmsep value.
However, in order to select the variables for the subset, naturally, I would think I have to use the variableIndices which are output of the GA. However, whichever creation function I use, the results are always in decimal form (e.g. 20.250...) and thus unusable for selection of subsets. I can use round(variableIndices), however I think that is not the solution.
My fitness function is:
function rmsep = gafit1(variableIndices,...
x_train,y_train,x_test,y_test)
% variableIndices=round(variableIndices)
y1=y_train;
x1=x_train;
[~,~,~,~,b] = plsregress(x1(:,variableIndices),y1,2);
y2=y_test;
x2=x_test(:,variableIndices);
yhat = [ones(size(x2,1),1) x2]*b;
rmsep=gafit0(y2,yhat)*100;
plot(y2,yhat,'.');
end
gafit0 is a routine which calculates rmsep.
Please help !!!
Best regards,
Petar

Antworten (1)

Alan Weiss
Alan Weiss am 18 Nov. 2014
Use mixed-integer optimization along with the constraint that no more than 6 variables can exist, a linear constraint of the form
A*x <= 6
where x is a binary vector of the variables in the problem and A is a row vector of ones. If you have more variables than just the binary ones, put zeros in the corresponding columns of A for those variables.
Alan Weiss
MATLAB mathematical toolbox documentation
  6 Kommentare
Petar
Petar am 20 Nov. 2014
Bearbeitet: Petar am 20 Nov. 2014
It seems that a constraint function needs to be coded. I shall study through the documentation on how to do so, and attempt to do it according to your suggestion.
However, will this now allow for use of different selection/crossover/mutation functions ?
Could my constraint function be something like this?
function [c,ceq] = gaconstraint(x)
% Preload y
global y
% Number of selected variables
numSelVariables=size(x,2);
for i = 1:numSelVariables
if x(i) > 0
% y=1 if x is positive
y(i)=true;
elseif x(i) < 0;
% y=0 if x is negative
y(i)=false;
else
end
end
% Three inequalities: y(i) <= x(i), x(i) <= numSelVariables*y(i), and
% sum(y(i)) <= 6
c = [y(i)-x(i); x(i)-numSelVariables*y(i); sum(y(i))-6];
% No linear equalities
ceq = [];
end
y is input from ga and is a row vector with six variables. Right?
Also how could my fitness function be modified to use with Particle Swarm Optimization Toolbox which requires a function handle and doesn't accept a variable of type 'cell'. The 'cell' variable in which I pass the function handle to GA is:
F={@gafit1,x_train,y_train,x_test,y_test};
Moreover, even if I manage to call it by loading the original matrices within the function file, and have only one input variable, now I face the same problem as with GA, and I don't seem to see the option to define integer variable indices for PSO.
Alan Weiss
Alan Weiss am 20 Nov. 2014
Once more I urge you to read in its entirety the first section I linked you to on mixed integer optimization. Please read it before asking any more questions. In particular, it states that you cannot have custom mutation or crossover functions. Yes, it is a pain and boring to read the documentation. But this particular documentation is quite relevant to what you are trying to do.
Also, do NOT use nonlinear constraints for the x and y variables, use LINEAR inequality constraints.
Alan Weiss
MATLAB mathematical toolbox documentation

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by