Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.46 KB | None | 0 0
  1.  
  2.  
  3. using System;
  4. using System.Drawing;
  5. using System.Collections;
  6. using System.ComponentModel;
  7. using System.Windows.Forms;
  8. using System.Data;
  9. using System.Threading;
  10. using System.IO;
  11.  
  12. using AForge;
  13. using AForge.Neuro;
  14. using AForge.Neuro.Learning;
  15. using AForge.Controls;
  16.  
  17. namespace XORProblem
  18. {
  19.  
  20. public class MainForm : System.Windows.Forms.Form
  21. {
  22. double[,] tabErreur = null;
  23. private IContainer components;
  24. private double learningRate = 0.1;
  25. private double momentum = 0.0;
  26. private double sigmoidAlphaValue = 1.0;
  27. private double learningErrorLimit = 0.1;
  28.  
  29. private bool saveStatisticsToFiles = false;
  30. private bool saveValidationToFiles = false;
  31. private int nbiteration = 200;
  32. private Thread workerThread = null;
  33. private bool needToStop = false;
  34. private Label label1;
  35. private TextBox learningRateBox;
  36. private Label label2;
  37. private TextBox alphaBox;
  38. private Label label3;
  39. private TextBox errorLimitBox;
  40. private Button startButton;
  41. private Label label6;
  42. private TextBox momentumBox;
  43. private GroupBox groupBox2;
  44. private Label label14;
  45. private Label label13;
  46. private CheckBox saveFilesError;
  47. private Chart errorChart;
  48. private Label label4;
  49. private TextBox nbiterations;
  50. private GroupBox groupBox5;
  51. private Label label18;
  52. private Label label17;
  53. private Chart errcroisechart;
  54. private Button button1;
  55. private Panel panel2;
  56. private Label label5;
  57. private Panel panel3;
  58. private GroupBox groupBox3;
  59. private GroupBox groupBox4;
  60. private Label label20;
  61. private Label label19;
  62. private Chart outputchart;
  63. private Label label16;
  64. private Label label15;
  65. private Chart validationChart;
  66. private Label label7;
  67. private GroupBox groupBox1;
  68. private GroupBox groupBox6;
  69. private Label label12;
  70. private Panel panel7;
  71. private Label label11;
  72. private Panel panel6;
  73. private Label label10;
  74. private Panel panel5;
  75. private Label label9;
  76. private Panel panel4;
  77. private Label label8;
  78. private Panel panel1;
  79. private Button button3;
  80. private CheckBox saveFileErrorValidation;
  81. public System.Windows.Forms.Timer timer1;
  82.  
  83.  
  84.  
  85. // Constructeur
  86. public MainForm()
  87. {
  88.  
  89. InitializeComponent();
  90.  
  91. UpdateSettings();
  92.  
  93. // initialiser les charts
  94. errorChart.AddDataSeries("error", Color.Red, Chart.SeriesType.Line, 3);
  95. validationChart.AddDataSeries("validation", Color.Magenta, Chart.SeriesType.Line, 3);
  96. outputchart.AddDataSeries("sortieDesi", Color.Green, Chart.SeriesType.Line, 3);
  97. outputchart.AddDataSeries("sortieRNS", Color.CornflowerBlue, Chart.SeriesType.Line, 3);
  98. outputchart.AddDataSeries("sortieRNSv", Color.Orange, Chart.SeriesType.Line, 3);
  99. errcroisechart.AddDataSeries("SORTIER", Color.CornflowerBlue, Chart.SeriesType.Line, 2);
  100. errcroisechart.AddDataSeries("SORTIED", Color.Green, Chart.SeriesType.Line, 2);
  101.  
  102. }
  103.  
  104. /// <summary>
  105. /// Clean up any resources being used.
  106. /// </summary>
  107. protected override void Dispose(bool disposing)
  108. {
  109. if (disposing)
  110. {
  111. if (components != null)
  112. {
  113. components.Dispose();
  114. }
  115. }
  116. base.Dispose(disposing);
  117. }
  118.  
  119. #region Windows Form Designer generated code
  120. /// <summary>
  121. /// Required method for Designer support - do not modify
  122. /// the contents of this method with the code editor.
  123. /// </summary>
  124. private void InitializeComponent()
  125. {
  126. this.components = new System.ComponentModel.Container();
  127. this.timer1 = new System.Windows.Forms.Timer(this.components);
  128. this.groupBox1 = new System.Windows.Forms.GroupBox();
  129. this.button3 = new System.Windows.Forms.Button();
  130. this.groupBox6 = new System.Windows.Forms.GroupBox();
  131. this.label12 = new System.Windows.Forms.Label();
  132. this.panel7 = new System.Windows.Forms.Panel();
  133. this.label11 = new System.Windows.Forms.Label();
  134. this.panel6 = new System.Windows.Forms.Panel();
  135. this.label10 = new System.Windows.Forms.Label();
  136. this.panel5 = new System.Windows.Forms.Panel();
  137. this.label9 = new System.Windows.Forms.Label();
  138. this.panel4 = new System.Windows.Forms.Panel();
  139. this.label8 = new System.Windows.Forms.Label();
  140. this.panel1 = new System.Windows.Forms.Panel();
  141. this.groupBox4 = new System.Windows.Forms.GroupBox();
  142. this.label20 = new System.Windows.Forms.Label();
  143. this.label19 = new System.Windows.Forms.Label();
  144. this.outputchart = new AForge.Controls.Chart();
  145. this.label7 = new System.Windows.Forms.Label();
  146. this.groupBox3 = new System.Windows.Forms.GroupBox();
  147. this.label16 = new System.Windows.Forms.Label();
  148. this.label15 = new System.Windows.Forms.Label();
  149. this.validationChart = new AForge.Controls.Chart();
  150. this.panel3 = new System.Windows.Forms.Panel();
  151. this.label5 = new System.Windows.Forms.Label();
  152. this.panel2 = new System.Windows.Forms.Panel();
  153. this.button1 = new System.Windows.Forms.Button();
  154. this.groupBox5 = new System.Windows.Forms.GroupBox();
  155. this.label18 = new System.Windows.Forms.Label();
  156. this.label17 = new System.Windows.Forms.Label();
  157. this.errcroisechart = new AForge.Controls.Chart();
  158. this.nbiterations = new System.Windows.Forms.TextBox();
  159. this.label4 = new System.Windows.Forms.Label();
  160. this.groupBox2 = new System.Windows.Forms.GroupBox();
  161. this.label14 = new System.Windows.Forms.Label();
  162. this.label13 = new System.Windows.Forms.Label();
  163. this.saveFilesError = new System.Windows.Forms.CheckBox();
  164. this.errorChart = new AForge.Controls.Chart();
  165. this.momentumBox = new System.Windows.Forms.TextBox();
  166. this.label6 = new System.Windows.Forms.Label();
  167. this.startButton = new System.Windows.Forms.Button();
  168. this.errorLimitBox = new System.Windows.Forms.TextBox();
  169. this.label3 = new System.Windows.Forms.Label();
  170. this.alphaBox = new System.Windows.Forms.TextBox();
  171. this.label2 = new System.Windows.Forms.Label();
  172. this.learningRateBox = new System.Windows.Forms.TextBox();
  173. this.label1 = new System.Windows.Forms.Label();
  174. this.saveFileErrorValidation = new System.Windows.Forms.CheckBox();
  175. this.groupBox1.SuspendLayout();
  176. this.groupBox6.SuspendLayout();
  177. this.groupBox4.SuspendLayout();
  178. this.groupBox3.SuspendLayout();
  179. this.groupBox5.SuspendLayout();
  180. this.groupBox2.SuspendLayout();
  181. this.SuspendLayout();
  182. //
  183. // timer1
  184. //
  185. this.timer1.Interval = 1;
  186. //
  187. // groupBox1
  188. //
  189. this.groupBox1.BackgroundImage = global::SinusProblem.Properties.Resources.decampement_40_720px;
  190. this.groupBox1.Controls.Add(this.button3);
  191. this.groupBox1.Controls.Add(this.groupBox6);
  192. this.groupBox1.Controls.Add(this.groupBox4);
  193. this.groupBox1.Controls.Add(this.label7);
  194. this.groupBox1.Controls.Add(this.groupBox3);
  195. this.groupBox1.Controls.Add(this.panel3);
  196. this.groupBox1.Controls.Add(this.label5);
  197. this.groupBox1.Controls.Add(this.panel2);
  198. this.groupBox1.Controls.Add(this.button1);
  199. this.groupBox1.Controls.Add(this.groupBox5);
  200. this.groupBox1.Controls.Add(this.nbiterations);
  201. this.groupBox1.Controls.Add(this.label4);
  202. this.groupBox1.Controls.Add(this.groupBox2);
  203. this.groupBox1.Controls.Add(this.momentumBox);
  204. this.groupBox1.Controls.Add(this.label6);
  205. this.groupBox1.Controls.Add(this.startButton);
  206. this.groupBox1.Controls.Add(this.errorLimitBox);
  207. this.groupBox1.Controls.Add(this.label3);
  208. this.groupBox1.Controls.Add(this.alphaBox);
  209. this.groupBox1.Controls.Add(this.label2);
  210. this.groupBox1.Controls.Add(this.learningRateBox);
  211. this.groupBox1.Controls.Add(this.label1);
  212. this.groupBox1.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  213. this.groupBox1.Location = new System.Drawing.Point(3, 12);
  214. this.groupBox1.Name = "groupBox1";
  215. this.groupBox1.Size = new System.Drawing.Size(1015, 724);
  216. this.groupBox1.TabIndex = 0;
  217. this.groupBox1.TabStop = false;
  218. this.groupBox1.Text = "réseau de neurones";
  219. this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
  220. //
  221. // button3
  222. //
  223. this.button3.BackColor = System.Drawing.Color.Gainsboro;
  224. this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  225. this.button3.Location = new System.Drawing.Point(5, 696);
  226. this.button3.Name = "button3";
  227. this.button3.Size = new System.Drawing.Size(75, 22);
  228. this.button3.TabIndex = 53;
  229. this.button3.Text = "&Quitter";
  230. this.button3.UseVisualStyleBackColor = false;
  231. this.button3.Click += new System.EventHandler(this.button3_Click);
  232. //
  233. // groupBox6
  234. //
  235. this.groupBox6.BackColor = System.Drawing.Color.Transparent;
  236. this.groupBox6.Controls.Add(this.label12);
  237. this.groupBox6.Controls.Add(this.panel7);
  238. this.groupBox6.Controls.Add(this.label11);
  239. this.groupBox6.Controls.Add(this.panel6);
  240. this.groupBox6.Controls.Add(this.label10);
  241. this.groupBox6.Controls.Add(this.panel5);
  242. this.groupBox6.Controls.Add(this.label9);
  243. this.groupBox6.Controls.Add(this.panel4);
  244. this.groupBox6.Controls.Add(this.label8);
  245. this.groupBox6.Controls.Add(this.panel1);
  246. this.groupBox6.ForeColor = System.Drawing.SystemColors.GradientActiveCaption;
  247. this.groupBox6.Location = new System.Drawing.Point(5, 543);
  248. this.groupBox6.Name = "groupBox6";
  249. this.groupBox6.Size = new System.Drawing.Size(212, 129);
  250. this.groupBox6.TabIndex = 8;
  251. this.groupBox6.TabStop = false;
  252. this.groupBox6.Text = "Information";
  253. //
  254. // label12
  255. //
  256. this.label12.AutoSize = true;
  257. this.label12.Location = new System.Drawing.Point(27, 104);
  258. this.label12.Name = "label12";
  259. this.label12.Size = new System.Drawing.Size(131, 13);
  260. this.label12.TabIndex = 58;
  261. this.label12.Text = "Sortie-Validée-RNS";
  262. //
  263. // panel7
  264. //
  265. this.panel7.BackColor = System.Drawing.Color.Gold;
  266. this.panel7.Location = new System.Drawing.Point(6, 103);
  267. this.panel7.Name = "panel7";
  268. this.panel7.Size = new System.Drawing.Size(13, 14);
  269. this.panel7.TabIndex = 57;
  270. //
  271. // label11
  272. //
  273. this.label11.AutoSize = true;
  274. this.label11.Location = new System.Drawing.Point(25, 84);
  275. this.label11.Name = "label11";
  276. this.label11.Size = new System.Drawing.Size(177, 13);
  277. this.label11.TabIndex = 56;
  278. this.label11.Text = "Sortie-Apprentissage-RNS";
  279. //
  280. // panel6
  281. //
  282. this.panel6.BackColor = System.Drawing.Color.SkyBlue;
  283. this.panel6.Location = new System.Drawing.Point(6, 83);
  284. this.panel6.Name = "panel6";
  285. this.panel6.Size = new System.Drawing.Size(13, 14);
  286. this.panel6.TabIndex = 55;
  287. //
  288. // label10
  289. //
  290. this.label10.AutoSize = true;
  291. this.label10.Location = new System.Drawing.Point(27, 64);
  292. this.label10.Name = "label10";
  293. this.label10.Size = new System.Drawing.Size(133, 13);
  294. this.label10.TabIndex = 54;
  295. this.label10.Text = "Sortie-Desirée-RNS";
  296. //
  297. // panel5
  298. //
  299. this.panel5.BackColor = System.Drawing.Color.DarkGreen;
  300. this.panel5.Location = new System.Drawing.Point(6, 63);
  301. this.panel5.Name = "panel5";
  302. this.panel5.Size = new System.Drawing.Size(13, 14);
  303. this.panel5.TabIndex = 53;
  304. //
  305. // label9
  306. //
  307. this.label9.AutoSize = true;
  308. this.label9.Location = new System.Drawing.Point(29, 44);
  309. this.label9.Name = "label9";
  310. this.label9.Size = new System.Drawing.Size(151, 13);
  311. this.label9.TabIndex = 52;
  312. this.label9.Text = "Erreur-Validation-RNS";
  313. //
  314. // panel4
  315. //
  316. this.panel4.BackColor = System.Drawing.Color.Fuchsia;
  317. this.panel4.Location = new System.Drawing.Point(6, 44);
  318. this.panel4.Name = "panel4";
  319. this.panel4.Size = new System.Drawing.Size(13, 13);
  320. this.panel4.TabIndex = 51;
  321. //
  322. // label8
  323. //
  324. this.label8.AutoSize = true;
  325. this.label8.Location = new System.Drawing.Point(29, 24);
  326. this.label8.Name = "label8";
  327. this.label8.Size = new System.Drawing.Size(180, 13);
  328. this.label8.TabIndex = 50;
  329. this.label8.Text = "Erreur-Apprentissage-RNS";
  330. //
  331. // panel1
  332. //
  333. this.panel1.BackColor = System.Drawing.Color.Red;
  334. this.panel1.Location = new System.Drawing.Point(6, 24);
  335. this.panel1.Name = "panel1";
  336. this.panel1.Size = new System.Drawing.Size(13, 14);
  337. this.panel1.TabIndex = 49;
  338. //
  339. // groupBox4
  340. //
  341. this.groupBox4.BackColor = System.Drawing.Color.Transparent;
  342. this.groupBox4.Controls.Add(this.label20);
  343. this.groupBox4.Controls.Add(this.label19);
  344. this.groupBox4.Controls.Add(this.outputchart);
  345. this.groupBox4.ForeColor = System.Drawing.SystemColors.HotTrack;
  346. this.groupBox4.Location = new System.Drawing.Point(223, 16);
  347. this.groupBox4.Name = "groupBox4";
  348. this.groupBox4.Size = new System.Drawing.Size(258, 272);
  349. this.groupBox4.TabIndex = 51;
  350. this.groupBox4.TabStop = false;
  351. this.groupBox4.Text = "Similarité sortieD/R/V";
  352. this.groupBox4.Enter += new System.EventHandler(this.groupBox4_Enter);
  353. //
  354. // label20
  355. //
  356. this.label20.AutoSize = true;
  357. this.label20.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  358. this.label20.Location = new System.Drawing.Point(1, 20);
  359. this.label20.Name = "label20";
  360. this.label20.Size = new System.Drawing.Size(50, 13);
  361. this.label20.TabIndex = 8;
  362. this.label20.Text = "Sortie>";
  363. //
  364. // label19
  365. //
  366. this.label19.AutoSize = true;
  367. this.label19.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  368. this.label19.Location = new System.Drawing.Point(180, 219);
  369. this.label19.Name = "label19";
  370. this.label19.Size = new System.Drawing.Size(65, 13);
  371. this.label19.TabIndex = 7;
  372. this.label19.Text = "Itération>";
  373. //
  374. // outputchart
  375. //
  376. this.outputchart.Location = new System.Drawing.Point(55, 20);
  377. this.outputchart.Name = "outputchart";
  378. this.outputchart.Size = new System.Drawing.Size(195, 198);
  379. this.outputchart.TabIndex = 1;
  380. this.outputchart.Text = "chart1";
  381. this.outputchart.Click += new System.EventHandler(this.outputchart_Click_1);
  382. //
  383. // label7
  384. //
  385. this.label7.BackColor = System.Drawing.Color.Transparent;
  386. this.label7.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  387. this.label7.ForeColor = System.Drawing.Color.LightSkyBlue;
  388. this.label7.Location = new System.Drawing.Point(3, 229);
  389. this.label7.Name = "label7";
  390. this.label7.Size = new System.Drawing.Size(120, 21);
  391. this.label7.TabIndex = 38;
  392. this.label7.Text = "Itération-Courante";
  393. this.label7.Click += new System.EventHandler(this.label7_Click);
  394. //
  395. // groupBox3
  396. //
  397. this.groupBox3.BackColor = System.Drawing.Color.Transparent;
  398. this.groupBox3.Controls.Add(this.label16);
  399. this.groupBox3.Controls.Add(this.label15);
  400. this.groupBox3.Controls.Add(this.saveFileErrorValidation);
  401. this.groupBox3.Controls.Add(this.validationChart);
  402. this.groupBox3.ForeColor = System.Drawing.SystemColors.HotTrack;
  403. this.groupBox3.Location = new System.Drawing.Point(749, 16);
  404. this.groupBox3.Name = "groupBox3";
  405. this.groupBox3.Size = new System.Drawing.Size(260, 272);
  406. this.groupBox3.TabIndex = 29;
  407. this.groupBox3.TabStop = false;
  408. this.groupBox3.Text = "erreur de validation";
  409. //
  410. // label16
  411. //
  412. this.label16.AutoSize = true;
  413. this.label16.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  414. this.label16.Location = new System.Drawing.Point(189, 221);
  415. this.label16.Name = "label16";
  416. this.label16.Size = new System.Drawing.Size(65, 13);
  417. this.label16.TabIndex = 5;
  418. this.label16.Text = "Itération>";
  419. //
  420. // label15
  421. //
  422. this.label15.AutoSize = true;
  423. this.label15.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  424. this.label15.ForeColor = System.Drawing.SystemColors.Highlight;
  425. this.label15.Location = new System.Drawing.Point(3, 17);
  426. this.label15.Name = "label15";
  427. this.label15.Size = new System.Drawing.Size(52, 13);
  428. this.label15.TabIndex = 4;
  429. this.label15.Text = "Erreur>";
  430. this.label15.Click += new System.EventHandler(this.label15_Click);
  431. //
  432. // validationChart
  433. //
  434. this.validationChart.Location = new System.Drawing.Point(58, 20);
  435. this.validationChart.Name = "validationChart";
  436. this.validationChart.Size = new System.Drawing.Size(196, 198);
  437. this.validationChart.TabIndex = 1;
  438. this.validationChart.Text = "chart1";
  439. this.validationChart.Click += new System.EventHandler(this.validationChart_Click);
  440. //
  441. // panel3
  442. //
  443. this.panel3.BackColor = System.Drawing.Color.Transparent;
  444. this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  445. this.panel3.ForeColor = System.Drawing.Color.White;
  446. this.panel3.Location = new System.Drawing.Point(123, 227);
  447. this.panel3.Name = "panel3";
  448. this.panel3.Size = new System.Drawing.Size(94, 21);
  449. this.panel3.TabIndex = 37;
  450. this.panel3.Paint += new System.Windows.Forms.PaintEventHandler(this.panel3_Paint);
  451. //
  452. // label5
  453. //
  454. this.label5.BackColor = System.Drawing.Color.Transparent;
  455. this.label5.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  456. this.label5.ForeColor = System.Drawing.Color.LightSkyBlue;
  457. this.label5.Location = new System.Drawing.Point(3, 202);
  458. this.label5.Name = "label5";
  459. this.label5.Size = new System.Drawing.Size(107, 19);
  460. this.label5.TabIndex = 36;
  461. this.label5.Text = "Erreur-Courante";
  462. //
  463. // panel2
  464. //
  465. this.panel2.BackColor = System.Drawing.Color.Transparent;
  466. this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  467. this.panel2.ForeColor = System.Drawing.Color.White;
  468. this.panel2.Location = new System.Drawing.Point(123, 200);
  469. this.panel2.Name = "panel2";
  470. this.panel2.Size = new System.Drawing.Size(94, 21);
  471. this.panel2.TabIndex = 35;
  472. this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint);
  473. //
  474. // button1
  475. //
  476. this.button1.BackColor = System.Drawing.Color.Gainsboro;
  477. this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  478. this.button1.Location = new System.Drawing.Point(154, 162);
  479. this.button1.Name = "button1";
  480. this.button1.Size = new System.Drawing.Size(60, 22);
  481. this.button1.TabIndex = 34;
  482. this.button1.Text = "&Stop";
  483. this.button1.UseVisualStyleBackColor = false;
  484. this.button1.Click += new System.EventHandler(this.button1_Click_1);
  485. //
  486. // groupBox5
  487. //
  488. this.groupBox5.BackColor = System.Drawing.Color.Transparent;
  489. this.groupBox5.Controls.Add(this.label18);
  490. this.groupBox5.Controls.Add(this.label17);
  491. this.groupBox5.Controls.Add(this.errcroisechart);
  492. this.groupBox5.ForeColor = System.Drawing.SystemColors.HotTrack;
  493. this.groupBox5.Location = new System.Drawing.Point(223, 305);
  494. this.groupBox5.Name = "groupBox5";
  495. this.groupBox5.Size = new System.Drawing.Size(786, 413);
  496. this.groupBox5.TabIndex = 33;
  497. this.groupBox5.TabStop = false;
  498. this.groupBox5.Text = "Calcule de sortie apprentissage/Désirée";
  499. //
  500. // label18
  501. //
  502. this.label18.AutoSize = true;
  503. this.label18.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  504. this.label18.Location = new System.Drawing.Point(6, 19);
  505. this.label18.Name = "label18";
  506. this.label18.Size = new System.Drawing.Size(48, 13);
  507. this.label18.TabIndex = 7;
  508. this.label18.Text = "sortie>";
  509. //
  510. // label17
  511. //
  512. this.label17.AutoSize = true;
  513. this.label17.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  514. this.label17.Location = new System.Drawing.Point(688, 387);
  515. this.label17.Name = "label17";
  516. this.label17.Size = new System.Drawing.Size(88, 13);
  517. this.label17.TabIndex = 6;
  518. this.label17.Text = "Vector-Input>";
  519. //
  520. // errcroisechart
  521. //
  522. this.errcroisechart.Location = new System.Drawing.Point(55, 19);
  523. this.errcroisechart.Name = "errcroisechart";
  524. this.errcroisechart.Size = new System.Drawing.Size(721, 365);
  525. this.errcroisechart.TabIndex = 2;
  526. this.errcroisechart.Text = "chart1";
  527. this.errcroisechart.Click += new System.EventHandler(this.chart1_Click);
  528. //
  529. // nbiterations
  530. //
  531. this.nbiterations.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  532. this.nbiterations.Location = new System.Drawing.Point(154, 135);
  533. this.nbiterations.Name = "nbiterations";
  534. this.nbiterations.Size = new System.Drawing.Size(60, 21);
  535. this.nbiterations.TabIndex = 31;
  536. //
  537. // label4
  538. //
  539. this.label4.BackColor = System.Drawing.Color.Transparent;
  540. this.label4.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  541. this.label4.ForeColor = System.Drawing.Color.LightSkyBlue;
  542. this.label4.Location = new System.Drawing.Point(3, 135);
  543. this.label4.Name = "label4";
  544. this.label4.Size = new System.Drawing.Size(132, 21);
  545. this.label4.TabIndex = 30;
  546. this.label4.Text = "Nombre-Itérations\r\n";
  547. this.label4.Click += new System.EventHandler(this.label4_Click_1);
  548. //
  549. // groupBox2
  550. //
  551. this.groupBox2.BackColor = System.Drawing.Color.Transparent;
  552. this.groupBox2.Controls.Add(this.label14);
  553. this.groupBox2.Controls.Add(this.label13);
  554. this.groupBox2.Controls.Add(this.saveFilesError);
  555. this.groupBox2.Controls.Add(this.errorChart);
  556. this.groupBox2.ForeColor = System.Drawing.SystemColors.HotTrack;
  557. this.groupBox2.Location = new System.Drawing.Point(487, 16);
  558. this.groupBox2.Name = "groupBox2";
  559. this.groupBox2.Size = new System.Drawing.Size(256, 272);
  560. this.groupBox2.TabIndex = 1;
  561. this.groupBox2.TabStop = false;
  562. this.groupBox2.Text = "erreur d\'apprentissage:";
  563. //
  564. // label14
  565. //
  566. this.label14.AutoSize = true;
  567. this.label14.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  568. this.label14.Location = new System.Drawing.Point(1, 19);
  569. this.label14.Name = "label14";
  570. this.label14.Size = new System.Drawing.Size(52, 13);
  571. this.label14.TabIndex = 3;
  572. this.label14.Text = "Erreur>";
  573. //
  574. // label13
  575. //
  576. this.label13.AutoSize = true;
  577. this.label13.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  578. this.label13.Location = new System.Drawing.Point(185, 221);
  579. this.label13.Name = "label13";
  580. this.label13.Size = new System.Drawing.Size(65, 13);
  581. this.label13.TabIndex = 2;
  582. this.label13.Text = "Itération>";
  583. //
  584. // saveFilesError
  585. //
  586. this.saveFilesError.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  587. this.saveFilesError.ForeColor = System.Drawing.Color.LightSkyBlue;
  588. this.saveFilesError.Location = new System.Drawing.Point(4, 248);
  589. this.saveFilesError.Name = "saveFilesError";
  590. this.saveFilesError.Size = new System.Drawing.Size(230, 18);
  591. this.saveFilesError.TabIndex = 1;
  592. this.saveFilesError.Text = "enregister l\'erreur d\'apprentissage";
  593. this.saveFilesError.CheckedChanged += new System.EventHandler(this.saveFilesCheck_CheckedChanged);
  594. //
  595. // errorChart
  596. //
  597. this.errorChart.Location = new System.Drawing.Point(54, 20);
  598. this.errorChart.Name = "errorChart";
  599. this.errorChart.Size = new System.Drawing.Size(196, 198);
  600. this.errorChart.TabIndex = 0;
  601. this.errorChart.Text = "chart1";
  602. this.errorChart.Click += new System.EventHandler(this.errorChart_Click);
  603. //
  604. // momentumBox
  605. //
  606. this.momentumBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  607. this.momentumBox.Location = new System.Drawing.Point(154, 54);
  608. this.momentumBox.Name = "momentumBox";
  609. this.momentumBox.Size = new System.Drawing.Size(60, 21);
  610. this.momentumBox.TabIndex = 3;
  611. //
  612. // label6
  613. //
  614. this.label6.BackColor = System.Drawing.Color.Transparent;
  615. this.label6.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  616. this.label6.ForeColor = System.Drawing.Color.LightSkyBlue;
  617. this.label6.Location = new System.Drawing.Point(3, 54);
  618. this.label6.Name = "label6";
  619. this.label6.Size = new System.Drawing.Size(69, 21);
  620. this.label6.TabIndex = 2;
  621. this.label6.Text = "Moment";
  622. this.label6.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  623. this.label6.Click += new System.EventHandler(this.label6_Click);
  624. //
  625. // startButton
  626. //
  627. this.startButton.BackColor = System.Drawing.Color.Gainsboro;
  628. this.startButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  629. this.startButton.Location = new System.Drawing.Point(6, 162);
  630. this.startButton.Name = "startButton";
  631. this.startButton.Size = new System.Drawing.Size(137, 23);
  632. this.startButton.TabIndex = 27;
  633. this.startButton.Text = "&Démarrer ";
  634. this.startButton.UseVisualStyleBackColor = false;
  635. this.startButton.Click += new System.EventHandler(this.startButton_Click);
  636. //
  637. // errorLimitBox
  638. //
  639. this.errorLimitBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  640. this.errorLimitBox.Location = new System.Drawing.Point(154, 108);
  641. this.errorLimitBox.Name = "errorLimitBox";
  642. this.errorLimitBox.Size = new System.Drawing.Size(60, 21);
  643. this.errorLimitBox.TabIndex = 7;
  644. //
  645. // label3
  646. //
  647. this.label3.BackColor = System.Drawing.Color.Transparent;
  648. this.label3.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  649. this.label3.ForeColor = System.Drawing.Color.LightSkyBlue;
  650. this.label3.Location = new System.Drawing.Point(3, 108);
  651. this.label3.Name = "label3";
  652. this.label3.Size = new System.Drawing.Size(110, 15);
  653. this.label3.TabIndex = 6;
  654. this.label3.Text = "Erreur-Limite";
  655. this.label3.Click += new System.EventHandler(this.label3_Click);
  656. //
  657. // alphaBox
  658. //
  659. this.alphaBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  660. this.alphaBox.Location = new System.Drawing.Point(154, 81);
  661. this.alphaBox.Name = "alphaBox";
  662. this.alphaBox.Size = new System.Drawing.Size(60, 21);
  663. this.alphaBox.TabIndex = 5;
  664. //
  665. // label2
  666. //
  667. this.label2.BackColor = System.Drawing.Color.Transparent;
  668. this.label2.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  669. this.label2.ForeColor = System.Drawing.Color.LightSkyBlue;
  670. this.label2.Location = new System.Drawing.Point(3, 81);
  671. this.label2.Name = "label2";
  672. this.label2.Size = new System.Drawing.Size(100, 15);
  673. this.label2.TabIndex = 4;
  674. this.label2.Text = " Valeur-Béta";
  675. this.label2.Click += new System.EventHandler(this.label2_Click);
  676. //
  677. // learningRateBox
  678. //
  679. this.learningRateBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  680. this.learningRateBox.Location = new System.Drawing.Point(154, 27);
  681. this.learningRateBox.Name = "learningRateBox";
  682. this.learningRateBox.Size = new System.Drawing.Size(60, 21);
  683. this.learningRateBox.TabIndex = 1;
  684. //
  685. // label1
  686. //
  687. this.label1.BackColor = System.Drawing.Color.Transparent;
  688. this.label1.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  689. this.label1.ForeColor = System.Drawing.Color.LightSkyBlue;
  690. this.label1.Location = new System.Drawing.Point(6, 28);
  691. this.label1.Name = "label1";
  692. this.label1.Size = new System.Drawing.Size(137, 20);
  693. this.label1.TabIndex = 0;
  694. this.label1.Text = "Pas-Apprentissage";
  695. this.label1.Click += new System.EventHandler(this.label1_Click);
  696. //
  697. // saveFileErrorValidation
  698. //
  699. this.saveFileErrorValidation.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  700. this.saveFileErrorValidation.ForeColor = System.Drawing.Color.LightSkyBlue;
  701. this.saveFileErrorValidation.ImageKey = "(aucun)";
  702. this.saveFileErrorValidation.Location = new System.Drawing.Point(6, 248);
  703. this.saveFileErrorValidation.Name = "saveFileErrorValidation";
  704. this.saveFileErrorValidation.Size = new System.Drawing.Size(211, 18);
  705. this.saveFileErrorValidation.TabIndex = 2;
  706. this.saveFileErrorValidation.Text = "enregister l\'erreur de validation";
  707. this.saveFileErrorValidation.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
  708. //
  709. // MainForm
  710. //
  711. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  712. this.BackColor = System.Drawing.Color.GhostWhite;
  713. this.ClientSize = new System.Drawing.Size(1022, 748);
  714. this.Controls.Add(this.groupBox1);
  715. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  716. this.MaximizeBox = false;
  717. this.Name = "MainForm";
  718. this.Text = "Réseau de neurones";
  719. this.Load += new System.EventHandler(this.MainForm_Load);
  720. this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
  721. this.groupBox1.ResumeLayout(false);
  722. this.groupBox1.PerformLayout();
  723. this.groupBox6.ResumeLayout(false);
  724. this.groupBox6.PerformLayout();
  725. this.groupBox4.ResumeLayout(false);
  726. this.groupBox4.PerformLayout();
  727. this.groupBox3.ResumeLayout(false);
  728. this.groupBox3.PerformLayout();
  729. this.groupBox5.ResumeLayout(false);
  730. this.groupBox5.PerformLayout();
  731. this.groupBox2.ResumeLayout(false);
  732. this.groupBox2.PerformLayout();
  733. this.ResumeLayout(false);
  734.  
  735. }
  736. #endregion
  737.  
  738. /// <summary>
  739. /// The main entry point for the application.
  740. /// </summary>
  741. [STAThread]
  742. static void Main()
  743. {
  744. Application.Run(new MainForm());
  745. }
  746.  
  747. // On main form closing
  748. private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  749. {
  750. // check if worker thread is running
  751. if ((workerThread != null) && (workerThread.IsAlive))
  752. {
  753. needToStop = true;
  754. workerThread.Join();
  755. }
  756. }
  757.  
  758. // Mettre à jour les controles de l'application
  759. private void UpdateSettings()
  760. {
  761. learningRateBox.Text = learningRate.ToString();
  762. momentumBox.Text = momentum.ToString();
  763. nbiterations.Text = nbiteration.ToString();
  764. alphaBox.Text = sigmoidAlphaValue.ToString();
  765. errorLimitBox.Text = learningErrorLimit.ToString();
  766. saveFilesError.Checked = saveStatisticsToFiles;
  767.  
  768. }
  769.  
  770. // Enable/disable controls
  771. private void EnableControls(bool enable)
  772. {
  773. learningRateBox.Enabled = enable;
  774. momentumBox.Enabled = enable;
  775. alphaBox.Enabled = enable;
  776. errorLimitBox.Enabled = enable;
  777.  
  778. saveFilesError.Enabled = enable;
  779.  
  780. startButton.Enabled = enable;
  781.  
  782. }
  783.  
  784. // On "Start" button click
  785. private void startButton_Click(object sender, System.EventArgs e)
  786. {
  787. // get learning rate
  788. try
  789. {
  790. learningRate = Math.Max(0.00001, Math.Min(1, double.Parse(learningRateBox.Text)));
  791. }
  792. catch
  793. {
  794. learningRate = 0.1;
  795. }
  796. // get momentum
  797. try
  798. {
  799. momentum = Math.Max(0, Math.Min(0.5, double.Parse(momentumBox.Text)));
  800. }
  801. catch
  802. {
  803. momentum = 0;
  804. }
  805. // get sigmoid's alpha value
  806. try
  807. {
  808. sigmoidAlphaValue = Math.Max(0.01, Math.Min(100, double.Parse(alphaBox.Text)));
  809. }
  810. catch
  811. {
  812. sigmoidAlphaValue = 1;
  813. }
  814. // get learning error limit
  815. try
  816. {
  817. learningErrorLimit = Math.Max(0, double.Parse(errorLimitBox.Text));
  818. }
  819. catch
  820. {
  821. learningErrorLimit = 0.1;
  822. }
  823. // get sigmoid's type
  824. try
  825. {
  826. nbiteration = Math.Max(10, int.Parse(nbiterations.Text));
  827. }
  828. catch
  829. {
  830. nbiteration = 200;
  831. }
  832. saveStatisticsToFiles = saveFilesError.Checked;
  833. // saveValidationToFiles = saveFileErrorValidation.Checked;
  834.  
  835. // update settings controls
  836. UpdateSettings();
  837.  
  838.  
  839. // run worker thread
  840. needToStop = false;
  841. workerThread = new Thread(new ThreadStart(SearchSolution));
  842. workerThread.Start();
  843. timer1.Enabled = true;
  844. }
  845.  
  846. // On "Stop" button click
  847. private void stopButton_Click(object sender, System.EventArgs e)
  848. {
  849.  
  850.  
  851.  
  852. }
  853. //---------------------------------------------------------------------------------------
  854. // Worker thread
  855. void SearchSolution()
  856. {
  857. // initialiser le vecteur d'entrées et le vecteur de sortis
  858. double[][] input = null;
  859. double[] []output = null;
  860. double[][] vinput = null;
  861. double[][] voutput = null;
  862.  
  863.  
  864. input = new double[12][] {
  865. new double[] { 0.0000},
  866. new double[] { 0.1642},
  867. new double[] { 0.2585},
  868. new double[] { 0.2092},
  869. new double[] { 0.3697},
  870. new double[] { 0.4425},
  871. new double[] { 0.5823},
  872. new double[] { 0.5687},
  873. new double[] { 0.4490},
  874. new double[] { 0.1543},
  875. new double[] { 0.1210},
  876. new double[] {1.0000},
  877.  
  878. /*new double[] { 0.2055},
  879. new double[] { 0.1703},
  880. new double[] { 0.1435},
  881. new double[] { 0.1684},
  882. new double[] { 0.2285},
  883. new double[] { 0.1234},
  884. new double[] { 0.5480},
  885.  
  886. new double[] {0.7240},
  887. new double[] { 0.6865},
  888. new double[] { 0.5232},
  889. new double[] { 0.3580},
  890. new double[] {0.2078},
  891. new double[] { 0.2069},
  892. new double[] { 0.1234 } */
  893.  
  894.  
  895. };
  896.  
  897.  
  898. vinput = new double[12][] {
  899. new double[] { 0.4866},
  900. new double[] { 0.5979},
  901. new double[] { 1.0000},
  902. new double[] { 0.7254},
  903. new double[] { 0.7312},
  904. new double[] { 0.4508},
  905. new double[] { 0.1073},
  906. new double[] { 0.1776},
  907. new double[] { 0.0000},
  908. new double[] { 0.1210},
  909. new double[] { 0.3441},
  910. new double[] { 0.1151}
  911.  
  912. };
  913.  
  914. //le vecteur de sortie_ d'apprentissage
  915. output = new double[12][]{
  916. new double[] { 0.0000},
  917. new double[] { 0.3335},
  918. new double[] { 0.3991},
  919. new double[] { 0.5982},
  920. new double[] { 0.7689},
  921. new double[] { 1.0000},
  922. new double[] { 0.5787},
  923. new double[] { 0.2830},
  924. new double[] { 0.3203},
  925. new double[] { 0.0225},
  926. new double[] { 0.0630},
  927. new double[] { 0.2526},
  928.  
  929. /*new double[] {0.1622},
  930. new double[] {0.1838},
  931. new double[] {0.3261},
  932. new double[] {0.4695},
  933. new double[] {0.6974},
  934. new double[] {0.6727},
  935. new double[] {0.3697},
  936. new double[] {0.3230},
  937. new double[] {0.2977},
  938. new double[] {0.0808},
  939. new double[] {0.0530},
  940. new double[] {0.1796},
  941. new double[] {0.1596},
  942. new double[] {0.4732}*/
  943. };
  944. //vecteur de sortie de validation
  945. voutput = new double[12][] { new double[] {0.4190},
  946. new double[] {0.8348},
  947. new double[] {0.8552},
  948. new double[] {1.0000},
  949. new double[] {0.8565},
  950. new double[] {0.4605},
  951. new double[] {0.0888},
  952. new double[] {0.0000},
  953. new double[] {0.0993},
  954. new double[] {0.0690},
  955. new double[] {0.2480},
  956. new double[] {0.3500},
  957.  
  958.  
  959.  
  960. /* new double[] {0.19391116},
  961. new double[] {0.257099057},
  962. new double[] {0.299550289},
  963. new double[] {0.545081354},
  964. new double[] {0.139968195},
  965. new double[] {-0.361387293},
  966. new double[] {-0.822998165},
  967. new double[] {-0.995560888},
  968. new double[] {-0.612664878},
  969. new double[] {0.292257041},
  970. new double[] {0.987906637},
  971. new double[] {0.405747428},
  972. new double[] {-0.89718364},
  973. new double[] {-0.234599031},
  974. new double[] {0.958708846},
  975. new double[] {-0.920692492},
  976. new double[] {0.781716095},
  977. new double[] {-0.89690409}*/
  978. };
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985. // créer un perceptron
  986. ActivationNetwork network = new ActivationNetwork(
  987. (IActivationFunction)new SigmoidFunction(sigmoidAlphaValue),
  988. 1, 8, 1);
  989. // create teacher
  990. BackPropagationLearning teacher = new BackPropagationLearning(network);
  991. // set learning rate and momentum
  992. teacher.LearningRate = learningRate;
  993. teacher.Momentum = momentum;
  994.  
  995. // iterations
  996. int iteration = 1;
  997.  
  998. // statistic files
  999. StreamWriter errorsFile = null;
  1000. StreamWriter validationFile = null;
  1001.  
  1002. try
  1003. {
  1004. // check if we need to save statistics to files
  1005. if (saveStatisticsToFiles)
  1006. {
  1007. // open files
  1008. errorsFile = File.CreateText("errorsApprentissage.csv");
  1009. }
  1010. if (saveValidationToFiles)
  1011. {
  1012. // open files
  1013. validationFile = File.CreateText("errorsValidation.csv");
  1014. }
  1015.  
  1016. // erros list
  1017. ArrayList errorsList = new ArrayList();
  1018. ArrayList abscicexList = new ArrayList();
  1019.  
  1020. ArrayList verrorsList = new ArrayList();
  1021. ArrayList sortdesireeList = new ArrayList();
  1022. ArrayList sortdesireesinusList = new ArrayList();
  1023.  
  1024. ArrayList sortyeList = new ArrayList();
  1025. ArrayList sortsinusList = new ArrayList();
  1026. ArrayList sortyVList = new ArrayList();
  1027. //****************************************
  1028. ArrayList tabDyn = new ArrayList();
  1029. Graphics g = panel2.CreateGraphics();
  1030. Graphics g2 = panel3.CreateGraphics();
  1031. //***************************************
  1032.  
  1033. // loop
  1034. //while (!needToStop)
  1035. for(int j=0;j<nbiteration;j++)
  1036. {
  1037. // run epoch of learning procedure
  1038. double error = teacher.RunEpoch(input, output);
  1039. errorsList.Add(error);
  1040.  
  1041. for(int F=0;F<12;F++)
  1042. {
  1043. abscicexList.Add(output);
  1044.  
  1045. }
  1046.  
  1047. //**************************************************
  1048. tabDyn.Add(error);
  1049. g.Clear(System.Drawing.SystemColors.ButtonFace);
  1050. g.DrawString(error + "", new Font("Arial", 10), new SolidBrush(Color.Black), 3, 3);
  1051. g2.Clear(System.Drawing.SystemColors.ButtonFace);
  1052. g2.DrawString(j + "", new Font("Arial", 10), new SolidBrush(Color.Black), 3, 3);
  1053. tabErreur = new double[tabDyn.Count, 2];
  1054. for (int i = 0; i < tabDyn.Count; i++)
  1055. {
  1056. tabErreur[i, 0] = i;
  1057. tabErreur[i, 1] = (double)tabDyn[i];
  1058. }
  1059. //**************************************************
  1060.  
  1061.  
  1062. //Calculer la sortie du réseau
  1063. //---------------------------------------------------
  1064. double s = 0;
  1065. IActivationFunction function = network[0][0].ActivationFunction;
  1066. for (int t = 0; t < 12; t++)
  1067. {
  1068. double[] so = calculer_sort(network,input[t]);
  1069. double verification = valider(so);
  1070. s += verification;
  1071.  
  1072. }
  1073. sortyeList.Add(s);
  1074.  
  1075. double sp = 0;
  1076. for (int te = 0; te < 12; te++)
  1077. {
  1078. double[] sop = calculer_sort(network, input[te]);
  1079. double verificationp = valider(sop);
  1080. sp += verificationp;
  1081. sortsinusList.Add(sp);
  1082.  
  1083. }
  1084.  
  1085. //Calculer la sortie de validation du réseau
  1086. //---------------------------------------
  1087. double sv = 0;
  1088. for (int w = 0; w < 12; w++)
  1089. {
  1090. double[] sov = calculer_sort(network, vinput[w]);
  1091. double verificationvalidation = valider(sov);
  1092. sv += verificationvalidation;
  1093. }
  1094. sortyVList.Add(sv);
  1095.  
  1096.  
  1097.  
  1098. //Stocker la sortie réel du réseau dans un ArrayList
  1099. //------------------------------------------
  1100. double sd = 0;
  1101.  
  1102. for (int k = 0; k < 12; k++)
  1103. {
  1104. double[] sod = calculer_sortieD(output[k]); ;
  1105. double verificat = valider(sod);
  1106. sd += verificat;
  1107. }
  1108. sortdesireeList.Add(sd);
  1109.  
  1110.  
  1111.  
  1112. double sds = 0;
  1113.  
  1114. for (int k = 0; k < 12; k++)
  1115. {
  1116. double[] sodsinus = calculer_sortieD(output[k]); ;
  1117. double verificat = valider(sodsinus);
  1118. sds += verificat;
  1119. sortdesireesinusList.Add(sds);
  1120. }
  1121.  
  1122.  
  1123. // Calculer l'erreur de validation
  1124. //------------------------------------------
  1125. double eval=0;
  1126.  
  1127. for(int i=0;i<12;i++)
  1128. {
  1129. double[] sortie = calculer_sortie(network,vinput[i]);
  1130.  
  1131. double erreurval = valider(sortie, voutput[i]);
  1132. eval += erreurval;
  1133. }
  1134. verrorsList.Add(eval);
  1135.  
  1136.  
  1137. // Stocker l'erreur courante
  1138. //------------------------------------------
  1139. if (errorsFile != null)
  1140. {
  1141. errorsFile.WriteLine(error);
  1142. }
  1143. if (validationFile != null)
  1144. {
  1145. validationFile.WriteLine(eval);
  1146. }
  1147.  
  1148. iteration++;
  1149.  
  1150. //Besoin de Stopper l'appliation
  1151. //------------------------------------------
  1152. if (error <= learningErrorLimit)
  1153. break;
  1154. }
  1155.  
  1156. // Exhiber les erreurs dynamics
  1157. //------------------------------------------
  1158. double[,] errors = new double[errorsList.Count, 2];
  1159.  
  1160. for (int i = 0, n = errorsList.Count; i < n; i++)
  1161. {
  1162. errors[i, 0] = i;
  1163. errors[i, 1] = (double)errorsList[i];
  1164. }
  1165.  
  1166. errorChart.RangeX = new DoubleRange(0, errorsList.Count - 1);
  1167. errorChart.UpdateDataSeries("error", errors);
  1168.  
  1169.  
  1170.  
  1171.  
  1172. double[,] verrors = new double[verrorsList.Count, 2];
  1173.  
  1174. for (int i = 0, n = verrorsList.Count; i < n; i++)
  1175. {
  1176. verrors[i, 0] = i;
  1177. verrors[i, 1] = (double)verrorsList[i];
  1178. }
  1179.  
  1180. validationChart.RangeX = new DoubleRange(0, errorsList.Count - 1);
  1181. validationChart.UpdateDataSeries("validation", verrors);
  1182. errcroisechart.RangeX = new DoubleRange(0, errorsList.Count - 1);
  1183.  
  1184. double[,] sorchart = new double[sortsinusList.Count, 2];
  1185.  
  1186. for (int i = 0, n = sortsinusList.Count; i < n; i++)
  1187. {
  1188. for (int kI = 0; kI < 12; kI++)
  1189. {
  1190. sorchart[i, 0] = i;
  1191. sorchart[i, 1] = (double)sortsinusList[i];
  1192. }
  1193. }
  1194.  
  1195.  
  1196.  
  1197. double[,] sordsinuschart = new double[sortdesireesinusList.Count, 2];
  1198.  
  1199. for (int i = 0, n = sortdesireesinusList.Count; i < n; i++)
  1200. {
  1201. for (int kI = 0; kI < 12; kI++)
  1202. {
  1203. sordsinuschart[i, 0] = i;
  1204. sordsinuschart[i, 1] = (double)sortdesireesinusList[i];
  1205. }
  1206. }
  1207.  
  1208.  
  1209.  
  1210.  
  1211. double[,] sortiechart = new double[sortyeList.Count, 2];
  1212.  
  1213. for (int i = 0, n = sortyeList.Count; i < n; i++)
  1214. {
  1215. sortiechart[i, 0] = i;
  1216. sortiechart[i, 1] = (double)sortyeList[i];
  1217. }
  1218.  
  1219. double[,] sortiDechart = new double[sortdesireeList.Count, 2];
  1220. for (int i = 0, n = sortdesireeList.Count; i < n; i++)
  1221. {
  1222. sortiDechart[i, 0] = i;
  1223. sortiDechart[i, 1] = (double)sortdesireeList[i];
  1224. }
  1225. errcroisechart.UpdateDataSeries("SORTIED", sordsinuschart);
  1226. errcroisechart.UpdateDataSeries("SORTIER", sorchart);
  1227.  
  1228.  
  1229.  
  1230. double[,] sortiVchart = new double[sortyVList.Count, 2];
  1231. for (int i = 0, n = sortyVList.Count; i < n; i++)
  1232. {
  1233. sortiVchart[i, 0] = i;
  1234. sortiVchart[i, 1] = (double)sortyVList[i];
  1235. }
  1236.  
  1237. outputchart.RangeX = new DoubleRange(0, errorsList.Count - 1);
  1238. outputchart.UpdateDataSeries("sortieRNS", sortiechart);
  1239. outputchart.UpdateDataSeries("sortieDesi", sortiDechart);
  1240. outputchart.UpdateDataSeries("sortieRNSv", sortiVchart);
  1241. }
  1242. catch (IOException)
  1243. {
  1244. MessageBox.Show("Failed writing file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1245. }
  1246. finally
  1247. {
  1248. // close files
  1249. if (errorsFile != null)
  1250. errorsFile.Close();
  1251. if (validationFile != null)
  1252. validationFile.Close();
  1253. }
  1254.  
  1255. needToStop = true;
  1256. // enable settings controls
  1257. //EnableControls( true );
  1258. }
  1259. //---------------------------------------------------------------------------------------------
  1260. double[] calculer_sortie(ActivationNetwork reseau,double[] input)
  1261. {
  1262. double[] sorties = reseau.Compute(input);
  1263.  
  1264.  
  1265. return sorties;
  1266. }
  1267. //---------------------------------------------------------------------------------------------
  1268. double[] calculer_sortieD(double[] output)
  1269. {
  1270. double[] sorties = output;
  1271.  
  1272.  
  1273. return sorties;
  1274. }
  1275.  
  1276.  
  1277. //---------------------------------------------------------------------------------------------
  1278.  
  1279. double[] calculer_sort(ActivationNetwork reseau, double[] input)
  1280. {
  1281. double[] so = reseau.Compute(input);
  1282.  
  1283.  
  1284. return so;
  1285. }
  1286. //-------------------------------------------------------------------------------------------
  1287. double valider(double[] sortie)
  1288. {
  1289.  
  1290.  
  1291. double er = 0;
  1292.  
  1293. for (int i = 0; i < sortie.Length; i++)
  1294. {
  1295. double e = sortie[i];
  1296. er += e * e;
  1297.  
  1298. }
  1299. return er;
  1300.  
  1301. }
  1302.  
  1303.  
  1304.  
  1305. //--------------------------------------------------------------------------------------------
  1306. double valider(double[] sortie, double[] sortiesDesiré)
  1307. {
  1308.  
  1309.  
  1310. double err = 0;
  1311. double[] erreurs = new double[sortie.Length];
  1312. for (int i = 0; i < sortie.Length; i++)
  1313. {
  1314. double e=sortiesDesiré[i] - sortie[i];
  1315. err += e * e;
  1316.  
  1317. }
  1318. return err;
  1319.  
  1320. }
  1321. //---------------------------------------------------------------------------------------------
  1322. private void label4_Click(object sender, EventArgs e)
  1323. {
  1324.  
  1325. }
  1326.  
  1327. private void label3_Click(object sender, EventArgs e)
  1328. {
  1329.  
  1330. }
  1331.  
  1332. private void groupBox1_Enter(object sender, EventArgs e)
  1333. {
  1334.  
  1335. }
  1336.  
  1337. private void sigmoidTypeCombo_SelectedIndexChanged(object sender, EventArgs e)
  1338. {
  1339.  
  1340. }
  1341.  
  1342. private void errorChart_Click(object sender, EventArgs e)
  1343. {
  1344.  
  1345. }
  1346. //-------------------------------------------------------------------------------------------
  1347. private void button1_Click(object sender, EventArgs e)
  1348. {
  1349.  
  1350. }
  1351. //----------------------------------------------------------------------------------------------
  1352.  
  1353.  
  1354. private void MainForm_Load(object sender, EventArgs e)
  1355. {
  1356.  
  1357. }
  1358.  
  1359. private void validationChart_Click(object sender, EventArgs e)
  1360. {
  1361.  
  1362. }
  1363.  
  1364. private void saveFilesCheck_CheckedChanged(object sender, EventArgs e)
  1365. {
  1366.  
  1367. }
  1368.  
  1369. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  1370. {
  1371.  
  1372. }
  1373.  
  1374. private void label6_Click(object sender, EventArgs e)
  1375. {
  1376.  
  1377. }
  1378.  
  1379. private void label4_Click_1(object sender, EventArgs e)
  1380. {
  1381.  
  1382. }
  1383.  
  1384. private void chart1_Click(object sender, EventArgs e)
  1385. {
  1386.  
  1387. }
  1388.  
  1389. private void label2_Click(object sender, EventArgs e)
  1390. {
  1391.  
  1392. }
  1393.  
  1394. private void label1_Click(object sender, EventArgs e)
  1395. {
  1396.  
  1397. }
  1398.  
  1399. private void button1_Click_1(object sender, EventArgs e)
  1400. {
  1401. try
  1402. {
  1403. needToStop = true;
  1404. workerThread.Join();
  1405. workerThread = null;
  1406. errorChart.Invalidate();
  1407. validationChart.Invalidate();
  1408. }
  1409. catch (Exception) { startButton.Enabled = false; }
  1410. startButton.Enabled = true;
  1411. }
  1412.  
  1413. private void panel2_Paint(object sender, PaintEventArgs e)
  1414. {
  1415.  
  1416. }
  1417.  
  1418. private void label5_Click(object sender, EventArgs e)
  1419. {
  1420.  
  1421. }
  1422.  
  1423. private void label10_Click(object sender, EventArgs e)
  1424. {
  1425.  
  1426. }
  1427.  
  1428. private void panel6_Paint(object sender, PaintEventArgs e)
  1429. {
  1430.  
  1431. }
  1432.  
  1433. private void label11_Click(object sender, EventArgs e)
  1434. {
  1435.  
  1436. }
  1437.  
  1438. private void label8_Click(object sender, EventArgs e)
  1439. {
  1440.  
  1441. }
  1442.  
  1443. private void label7_Click(object sender, EventArgs e)
  1444. {
  1445.  
  1446. }
  1447.  
  1448. private void outputchart_Click(object sender, EventArgs e)
  1449. {
  1450.  
  1451. }
  1452.  
  1453. private void panel3_Paint(object sender, PaintEventArgs e)
  1454. {
  1455.  
  1456. }
  1457.  
  1458. private void button3_Click(object sender, EventArgs e)
  1459. {
  1460. Close();
  1461. }
  1462.  
  1463. private void groupBox4_Enter(object sender, EventArgs e)
  1464. {
  1465.  
  1466. }
  1467.  
  1468. private void outputchart_Click_1(object sender, EventArgs e)
  1469. {
  1470.  
  1471. }
  1472.  
  1473. private void textBox1_TextChanged(object sender, EventArgs e)
  1474. {
  1475.  
  1476. }
  1477.  
  1478. private void label15_Click(object sender, EventArgs e)
  1479. {
  1480.  
  1481. }
  1482.  
  1483.  
  1484. }
  1485. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement