1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using System.IO;
using AForge.Neuro;
using AForge.Neuro.Learning;
using AForge.Controls;
using ZedGraph;
using AForge.Genetic;
namespace Network
{
public partial class Form1 : Form
{
double erreur;
int nbreNeurHidLay = 3;
double pasDApp = 0.1;
double momentum = 0;
int j;
double[][] entrees = new Double[119][];
double[][] sorties = new Double[119][];
double[][] entreesval = new Double[118][];
double[][] sortiesdis = new Double[118][];
double[][] entreestest = new Double[7][];
double[][] sortiestest = new Double[7][];
ArrayList tabDynErr = new ArrayList();
ArrayList tabDynVal = new ArrayList();
ArrayList tabCompO = new ArrayList();
ArrayList sortiescalculées = new ArrayList();
bool stop = false;
double[] Données_semaine_RNA = new double[246];
//double[] PIBsemaine5ans = new double[265];
IActivationFunction fonction;
ActivationNetwork reseau;
BackPropagationLearning apprentissage;
public Form1()
{
Control.CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
initialisation();
}
public void initialisation()
{
initgraph();
limErreurfield.Text = "0,01";
limIterField.Text = 500.ToString();
pasDAppField.Text = pasDApp.ToString();
MomentumField.Text = momentum.ToString();
alphaField.Text = "2";
nbreNeuField.Text = nbreNeurHidLay.ToString();
fonction = new BipolarSigmoidFunction(double.Parse(alphaField.Text));
reseau = new ActivationNetwork(fonction, 3, int.Parse(nbreNeuField.Text), 1);
apprentissage = new BackPropagationLearning(reseau);
apprentissage.LearningRate = double.Parse(pasDAppField.Text);
apprentissage.Momentum = double.Parse(MomentumField.Text);
gotya("C:\\Data\\Données_semaine_RNA3.txt", Données_semaine_RNA);
//gotya2("C:\\Data\\PIB_semaine5ans.txt", PIBsemaine5ans);
for (int i = 0; i < 119; i++)
entrees[i] = new double[] { Données_semaine_RNA[i], Données_semaine_RNA[i+1], Données_semaine_RNA[i+2]};
for (int i = 0; i < 119; i++)
sorties[i] = new double[] { Données_semaine_RNA[i + 3] };
for (int i = 0; i < 118; i++)
entreesval[i] = new double[] { Données_semaine_RNA[i + 119], Données_semaine_RNA[i + 120], Données_semaine_RNA[i + 121] };
for (int i = 0; i < 118; i++)
sortiesdis[i] = new double[] { Données_semaine_RNA[i + 122] };
for (int i = 0; i < 7; i++)
sortiestest[i] = new double[] { Données_semaine_RNA[i + 236], Données_semaine_RNA[i + 237], Données_semaine_RNA[i + 238] };
for (int i = 0; i < 7; i++)
sortiestest[i] = new double[] { Données_semaine_RNA[i + 239] };
}
public void learnin() {
int j = 0, cpt=0;;
while (!stop)
{
erreur = apprentissage.RunEpoch(entrees, sorties);
double erreurVal = computiation(entreesval, sortiesdis);
listErreur.Items.Add(j.ToString("000") + "\t" + erreur.ToString("0.######") + "\t\t" + erreurVal.ToString("0.######") );
tabDynErr.Add(erreur);
tabDynVal.Add(erreurVal);
listErreur.SelectedIndex = listErreur.Items.Count - 1;
if (erreurVal<double.Parse(limErreurfield.Text) || j+1>int.Parse(limIterField.Text))
{
arreter.Enabled = false;
stop = true;
CreerGraphique(zg1);
}
/*if (j!=0 && (double)tabDynVal[j] > (double)tabDynVal[j - 1])
{
cpt++;
if (cpt > 10)
{
arreter.Enabled = false;
stop = true;
CreerGraphique(zg1);
}
}
//*/
j++;
}
}
private double computiation(double[][] entreesval, double[][] sortiesdis)
{
double totalError = 0;
for (int i = 0, inputVectorsAmount = entreesval.Length; i < inputVectorsAmount; i++)
{
double[] computedOutput = reseau.Compute(entreesval[i]);
tabCompO.Add(computedOutput[0]);
for (int j = 0, outputLength = sortiesdis[0].Length; j < outputLength; j++)
{
double error = sortiesdis[i][j] - computedOutput[j];
totalError += error * error;
}
}
return totalError;
}
private void commencer_Click(object sender, EventArgs e)
{
zg1.GraphPane.CurveList.Clear();
zg1.Invalidate();
commencer.Enabled = false;
arreter.Enabled = true;
stop = false;
// learnin();
Thread thread = new Thread(new ThreadStart(learnin));
thread.Start();
}
private void arreter_Click(object sender, EventArgs e)
{
arreter.Enabled = false;
stop = true;
CreerGraphique(zg1);
}
public void gotya(String filename, Double[] tabData)
{
TextReader sr = new StreamReader(filename);
string contents = sr.ReadToEnd();
string[] myArray = contents.Split('\t');
for (int j = 0; j <246; j++)
{
// string a = myArray[j];
tabData[j] = Convert.ToDouble(myArray[j]) / 4175.9;
}
} |
Partager