MATLAB Answers

trying to use a neural network in a genetic optimiser

1 view (last 30 days)
luke haworth
luke haworth on 27 Mar 2021
hi, i have created a neural net using 6 inputs and one output, its for a project to optermize intake length and valve timings for an engine
i am happy that the network is working as i intended but i dont know how to generate a function from the network and then use this funtion in the genetic algorithm optimizer, any help would be appieciated
here is my code for the network
filename3 = 'data for network.xlsx';
%x1 = rpm
x1 = xlsread(filename3,'C4:AGW4');
%x2 = length
x2 = xlsread(filename3,'C5:AGW5');
%x3 = IVO timing
x3 = xlsread(filename3,'C6:AGW6');
%x4 = IVC timing
x4 = xlsread(filename3,'C7:AGW7');
%x5 = EVO timing
x5 = xlsread(filename3,'C8:AGW8');
%x6 = EVC timing
x6 = xlsread(filename3,'C9:AGW9');
%x = {x1;x2;x3;x4;x5;x6};
x25 = [x1;x2;x3;x4;x5;x6];
%y1 = hp
y1 = xlsread(filename3,'C10:AGW10');
net_hp = feedforwardnet(10);
net_hp = configure(net_hp,x25,y1);
net_hp = init(net_hp);
[net_hp,tr] = train(net_hp,x25,y1);

Answers (1)

Abdolkarim Mohammadi-Balani
If I have understood you well, you want ga() to train your feedforward ANN. If so, you can read about it here:
  3 Comments
Abdolkarim Mohammadi-Balani
I think you have a surrogate model, that is, you have trained a network that gets inputs and returns the horsepower. If so, your job is very easy. Just put the network inside a function
function ObjectiveFunctionValue = ObjectiveFunction (x, net)
ObjectiveFunctionValue = net (x);
end
and pass it as the objective function to ga() or anything else. For example:
fun = @ (x) ObjectiveFunction (x, net);
nvars = % number of decision variables (inputs of the network)
[x, fval] = ga (fun, nvars);
Read more in ga() documentation.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!