Feed Forward Neural Network with Genetic Algorithm
Problem definition and training data selection Z = f(x,y) = x*y x and y varied from 0 to 1 in intervals of 0.01 0<=x<=1 z = f(x,y) will have 100x100 grid 0<=y<=1 points 100 points randomly chosen for x and y each This gives z = f(x,y) as 100 points for training
Neural Network S tructure 2 inputs – x and y 14 edges, each associated with a weight 2 hidden layers y1 = g(w(1)*x + w(2)*y) 3 neurons in first hidden layer y2 = g(w(3)*x + w(4)*y) 2 neurons in second hidden layer y3 = g(w(5)*x + w(6)*y) 1 output – z = f(x,y) z1 = g(w(7)*y1 + w(8)*y2 + w(9)*y3) z2 = g(w(10)*y1 + w(11)*y2 + w(12)*y3) output = g(w(14)*z1 + w(14)*z2) Here, g is chosen to be a sigmoid function This neural network encoded in compute_neural.m
Encoding the chromosomes for GA -6.35<=weight<=6.4 14 edges in the network => 14 weights (-6.35,6.4) = (-127/ 20,128/ 20) 14 binary arrays needed for the -127 to 128 -> 255 values neural network 8 bit binary representation A 14x8 matrix created to represent 128 added to each weight, so that all the weights in the network all are non zero, and then the Every such 14x8 matrix represents binary equivalent is filled in an 8 a chromosome for the GA bit array Functionality captured by decimal_to_binary.m and binary_to_decimal.m
GA Formulation Random init ial populat ion generat ed by Crossover using round(rand(14,8,41)) Randomly choose indices for the fitness proportionate selection array 41 is t he populat ion size Corresponding indices are the indices Every 14x8 mat rix is a chromosome for 2 parents Fit ness funct ion Randomly choose columns from each and exchange For a given chromosome and x and y, compute the rms error for (actually Mut at ion taken max error in this case) randi(1,100) < 10 (10% probability) Fit ness proport ionat e select ion A slight modificat ion is made for bet t er An array generated with indices of the convergence, best of each generat ion is chromosomes; lower the error, more kept in every new generat ion indices of that chromosome Capt ure in generat e_offspring.m Consider [0.1 0.4 0.3 0.2] The array A generated is similar to [1 2 2 2 2 3 3 3 4 4]
Graphic visualization 0 1 0 0 1 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 1 0 0 0 0 1 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 0 0 1 1 0 0 1 1 0 1 0 0 0 1 1 0 0
Neural Network fitted values, error
Possible manipulations Population size (41) Range of weights (-6.35 to 6.4) Number of neurons (3,2) Number of hidden layers (2) Resolution of weights (1/ 20) Number of iterations of GA (200) S election of fitness function (max(errors)) (conservative) S election of activation function (sigmoid)
Recommend
More recommend