Problems while using GA tool
Afficher commentaires plus anciens
Im tried to ANN model using NN tool, below is the main code. How can i use this algorithm for GA. Actually im using it as fitness function and experienceing Your fitness function must return a scalar value. Can anyone help me to solve this problem
function [y1] = myNeuralNetworkFunction(x1)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Auto-generated by MATLAB, 19-Jun-2023 14:54:07.
%
% [y1] = myNeuralNetworkFunction(x1) takes these arguments:
% x = 3xQ matrix, input #1
% and returns:
% y = 1xQ matrix, output #1
% where Q is the number of samples.
%#ok<*RPMT0>
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1.xoffset = [100;1;71];
x1_step1.gain = [0.02;1;0.142857142857143];
x1_step1.ymin = -1;
% Layer 1
b1 = [-0.30737283352153921268;1.322612692426588854;0.58129519002642282555;1.4748592960276967201;2.0944333345187930995];
IW1_1 = [-1.5086427375102904325 -3.038961833301901283 1.4863499450687009951;-0.64162409885264004572 2.4285095642721183928 -0.14727698235538747018;0.0041660806219078940632 0.8907322179363926784 0.4739010872904309557;0.24439012000049564755 -1.6457877135168710314 0.33951958182712982381;0.089546823753675119928 1.3460500881462804657 3.3283147583294683258];
% Layer 2
b2 = -0.70337339938547793761;
LW2_1 = [0.21092763030859110196 -0.71992817515568152675 1.4753500640686965095 0.70510771700780461302 -0.19667447384695707635];
% Output 1
y1_step1.ymin = -1;
y1_step1.gain = 0.0342465753424658;
y1_step1.xoffset = 35.6;
% ===== SIMULATION ========
% Dimensions
Q = size(x1,2); % samples
% Input 1
xp1 = mapminmax_apply(x1,x1_step1);
% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*xp1);
% Layer 2
a2 = repmat(b2,1,Q) + LW2_1*a1;
% Output 1
y1 = mapminmax_reverse(a2,y1_step1);
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end
% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end
% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end
1 commentaire
Aniketh
le 6 Juil 2023
Based on my understanding, you could potentially modify the provided neural network function to work as a fitness function in a genetic algorithm (GA). Here's a suggestion on how you might approach it:
Consider modifying the function signature of myNeuralNetworkFunction to accept a population matrix instead of a single input:
function y1 = myNeuralNetworkFunction(x)
In this case, x would be a matrix with dimensions NxM, where N represents the number of variables (genes) and M denotes the population size.
Adjust the code inside the function to handle the population of solutions. You may need to iterate over each solution in the population and perform the neural network simulation for each one.
Réponses (0)
Catégories
En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!