Beispiel #1
0
        public ElmansNetwork Learn(ElmansNetwork elmanNet)
        {
            if (data == null || data.Count == 0)
            {
                //MessageBox.Show("Wczytaj zestaw ucz¹cy");
                return elmanNet;
            }

            int entryLayerSize = Properties.Settings.Default.entryLayerSize;
            int exitLayerSize = Properties.Settings.Default.estimationTime;
            int hiddenLayerSize = Properties.Settings.Default.hiddenLayerSize;

            //IEnumerator enumerator = data.Keys.GetEnumerator();
            //double[] values = new double[data.Count];
            //int i = 0;
            //while (enumerator.MoveNext())
            //{
            //    DateTime dt = (DateTime)enumerator.Current;
            //    values[i++] = data[dt];
            //}
            int i;
            double[] values = this.ListDoubleData.ToArray();
            bool useTechnicalAnalysis = Properties.Settings.Default.useTechnicalAnalysis;

            if (elmanNet == null ||
                elmanNet.NumberOfEntryNeurons != entryLayerSize)
                elmanNet = new ElmansNetwork(entryLayerSize, hiddenLayerSize, 1, useTechnicalAnalysis);

            double[] val = new double[entryLayerSize];
            double[] correct = new double[exitLayerSize];

            for (i = 0; i < values.Length - entryLayerSize - exitLayerSize; ++i)
            {
                for (int j = 0; j < entryLayerSize; ++j)
                {
                    val[j] = values[i + j];
                }
                for (int j = 0; j < exitLayerSize; ++j)
                {
                    correct[j] = values[i + j + entryLayerSize];
                }
                double oMin, oMax;
                this.Normalize( ref val, ref correct, out oMin, out oMax);
                for (int k = 0; k < exitLayerSize; k++)
                {
                    double[] temp = new double[1];
                    temp[0] = correct[k];
                    elmanNet.Learn(val, temp);
                    for (int l = 1; l < entryLayerSize; l++)
                        val[l - 1] = val[l];
                    val[entryLayerSize - 1] = correct[k];
                }
            }
            return elmanNet;
        }
Beispiel #2
0
        public void SaveNetwork(ElmansNetwork elmanNet)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Pliki xml (*.xml)|*.xml";
            sfd.Title = "Wybierz plik z sieci¹";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                //Opens a file and serializes the object into it in binary format.
                Stream stream = File.Open(sfd.FileName, FileMode.Create);
                SoapFormatter formatter = new SoapFormatter();

                //BinaryFormatter formatter = new BinaryFormatter();

                formatter.Serialize(stream, elmanNet);
                stream.Close();
            }
        }
Beispiel #3
0
        private void learnNetworkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //TODO
            if (data == null || data.Count == 0)
            {
                MessageBox.Show("Wczytaj zestaw ucz¹cy");
                return;
            }
            if (data.Count < Properties.Settings.Default.entryLayerSize)
            {
                MessageBox.Show("Wczytany zestaw ucz¹cy zawiera zbyt ma³o danych.\nWczytaj wiêcej danych lub zmieñ ustawienia sieci.");
                return;
            }

            this.elmanNet = this.data.Learn(this.elmanNet);

            if (data != null && elmanNet != null && data.Count >= elmanNet.NumberOfEntryNeurons)
            {
                this.performEstimationToolStripMenuItem.Enabled = true;
                double error = elmanNet.CountError();
                MessageBox.Show("Sieæ nauczona. B³¹d œredniokwadratowy: " + error);
                this.elmanNetErrorTextBox.Text = error.ToString();
                this.elmanNetErrorPanel.Visible = true;
            }
        }
Beispiel #4
0
 private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //network parameters changed
     if (settingsForm.ShowDialog() == DialogResult.OK)
     {
         elmanNet = null;
     }
 }
Beispiel #5
0
 private void newNetworkToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if(this.data != null)
         this.data.ClearData();
     this.dataGraph1.ClearData();
     this.dataGraph1.Refresh();
     this.elmanNet = null;
     this.elmanNetErrorPanel.Visible = false;
     this.exitValuesMatrixPreview.Visible = false;
 }
Beispiel #6
0
 private void NetworkTest()
 {
     elmanNet = new ElmansNetwork(5, 2, 1, Properties.Settings.Default.useTechnicalAnalysis);
     double[] learn = new double[] { 1, 2, 3, 4, 5 };
     double[] correct = new double[] { 6 };
     //double[] test = new double[] { 7, 7, 7, 7, 7 };
     double[] test = new double[] { 1, 2, 3, 4, 5 };
     double oMin, oMax;
     this.data.Normalize(ref learn, ref correct, out oMin, out oMax);
     for(int i=0;i<100;++i)
     {   elmanNet.Learn(learn, correct);
         }
     learn = new double[] { 6, 7, 8, 9, 10 };
     correct = new double[] { 11 };
     this.data.Normalize(ref learn, ref correct, out oMin, out oMax);
     //elmanNet.Learn(learn, correct);
     this.data.Normalize(ref test, out oMin, out oMax);
     double[] exit = elmanNet.ComputeExitValues(test);
        // MessageBox.Show(exit[0].ToString());
     this.data.DeNormalize(ref exit, oMin, oMax);
     this.exitValuesMatrixPreview.BuildControl(exit);
 }
Beispiel #7
0
 private void loadNetworkToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //TODO
     this.elmanNet = this.data.LoadNetwork();
     this.elmanNetErrorPanel.Visible = false;
 }