Beispiel #1
0
 //
 public double Simulate(DataSet patterns, DataSet targets)
 {
     double  err = 0.0;
     double  sim = 0.0;
     //
     try
     {
         if(patterns.GetLengthOfVectors() != iLayer.GetSize() || targets.GetLengthOfVectors() != oLayer.GetSize())
             throw new Exception("Input/Target Vectors Invalid with Input/Output Layer Size");
         //
         if(patterns.GetDataValidation() == true && targets.GetDataValidation() == true
             && patterns.GetNumberOfVectors() == targets.GetNumberOfVectors())
         {
             for(int i=0; i<patterns.GetNumberOfVectors(); i++)
             {
                 this.SetInputVector(patterns.GetDataVector(i));
                 this.SetTargetVector(targets.GetDataVector(i));
                 this.FeedForward();
                 this.CalculateOutputError();
                 err = this.GetInstantOutputError();
                 sim += err;
             }
             //
         }
         else
         {
             throw new Exception("Invalid Simulation Data");
         }
         //
         return sim/patterns.GetNumberOfVectors();
     }
     catch(System.Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw;
     }
 }
Beispiel #2
0
 //
 public void Simulate(DataSet ds, string results)
 {
     string filename = results;
     //
     StreamWriter writer = new StreamWriter(filename, false);
     //
     try
     {
         //
         if(ds.GetLengthOfVectors() != iLayer.GetSize())
             throw new Exception("Input Vector Length differs from Input Layer's Size");
         //
         if(ds.GetDataValidation())
         {
             for(int i=0; i<ds.GetNumberOfVectors(); i++)
             {
                 this.SetInputVector(ds.GetDataVector(i));
                 this.FeedForward();
                 //
                 foreach(double d in this.oLayer.GetOutputVector())
                 {
                     writer.Write(d.ToString("F4")+" ");
                 }
                 //
                 writer.Write("\n");
             }
         }
         else
         {
             writer.WriteLine("Invalid Simulation Data");
         }
         //
         writer.Flush();
         writer.Close();
     }
     catch(System.Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw;
     }
     finally
     {
         writer.Close();
     }
 }
Beispiel #3
0
 //
 public void Simulate(DataSet patterns, DataSet targets, string results)
 {
     double  err = 0.0;
     double  sim = 0.0;
     //
     string filename = results;
     StreamWriter writer = new StreamWriter(filename, false);
     //
     try
     {
         if(patterns.GetLengthOfVectors() != iLayer.GetSize() || targets.GetLengthOfVectors() != oLayer.GetSize())
             throw new Exception("Input/Target Vectors Invalid with Input/Output Layer Size");
         //
         if(patterns.GetDataValidation() == true && targets.GetDataValidation() == true
             && patterns.GetNumberOfVectors() == targets.GetNumberOfVectors())
         {
             for(int i=0; i<patterns.GetNumberOfVectors(); i++)
             {
                 this.SetInputVector(patterns.GetDataVector(i));
                 this.SetTargetVector(targets.GetDataVector(i));
                 this.FeedForward();
                 this.CalculateOutputError();
                 err = this.GetInstantOutputError();
                 sim += err;
                 //
                 foreach(double d in this.oLayer.GetOutputVector())
                 {
                     writer.Write(d.ToString("F6")+" ");
                 }
                 //
                 writer.Write(err.ToString("E6"));
                 writer.Write("\n");
             }
             //
             Console.WriteLine("Average Simulation Error: {0:E6}", sim/patterns.GetNumberOfVectors());
         }
         else
         {
             writer.WriteLine("Invalid Simulation Data");
             throw new Exception("Invalid Simulation Data");
         }
         //
         writer.Flush();
         writer.Close();
     }
     catch(System.Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw;
     }
     finally
     {
         writer.Close();
     }
 }
Beispiel #4
0
        //
        private void button5_Click(object sender, System.EventArgs e)
        {
            string filename = null;
            //
            if(sf.ShowDialog() == DialogResult.OK && of.FileName != " ")
            {
                filename = sf.FileName;
                //
                try
                {

                    if(patterns != null)
                    {
                        if(targets != null)
                            network.Simulate(patterns, targets, filename);
                        else
                            network.Simulate(patterns, filename);
                    }
                    //
                    MessageBox.Show("Simulation Finished", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch(System.Exception ex)
                {
                    MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    patterns = null;
                    patterns = null;
                    network  = null;
                    this.button3.Enabled = false;
                    this.button4.Enabled = false;
                    this.button5.Enabled = false;
                }
            }
            //
            if(targets != null)
            {
                NeuralLib.DataSet dset = new NeuralLib.DataSet(filename);
                //
                double[] dummy;
                //
                chart1.Series.Clear();
                chart1.OpenData(COD.Values, 0, dset.GetNumberOfVectors());
                if(network.GetLayer(network.Depth-1).GetSize() == 1)
                {
                    // network has one output neuron.
                    chart1.AxisY.Title.Text = "Real Output-Simulated Output";
                    double sse = 0.0;
                    for(int i=0; i<dset.GetNumberOfVectors(); i++)
                    {
                        dummy = dset.GetDataVector(i);
                        chart1.Value[0, i] = targets.GetDataVector(i)[0];
                        chart1.Value[1, i] = dummy[0];
                        sse += dummy[dummy.Length-1];
                    }
                    //
                    label1.Text = "SSE: "+sse.ToString("F6")+" MSE: "+(sse/dset.GetNumberOfVectors()).ToString("F6")+" RMSE: "+
                        Math.Sqrt(sse/dset.GetNumberOfVectors()).ToString("F6");
                }
                else
                {
                    chart1.AxisY.Title.Text = "RMSE";
                    double sse = 0.0;
                    for(int i=0; i<dset.GetNumberOfVectors(); i++)
                    {
                        dummy = dset.GetDataVector(i);
                        chart1.Value[0, i] = Math.Sqrt(dummy[dummy.Length-1]);
                        sse += dummy[dummy.Length-1];
                    }
                    label1.Text = "SSE: "+sse.ToString("F6")+" MSE: "+(sse/dset.GetNumberOfVectors()).ToString("F6")+" RMSE: "+
                        Math.Sqrt(sse/dset.GetNumberOfVectors()).ToString("F6");
                }
                //
                label1.Left = chart1.Left+chart1.Width/2-label1.Width/2;
                chart1.CloseData(COD.Values);
                chart1.RecalcScale();
                chart1.Refresh();
            }
        }