protected uint vPeriod = 5; // validation period. #endregion Fields #region Constructors // // public TrainingAlgorithm(BackPropNet net, string tPatterns, string tTargets) { uint depth = net.Depth; // try { // allocate mem for matrices of error gradients errGrad = new double[depth-1][,]; // allocate mem for depth-1 vectors // for(uint i=0; i<depth-1; i++) { uint temp1 = net.GetLayer(i).GetSize(); uint temp2 = net.GetLayer(i+1).GetSize(); // errGrad[i] = new double[temp1, temp2]; } // // this.trPatterns = new DataSet(tPatterns); this.trTargets = new DataSet(tTargets); this.network = net; // if(trPatterns.GetNumberOfVectors() != trTargets.GetNumberOfVectors()) throw new Exception("Datasets have different number of vectors."); if(trPatterns.GetDataValidation() != true || trTargets.GetDataValidation() != true) throw new Exception("Invalid Data"); if(trPatterns.GetLengthOfVectors() != net.GetLayer(0).GetSize() || trTargets.GetLengthOfVectors() != net.GetLayer(net.Depth-1).GetSize()) throw new Exception("Incosistent Data/Inputs or Data/Outputs"); } catch(Exception ex) { Console.WriteLine(ex.Message); throw; } }
// public void SetValidationData(string vPatterns, string vTargets) { try { this.vaPatterns = new DataSet(vPatterns); this.vaTargets = new DataSet(vTargets); // if(vaPatterns.GetNumberOfVectors() != vaTargets.GetNumberOfVectors()) throw new Exception("Datasets have different number of vectors."); if(vaPatterns.GetDataValidation() != true || vaTargets.GetDataValidation() != true) throw new Exception("Invalid Data"); if(vaPatterns.GetLengthOfVectors() != network.GetLayer(0).GetSize() || vaTargets.GetLengthOfVectors() != network.GetLayer(network.Depth-1).GetSize()) throw new Exception("Incosistent Data/Inputs or Data/Outputs"); this.validate = true; } catch(Exception ex) { Console.WriteLine(ex.Message); this.validate = false; throw; } }
// public void SetData(NeuralLib.DataSet pat, NeuralLib.DataSet tar) { patterns = pat; targets = tar; // if(patterns.GetDataValidation() != true || targets.GetDataValidation() != true || patterns.GetNumberOfVectors() != targets.GetNumberOfVectors()) throw new Exception("Bad Patterns/Targets or vectors differ in length"); // this.CheckNetworks(); }
// 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; } }
// 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(); } }
// 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(); } }
private void button6_Click(object sender, System.EventArgs e) { string filename; // openFile.Title = "Choose Test Inputs File..."; // if(openFile.ShowDialog() == DialogResult.OK) { filename = openFile.FileName; // if(openFile.FileName != " ") { this.testInputs = filename; // try { NeuralLib.DataSet temp = new NeuralLib.DataSet(testInputs); // if(!temp.GetDataValidation()) throw new Exception("Test Inputs Data Corrupt!"); else if(temp.GetLengthOfVectors() != Convert.ToInt32(cbInputNeurons.SelectedItem)) throw new Exception("Test Inputs Vector Size NOT EQUAL to Network's Number Of Input Neurons!"); else MessageBox.Show("Test Inputs Loaded!", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch(System.Exception ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Choose AGAIN Test Inputs!", "Warning"); this.testInputs = null; } } } }