Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear;
- clc;
- epochs=100;
- learning_rate=0.1;
- hidden_nodes=80;
- place=linspace(0,2*pi,hidden_nodes);
- var=0.07;
- %training and test sets
- x=(0:0.01:2*pi);
- test_set=(0.05:0.01:6.33);
- %gaussian noise
- variance=0.6;
- noise=sqrt(variance).*randn(1,length(x));
- %Target sets
- t1=sin(2*x)+noise;
- t2=square(2*x)+noise;
- weight_matrix=rand(hidden_nodes,1);
- first_weight=weight_matrix;
- for i=1:epochs
- for j=1:length(x)
- %plot the output of hidden nodes
- for k=1:length(place)
- y(k,:)=rbf(test_set(k),place(k),var);
- %plot(y(k,:))
- phi=y';
- end
- out=phi*weight_matrix;
- error=t1(j)-out;
- delta=learning_rate * error * y;
- %delta
- weight_matrix=weight_matrix+delta;
- end
- permute = randperm(length(x));
- % Permute data
- x = x(:, permute);
- end
- %results
- for i=1:length(place)
- a(k,:)=rbf(x,place(k),var);
- %plot(y(k,:))
- phi=a';
- end
- out1=phi*first_weight;
- out2=phi*weight_matrix;
- plot(t1,'g')
- hold on
- plot(out1','r')
- hold on
- plot(out2,'b')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement