Facebook
From jaja, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 111
  1. function y=f1(x)
  2.         y=sum(x.^2)
  3. endfunction
  4.  
  5. PopSize=100;
  6. Proba_cross=0.7;
  7. Proba_mut=0.1;
  8. NbGen=5;
  9. Log =%T;
  10. ga_params =init_param();
  11. ga_params = add_param(ga_params,"dimension",2);
  12. ga_params = add_param(ga_params,"minbound",[-100;-100]);
  13. ga_params= add_param(ga_params,"maxbound",[100;100]);
  14.  
  15.  
  16. PlotNumber=1;
  17. errors=[];
  18. popSizes=[];
  19. i=1;
  20. N=30;
  21. MaxNEval=500;
  22. for PopSize =10:1:50
  23. ANbGen =MaxNEval/PopSize;
  24. errors(i)=0;
  25. for n=1:N
  26. [pop_opt, fobj_pop_opt] = ..
  27.     optim_ga(f1,PopSize,ANbGen,Proba_mut,Proba_cross,Log,ga_params);
  28.    errors(i)=errors(i)+fobj_pop_opt(1);
  29. end
  30. popSizes(i)=PopSize;
  31. errors(1)=errors(i)/N;
  32. i=i+1;
  33. end
  34. plot(popSizes,log(errors));
  35. /
  36. /
  37. /
  38. /
  39. /
  40. /
  41. /
  42. /
  43. /
  44. /
  45. /
  46. /
  47. /
  48. /
  49. /
  50. /
  51. /
  52. /
  53. /
  54. /
  55. /
  56. function y=f1(x)
  57.         y=sum(x.^2)
  58. endfunction
  59.  
  60. PopSize=26;
  61. Proba_cross=0.7;
  62. Proba_mut=0.07;
  63. NbGen=5;
  64. Log =%T;
  65. ga_params =init_param();
  66. ga_params = add_param(ga_params,"dimension",2);
  67. ga_params = add_param(ga_params,"minbound",[-100;-100]);
  68. ga_params= add_param(ga_params,"maxbound",[100;100]);
  69.  
  70.  
  71. PlotNumber=1;
  72. errors=[];
  73. probacross=[];
  74. i=1;
  75. N=30;
  76. MaxNEval=500;
  77. for Proba_cross =0.3:0.1:0.9
  78. ANbGen =MaxNEval/PopSize;
  79. errors(i)=0;
  80. for n=1:N
  81. [pop_opt, fobj_pop_opt] = ..
  82.     optim_ga(f1,PopSize,ANbGen,Proba_mut,Proba_cross,Log,ga_params);
  83.    errors(i)=errors(i)+fobj_pop_opt(1);
  84. end
  85. probacross(i)=Proba_cross;
  86. errors(1)=errors(i)/N;
  87. i=i+1;
  88. end
  89. plot(probacross,log(errors));
  90. /
  91. /
  92. /
  93. /
  94. /
  95. /
  96. /
  97. /
  98. /
  99. /
  100. /
  101. /
  102. /
  103. /
  104. /
  105. /
  106. /
  107. /
  108. /
  109. /
  110. /
  111. function y=f1(x)
  112.         y=sum(x.^2)
  113. endfunction
  114.  
  115. PopSize=100;
  116. Proba_cross=0.7;
  117. Proba_mut=0.1;
  118. NbGen=5;
  119. Log =%T;
  120. ga_params =init_param();
  121. ga_params = add_param(ga_params,"dimension",2);
  122. ga_params = add_param(ga_params,"minbound",[-100;-100]);
  123. ga_params= add_param(ga_params,"maxbound",[100;100]);
  124.  
  125.  
  126. PlotNumber=1;
  127. errors=[];
  128. popSizes=[];
  129. i=1;
  130. N=30;
  131. MaxNEval=500;
  132. for PopSize =10:1:50
  133. ANbGen =MaxNEval/PopSize;
  134. errors(i)=0;
  135. for n=1:N
  136. [pop_opt, fobj_pop_opt] = ..
  137.     optim_ga(f1,PopSize,ANbGen,Proba_mut,Proba_cross,Log,ga_params);
  138.    errors(i)=errors(i)+fobj_pop_opt(1);
  139. end
  140. popSizes(i)=PopSize;
  141. errors(1)=errors(i)/N;
  142. i=i+1;
  143. end
  144. plot(popSizes,log(errors));
  145. /
  146. /
  147. /
  148. /
  149. /
  150. /
  151. /
  152. /
  153. /
  154. /
  155. /
  156. /
  157. /
  158. /
  159. /
  160. /
  161. /
  162. /
  163. /
  164. /
  165. /
  166. /
  167. /
  168. /
  169. /
  170. function y=f1(x)
  171.         y=sum(x.^2)
  172. endfunction
  173.  
  174. PopSize=32;
  175. Proba_cross=0.7;
  176. Proba_mut=0.1;
  177. NbGen=5;
  178. Log =%T;
  179. ga_params =init_param();
  180. ga_params = add_param(ga_params,"dimension",2);
  181. ga_params = add_param(ga_params,"minbound",[-100;-100]);
  182. ga_params= add_param(ga_params,"maxbound",[100;100]);
  183.  
  184.  
  185. PlotNumber=1;
  186. errors=[];
  187. popSizes=[];
  188. i=1;
  189. N=30;
  190. MaxNEval=500;
  191. for PopSize =10:1:50
  192. ANbGen =MaxNEval/PopSize;
  193. errors(i)=0;
  194. for n=1:N
  195. [pop_opt, fobj_pop_opt] = ..
  196.     optim_ga(f1,PopSize,ANbGen,Proba_mut,Proba_cross,Log,ga_params);
  197.    errors(i)=errors(i)+fobj_pop_opt(1);
  198. end
  199. popSizes(i)=PopSize;
  200. errors(1)=errors(i)/N;
  201. i=i+1;
  202. end
  203. plot(popSizes,log(errors));
  204.