Advertisement
cheungtifan

Untitled

Apr 25th, 2012
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. % I use this code to obtain the time of detecting the attacks against z3,
  2. % using the nonparametric cusum algorithm
  3. clear;
  4. clc;
  5. max_iter = 1000;
  6. taoval = 1:3:400; %taoval means \tau, which is the threshold
  7.  
  8. iter1 = [];iter2 = [];iter3 = [];
  9. for itao = 1:length(taoval)
  10. tao = taoval(itao);
  11. Si1 = 0;Si_1 = 0;
  12. for i = 1:max_iter-1
  13. Si1 = Si_1+0.01*abs(randn(1));
  14. if(i>100)
  15. Si1 = Si1+0.5*94.20; %94.20 is the \gamma?percentiles of z3, which is derived from historical data. 0.5 means the true value is changed by 50%
  16. end
  17.  
  18. if(Si1>tao)
  19. iter_tmp1 = i;
  20. break;
  21. end
  22. Si_1 = Si1;
  23. end
  24. iter1 = [iter1,iter_tmp1-100];
  25. Si2=0; Si_1 = 0;
  26. for i = 1:max_iter-1
  27. Si2 = Si_1+0.01*abs(randn(1));
  28.  
  29. if(i>100)
  30. Si2 = Si2+0.3*94.20; %0.3 means the true value is changed by 30%
  31. end
  32. if(Si2>tao)
  33. iter_tmp2 = i;
  34. break;
  35. end
  36. Si_1 = Si2;
  37. end
  38. iter2 = [iter2,iter_tmp2-100];
  39. Si3=0; Si_1 = 0;
  40. for i = 1:max_iter-1
  41. Si3 = Si_1+0.01*abs(randn(1));
  42.  
  43. if(i>100)
  44. Si3 = Si3+0.1*94.20; %0.1 means the true value is changed by 10%
  45. end
  46. if(Si3>tao)
  47. iter_tmp3 = i;
  48. break;
  49. end
  50. Si_1 = Si3;
  51. end
  52. iter3 = [iter3,iter_tmp3-100];
  53. end
  54. figure(1);clf;
  55. plot(taoval,iter1,'r--','linewidth',2);hold on;
  56. plot(taoval,iter2,'g-.','linewidth',2);hold on;
  57. plot(taoval,iter3,'b-','linewidth',2);hold off;
  58. xlabel('\tau');ylabel('Average Detection Time(s)');
  59. LEGEND('z_{a}=0.5*z','z_{a}=0.7*z','z_{a}=0.9*z','Location','northwest');
  60. title('z_{3}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement