Trouble import my trained ANN model as fitness function in GA.
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I am new to matlab code.
I have trained an ANN model for a fuel cell performance prediction, and I want to use this trained model as my fitness function in GA to find maximum power output.
Specification for my ANN model: Inputs: temperature, anode humidity, cathode humidity,voltage (4 inputs). Output: Current density(1 output)
Here, I have several questions regarding with fitness functin in GA:
- My output for this ANN model is a 1XQ (Q is number of sample) row vector. when I try to use GA, the error appears that "Your fitness function must return a scalar value." Is there any solution to deal with this issue. I have tried to vectorize my fitness function. I tried to vectorize my fitness function, but failed.
clear all
close all
clc
load net
x_New = csvread('Curve_Test_Input.csv');
x1 = x_New';
input_para = x1;
voltage = input_para(4,:);
objFcn = @(x1) -sim(net,x1').*voltage;
power = objFcn(x1');
%[xOpt fVal] = ga(objFcn,4)
2. I tried to vectorize my fitness function, and set lower and upper bound for my inputs parameters. But the error appears that "Matrix dimensions must agree."
However, when I comment my last line of code :
%[xOpt fVal] = ga(objFcn,nVars,A,b,Aeq,beq,lb,ub,nonlcon,options)
My program can run without problem. Therefore, I guess something must wrong when I import ANN model into GA as fitness function.
clear all
close all
clc
load net
x_New = csvread('Curve_Test_Input.csv');
x1 = x_New';
input_para = x1;
voltage = input_para(4,:);
objFcn = @(x1) -sim(net,x1').*voltage;
power = objFcn(x1');
options = optimoptions('ga','UseVectorized',true);
A = [];
b= [];
Aeq = [];
beq = [];
lb = [313,0.25,0.25,0.3];
ub = [333,0.9,0.9,0.9];
nVars = 4;
nonlcon = [];
[xOpt fVal] = ga(objFcn,nVars,A,b,Aeq,beq,lb,ub,nonlcon,options)
Could you give me some suggestions for how to import an ANN model with input of [4XQ] and output of [1XQ] matrix, into GA as my fitness function?
A screenshot of my workspace varaibles is also included.

Thank you very much~
댓글 수: 0
채택된 답변
Walter Roberson
2020년 5월 18일
when I try to use GA, the error appears that "Your fitness function must return a scalar value." Is there any solution to deal with this issue.
No, there is no solution. ga() is only ever suitable for optimizing one function at a time. You are trying to optimize one function per sample.
If you had information about the relative importance of the output of each sample, then you might be able to create a scalar weighted optiization measure, perhaps.
For example, suppose that you can increase the output for sample 17 by 0.2 by lowering the output for sample 23 by 0.1 . Is that worth doing? How does it compare to increasing the output for sample 17 by sqrt(2)/10 by lowering the output for sample 23 by sqrt(2)/10 ?
When you have multiple outputs and no weighting function, then the best you can do is use gamultiobj() to find pareto fronts.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!