- The input to the fitness needs to be a single variable
- MATLAB does not allow for arrays of function handles
Optimisation application: how do I create the fitness function?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Howard Clapp
el 10 de Ag. de 2015
Comentada: Howard Clapp
el 20 de Ag. de 2015
I have two functions: EndCarb and EndCost.
These functions use inputs of: ID [1 2] and Q [0.000001:0.000001:0.01], and give an output of carbon quantity and cost respectively. (EndCarb [ID,Q]; EndCost[ID,Q])
I want to use the gamultiobj tool to optimise the inputs of ID and Q to give the pareto optimal cost and carbon. So far I have been attempting to write a script along the lines of:
fun(1) = @(ID,Q) EndCost(ID,Q);
%parameterised function
Q=0.000001:0.000001:0.01;
%parameter
fun1a=@(ID) fun(1)(ID,Q);
%function of ID alone
ID=[1,2];
fun(2) = @(ID,Q) EndCarbon(ID,Q);
%parameterised function
Q=0.000001:0.000001:0.01;
%parameter
fun2a=@(ID) fun(2)(ID,Q);
%function of ID alone
ID=[1,2];
% Combine two objectives 'fun1' and 'fun2'
fun1and2 = @(ID,Q) [fun(1)(ID,Q) fun(2)(ID,Q)];
I'm not sure if this is the right track, as I am unable to get it to work. Can anybody advise anything?
0 comentarios
Respuesta aceptada
Adam Barber
el 12 de Ag. de 2015
Hey Howard,
It looks like you are on the right track to defining your fitness function for "gamultiobj". I think the issues you are running into is that:
You can resolve the first issue by following the example at: http://www.mathworks.com/help/gads/computing-objective-functions.html
The example function there has 3 values, but only accepts one input argument
function z = my_fun(x)
z = zeros(1,3); % allocate output
z(1) = x(1)^2 - 2*x(1)*x(2) + 6*x(1) + 4*x(2)^2 - 3*x(2);
z(2) = x(1)*x(2) + cos(3*x(2)/(2+x(1)));
z(3) = tanh(x(1) + x(2));
You will need to do something similar where you combine "ID" and "Q" into a single variable that you pass to your objective function.
For the second issue, you can either use a cell array to define your function handles:
fun{1} = @(ID,Q) EndCost(ID,Q);
fun{2} = @(ID,Q) EndCarbon(ID,Q);
or just store them as separate variables.
Now, you can define your fitness function as something like the following:
fun1and2 = @(X) [fun{1}(X(1:2),X(3:end)) fun{2}(X(1:2),X(3:end))]; % ID and Q are "stacked" into X
Hope this helps get you on your way, and if this does not help then post the error(s) that you are seeing.
-Adam
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!