daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Feb 12th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clear;
  2. clc;
  3.  
  4. epochs=100;
  5. learning_rate=0.1;
  6. hidden_nodes=80;
  7. place=linspace(0,2*pi,hidden_nodes);
  8. var=0.07;
  9.  
  10. %training and test sets
  11. x=(0:0.01:2*pi);
  12. test_set=(0.05:0.01:6.33);
  13.  
  14. %gaussian noise
  15. variance=0.6;
  16. noise=sqrt(variance).*randn(1,length(x));
  17.  
  18. %Target sets
  19. t1=sin(2*x)+noise;
  20. t2=square(2*x)+noise;
  21.  
  22. weight_matrix=rand(hidden_nodes,1);
  23. first_weight=weight_matrix;
  24. for i=1:epochs
  25.     for j=1:length(x)
  26.    
  27.         %plot the output of hidden nodes
  28.         for k=1:length(place)
  29.         y(k,:)=rbf(test_set(k),place(k),var);
  30.         %plot(y(k,:))
  31.         phi=y';
  32.         end
  33.        
  34.         out=phi*weight_matrix;
  35.         error=t1(j)-out;
  36.         delta=learning_rate * error * y;
  37.         %delta
  38.         weight_matrix=weight_matrix+delta;
  39.     end
  40.         permute = randperm(length(x));
  41.         % Permute data
  42.         x = x(:, permute);
  43. end        
  44.    
  45.     %results
  46.     for i=1:length(place)
  47.         a(k,:)=rbf(x,place(k),var);
  48.         %plot(y(k,:))
  49.         phi=a';
  50.     end
  51.    
  52.         out1=phi*first_weight;
  53.         out2=phi*weight_matrix;
  54.         plot(t1,'g')
  55.         hold on
  56.         plot(out1','r')
  57.         hold on
  58.         plot(out2,'b')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top