FunctionApproximation

FunctionApproximation - V=V + (eta*delta_y(1:n,1)*[x(i)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
% % Mini Project1 Part2 function [Ea,epoch,EtestAve,EaEpoch,d] = FunctionApproximation(nn,data_N,et) tic %clear all n=nn; % # of neurons in the hidden layer V1=rand(n,2); V2=-rand(n,2); V=V1+V2; W1=rand(1,n+1); W2=-rand(1,n+1); W=W1+W2; y=zeros(n,1); % y(11,1)=-1; o=0; E=0; Ea = 1; N=data_N; eta=et; epoch=0; E=0; epoch=epoch+1; for i=1:8*N+1 x(i)=-pi+.25*pi*(i-1)/N; %inputs to the network d(i)=cos(x(i))*cos(2*x(i)); %Desired outputs y(:,1)=bivariateexp(V*([x(i) -1]')); %1 st layer's outputs are evaluated o(i)=bivariateexp(W*([y' -1]')); %2 nd layer's input is evaluated %% step 3 error evaluation E=E + .5*((d(i)-o(i))^2) ; for k=1:n fy(k,1)=.5*(1-y(k,1)^2); if (k==n) fy(n+1,1)=0; end end %step 4 Calculating errors delta_o = .5*((d(i)-o(i))*(1-o(i)^2)); for nrn=1:n delta_y(nrn,1) = W(1,nrn)*delta_o*.5*fy(nrn,1); end %W %fy(:,1) %step 5 adjusting weights of output layer W=W + eta*delta_o*[y' -1]; %delta_y %V %step 6 adjusting weights of hidden layer
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: V=V + (eta*delta_y(1:n,1)*[x(i) -1]); end Ea=E/(8*N+1);EaEpoch(1,epoch)=Ea; end % m=1:8*N; it is not needed i guess. hold on subplot(2,2,1:2),plot(EaEpoch),title('Average Error Vs # of Iterations') xlabel('Number of iterations'), ylabel('Ea : Average Error') subplot(2,2,3:4), plot(x,d,'r'),title('Outputs Vs inputs') xlabel('input pattern values'), ylabel('Network Outputs') hold on subplot(2,2,3:4), plot(x,o,'b--'); epoch Ea % test set ytest=zeros(n,1); Etest=0; E for i=1:8*N xtest(i)=(x(i)+x(i+1))/2; dtest(i)=cos(xtest(i))*cos(2*xtest(i)); %Desired outputs end e for i=1:8*N ytest(:,1)=bivariateexp(V*([xtest(i) -1]')); otest(i)=bivariateexp(W*([ytest' -1]')); Etest=Etest + .5*((dtest(i)-otest(i))^2) ; end %plot(d,'r--') it is on the line 61. so no need. hold on subplot(2,2,3:4), plot(xtest,otest,'g:') ; %title('the plot'); legend('desired outputs','training data outputs','test data outputs') EtestAve=Etest/(8*N) toc %%...
View Full Document

This note was uploaded on 07/13/2011 for the course ECE 501 taught by Professor Deniz during the Spring '11 term at Istanbul Universitesi.

Page1 / 2

FunctionApproximation - V=V + (eta*delta_y(1:n,1)*[x(i)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online