how can I optimize a neural network with multiple outputs using the Genetic Algorithm ?

Hello,
I have trained a neural network using the Neural net fitting app, my neural network have 3 inputs and 4 outputs. I want to optimize the neural network using the Genetic Algorithm but the problem is whenever I use the optimization app and include the following script I always get an error telling me that my neural network has several outputs and that the app only takes one output at a time to be able to give me the optimal conditions. ( For more info I am trying to optimize my neural network so that it gives me the optimal conditions to maximize my 4 outputs at the same time). Is there a way can change the script so that it can work with 4 outputs or is it impossible to do with the Genetic algorithm.
function y = fonc(x)
saveVarsMat = load(EA.mat');
net = saveVarsMat.net;
y = -(net(x'));

Réponses (1)

Generally speaking, optimization algorithms try to minimize a single scalar function of the input variables x. I don't know what your neural network is outputting that you are trying to "optimize," where I put that word in quotes because I am not sure that you are trying to minimize something.
Sometimes people want to minimize a difference between an output vector fonc(x) and a known vector known. In that case, the usual objective function is the sum of squares of differences:
f = sum((fonc(x) - known).^2);
Alan Weiss
MATLAB mathematical toolbox documentation

4 commentaires

Thank you so much for you answer sir.
The thing is I am trying to maximize 4 outputs ( my outputs are concentrations of 4 different molécules) and my 3 inputs are 3 different factors that influence on the concentration of those molecules. what I am trying to do is to have the optimal conditions (aka optimal factors/inputs) that help me get the optimal maximum concentration on all 4 outputs at the same time.
PS: maximize here is the same as minimize as I would just take the function and ad a negative sign in it to have the max.
Is it actually possible to do that ?
Unless you are extremely lucky, it is impossible to get all four outputs maximized individually at the exact same combinations of factors. Generally, the factor combination that maximizes one output differs from the factor combination that maximizes another output. To see, you can try to maximize one output at a time and see what the factor combinations are that maximize each output. As I said at first, you'd have to be very lucky to have all outputs maximized at the same point.
So what can you do? You have a few choices.
  • Look at the tradeoffs between the various factors. This is called multiobjective optimization (where you want to optimize several objectives simultaneously). See Multiobjective Optimization.
  • Combine your objectives in a way that makes sense for you. Do you want to maximize the sum of the outputs? That is a single objective that you can maximize. Want to maximize the smallest objective? That, too, is a single objective, and there is a solver called fminimax for just that purpose.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Excuse me sir but my previous explanation might have been confusing. In other words I am tryin to have the optimal conditions (optimal inputs) to have the highest value either in all 4 outputs (best case scenario) or at least to have the highest value for most of the outputs. And by highest value it does not necessarily mean that it will be 100% which means I can for exemple have optimal conditions that give me like 90%, 80%,87%,40% for all four outputs respectively but it will be the optimal conditions to maximize the totality of the outputs as a whole.
As I said before, you can look at the multiobjective solution (using gamultiobj or paretosearch) and choose the best tradeoff point on the Pareto front, where "best" means whatever you think is best. Or you can come up with a single scalar function that is "the totality of the outputs as a whole." I don't know what you mean by that, but if you can come up with a scalar mathematical expression then optimize that.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Connectez-vous pour commenter.

Produits

Version

R2021a

Commenté :

le 15 Nov 2022

Community Treasure Hunt

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

Start Hunting!

Translated by