# Performance in backpropagation algorithm

Filed under:
|
|
##### backpropagation

I've written a matlab program for standard backpropagation algorithm, it is my homework and I should not use matlab toolbox, so I write the entire code by myself. This link helped me for backpropagation algorithm. I have a data set of 40 random number and initial weights randomly. As output, I want to see a diagram that shows the performance. I used mse and plot function to see performance for 20 epochs but the result is this: I heard that performance should go up through backpropagation, so I want to know is there any problem with my code or this result is normal because local minimums.

This is my code:

Hidden_node=inputdlg('Enter the number of Hidden nodes'); a=0.5;%initialize learning rate hiddenn=str2num(Hidden_node{1,1});

randn('seed',0);

%creating data set

s=2;

N=10;

m=[5 -5 5 5;-5 -5 5 -5];

S = s*eye(2);

[l,c] = size(m);

x = []; % Creating the training set

for i = 1:c

x = [x mvnrnd(m(:,i)',S,N)'];

end

% target value

toutput=[ones(1,N) zeros(1,N) ones(1,N) zeros(1,N)];

for epoch=1:20; %number of epochs

for kk=1:40; %number of patterns

%initial weights of hidden layer

for ii=1 : 2;

``````for jj=1 :hiddenn;

whidden{ii,jj}=rand(1);

end
``````

end

initial the wights of output layer

for ii=1 : hiddenn;

``````    woutput{ii,1}=rand(1);
``````

end

for ii=1:hiddenn;

x1=x(1,kk);

x2=x(2,kk);

w1=whidden{1,ii};

w2=whidden{2,ii};

activation{1,ii}=(x1(1,1)*w1(1,1))+(x2(1,1)*w2(1,1));

end

%calculate output of hidden nodes

for ii=1:hiddenn;

hidden_to_out{1,ii}=logsig(activation{1,ii});

end

``````activation_O{1,1}=0;

for jj=1:hiddenn;

activation_O{1,1} = activation_O{1,1}+(hidden_to_out{1,jj}*woutput{jj,1});

end
``````

%calculate output

out{1,1}=logsig(activation_O{1,1});

out_for_plot(1,kk)= out{1,ii};

%calculate error for output node

delta_out{1,1}=(toutput(1,kk)-out{1,1});

%update weight of output node

for ii=1:hiddenn; woutput{ii,jj}=woutput{ii,jj}+delta_out{1,jj}*hidden_to_out{1,ii}*dlogsig(activation_O{1,jj},logsig(activation_O{1,jj}))*a;

end

%calculate error of hidden nodes

for ii=1:hiddenn;

``````delta_hidden{1,ii}=woutput{ii,1}*delta_out{1,1};
``````

end

%update weight of hidden nodes

for ii=1:hiddenn;

``````for jj=1:2;

whidden{jj,ii}= whidden{jj,ii}+(delta_hidden{1,ii}*dlogsig(activation{1,ii},logsig(activation{1,ii}))*x(jj,kk)*a);

end
``````

end

``````   a=a/(1.1);%decrease learning rate
``````

end

%calculate performance

e=toutput(1,kk)-out_for_plot(1,1);

perf(1,epoch)=mse(e);

end

plot(perf);

Thanks a lot.

© Stack Overflow or respective owner

### Related posts about algorithm

• #### Jpeg Algorithm vs BMP Algorithm?

as seen on Super User - Search for 'Super User'
I'm just wonder, what the differences are between creating a BMP file algorithm and JPG file algorithm ? If you know the others images' format algorithm, please post them. Thanks. >>> More

• #### word disambiguation algorithm (Lesk algorithm)

as seen on Stack Overflow - Search for 'Stack Overflow'
Hii.. Can anybody help me to find an algorithm in Java code to find synonyms of a search word based on the context and I want to implement the algorithm with WordNet database. For example, "I am running a Java program". From the context, I want to find the synonyms for the word "running", but the… >>> More

• #### Search algorithm (with a sort algorithm already implemented)

as seen on Stack Overflow - Search for 'Stack Overflow'
Hello, Im doing a Java application and Im facing some doubts in which concerns performance. I have a PriorityQueue which guarantees me the element removed is the one with greater priority. That PriorityQueue has instances of class Event (which implements Comparable interface). Each Event is associated… >>> More

• #### Is there any algorithm for finding LINES by PIXEL COLORS on picture?

as seen on Stack Overflow - Search for 'Stack Overflow'
So I have Image like this I want to get something like this (I hevent drawn all lines I want but I hope you can get my idea) I need algorithm for finding all straight lines on it by just reading colors of pixels. No hard math, no Haar, no Hough. Some algorithm which would be based on points… >>> More

• #### collsion issues with quadtree [on hold]

as seen on Game Development - Search for 'Game Development'
So i implemented a Quad tree in Java for my 2D game and everything works fine except for when i run my collision detection algorithm, which checks if a object has hit another object and which side it hit.My problem is 80% of the time the collision algorithm works but sometimes the objects just go… >>> More

### Related posts about matlab

• #### Importing matlab functions in matlab

as seen on Stack Overflow - Search for 'Stack Overflow'
Hi, I have some Matlab functions defined in .m files and I'd like to import them into Matlab (as in I'd like them to form part of the commands). Is this possible please and how can I do this? Thank you very much and regards, Krt_Malta >>> More

• #### c# with matlab dll should be running on pc without matlab

as seen on Stack Overflow - Search for 'Stack Overflow'
hi, i have a very big problem. ich wrote a programm which is using a matlab dll. i build some classes with the matlab .net builder. it runs on my pc :) the problem is, i want to use ist on a pc without matlab. so i installed mcr, but it dont run :( what are the steps i should do? the system variable… >>> More

• #### Matlab and .NET Interaction

as seen on Stack Overflow - Search for 'Stack Overflow'
Hi All! I'm having an issue interacting between Matlab and .NET. I've managed to call .NET methods from Matlab code and vice versa. However, if I call a .NET method that, in turn, instantiates a Matlab object, it crashes (with a type initialization exception). Think about this scenario: a .NET… >>> More

• #### Matlab matrix replacement assignment gives error

as seen on Stack Overflow - Search for 'Stack Overflow'
Hello, when i tried to update some part of a matrix, i got the following error message: ??? Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts My code tries to update some values of a matrix that represent a binary image. My code is as follows: outImage(3:5,2:4,1) =… >>> More

• #### MATLAB matrix replacement assignment gives error

as seen on Stack Overflow - Search for 'Stack Overflow'
I tried to update some part of a matrix, I got the following error message: ??? Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts My code tries to update some values of a matrix that represent a binary image. My code is as follows: outImage(3:5,2:4,1) = max(imBinary(3:5… >>> More