NN_GWO gives 0 values for weights

조회 수: 2 (최근 30일)
Sarmed Wahab
Sarmed Wahab 2022년 10월 31일
I have combined the Gre wolf optimizer with neural network to make a hybrid model to optimize Mean Square error for my research.
However my GWO code gives 0 values for all weights.
I have looked into code for hours but I am unable to find my mistake. If someone can spare some time it will be really helpful.
I am attaching the code below.
clear all
clc
load ("slab.mat")
input_val = slab(:,1:6);
output_val = slab(:,7);
nm_input = [];
% Normalizing the data
for i=1:6
%the normalized values are correct, I have checked.
nm_input(:,i) = (input_val(:,i) - min(input_val(:,i))) / (max(input_val(:,i)) - min(input_val(:,i)));
end
X = nm_input;
nm_output = (output_val(:,1) - min(output_val(:,1))) / (max(output_val(:,1)) - min(output_val(:,1)));
Y = nm_output;
sz = (ceil(size(X,1))*0.75);
sz = round(sz);
% inputs for the neural net
inputs = X';
% targets for the neural net
targets = Y';
% number of neurons
n = 4;
% create a neural network
net_fnn = feedforwardnet(n);
% configure the neural network for this dataset
% net_nn = configure(net_nn, inputs, targets);
net_fnn = train(net_fnn, inputs, targets);
% get the normal NN weights and bias
getwb(net_fnn)
% error MSE normal NN
error_fnn = targets - net_fnn(inputs);
calc = mean(error_fnn.^2)/mean(var(targets',1));
output_fnn = net_fnn(inputs);
% defining the parameters
fobj = @(x) NMSE(x, net_fnn, inputs, targets);
dim = size(inputs,1)*n+n+n+1;
% Max_iteration =
% SearchAgents_no = number of search agents
lb = 1;
ub = -1;
SearchAgents_no=3; % Number of search agents
%Function_name='F10'; % Name of the test function that can be from F1 to F23 (Table 1,2,3 in the paper)
Max_iteration=3; % Maximum numbef of iterations
% Load details of the selected benchmark function
%[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
[Best_score,Best_pos,GWO_cg_curve]=GWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
net_GWO = setwb(net_fnn, Best_pos'); %This lines contains the error
% get the GWO optimized NN weights and bias
getwb(net_GWO)
% error MSE GWO optimized NN
error_GWO = targets - net_GWO(inputs);
calc = mean(error_GWO.^2)/mean(var(targets',1));
output_GWO = net_GWO(inputs);
outputs = [targets; output_GWO; output_fnn]';
disp("error_GWO , error_nn ")
errors = [error_GWO; error_fnn]'
predictions = [output_GWO', output_fnn', nm_output];
% biases and weights
wb_GWO = getwb(net_GWO);
wb_fnn = getwb(net_fnn);
wb_total = [wb_GWO, wb_fnn];
%plots
figure;
plot(nm_output,'LineWidth',2, 'Marker','diamond', 'MarkerSize',8)
hold on;
plot(output_fnn, 'LineWidth',2, 'Marker','x', 'MarkerSize',8);
plot(output_GWO, 'LineWidth',2, 'Marker','pentagram', 'MarkerSize',8);
title('GWO Optimization based Feed-Forward Neural Network');
xlabel('Time Interval');
ylabel('Values');
legend('Actual Values', 'FNN Predictions', 'GWo-FNN Predictions');
hold off;
the code works without any error but the problem is that the weights are all zero so the bias value is returned as the ouput for prediction.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Approximation and Clustering에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by