Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fill the blanks: % Only valid for one input, one output and Nn neurons in the hidden layer clearvars clc addpath('../Basic_blocks') % Main parameters

Please fill the blanks:

% Only valid for one input, one output and Nn neurons in the hidden layer clearvars clc addpath('../Basic_blocks')

% Main parameters mu=.01; % Step size Ns=100000; % Number of samples Nh=2; % Number of neurons hidden layer Ni=1; % Number of inputs No=1; % Number of outputs in=3;

% Defining the input and the desired signals x=(rand(1,Ns)-.5)*4; d=1+sin(in*pi/4*x);

% Defining the variables (weights and bias) W1=zeros(Nh,Ni,Ns+1); % Weights hidden layer W2=zeros(No,Nh,Ns+1); % Weights output layer W1(:,:,1)=rand(Nh,Ni); % Initialization W2(:,:,1)=rand(No,Nh); % Initialization b1=zeros(Nh,Ns+1); % Bias hidden layer b1(:,1)=(rand(Nh,1)-.5)*4; % Iitialization b2=zeros(No,Ns+1); % Bias output layer b2(:,1)=(rand(No,1)-.5)*4; % Initialization tipo='linear'; % Output nonlinearity error=zeros(1,Ns); % Error signal

% Loop along the samples including the forward and backward steps for k=1:Ns y0=[x(k)]; [y1 y2 v1 v2]=forward(W1(:,:,k),W2(:,:,k),b1(:,k),b2(:,k),y0,tipo); e(k)=d(k)-y2; [delta2 delta1]=backward(W2(:,:,k),y1,y2,e(k),tipo); W2(:,:,k+1)=W2(:,:,k)+2*mu*delta2*y1'; b2(k+1)=b2(k)+mu*2*delta2; W1(:,:,k+1)=W1(:,:,k)+mu*2*delta1*y0; b1(:,k+1)=b1(:,k)+mu*2*delta1; end

% How to present results test=-2:.02:2; reg=zeros(size(test)); for k=1:length(test) [y1 reg(k) v1 v2]=forward(W1(:,:,Ns),W2(:,:,Ns),b1(:,Ns),b2(Ns),test(k),'linear'); end plot(test,1+sin(in*pi/4*test),'r'),hold plot(test,reg,'--b'),hold off grid title('Error: q=1,Nh=2')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Discuss five types of employee training.

Answered: 1 week ago

Question

Identify the four federally mandated employee benefits.

Answered: 1 week ago