public override PatternResult Train(List <Pattern> patterns, int iterations) { double error = 0.0; if (patterns.Count == 0) { return(null); } foreach (string c in charsSet) { DoubleVectorList inputs = new DoubleVectorList(); DoubleVectorList outputs = new DoubleVectorList(); foreach (Pattern p in patterns) { // Add every item. The solution is either "yes this is a letter X" or "no this is not a letter X" inputs.Add(p.Inputs.Scale()); if (GetOutputCharacter(p.Outputs) == c) { DoubleVector v = new DoubleVector(1); v[0] = 0.99; outputs.Add(v); } else { DoubleVector v = new DoubleVector(1); v[0] = 0.01; outputs.Add(v); } } // Train only if we have patters for this letter in our character set if (inputs.Count > 0) { // Get the specialized neural network for this specific letter error += sann.Where(nn => nn.Solution == c).ToList()[0].NeuralNet.Train(inputs, outputs, iterations); } } return(new PatternResult(error)); }
public override PatternResult Train(List <Pattern> patterns, int iterations) { if (patterns.Count == 0) { return(null); } DoubleVectorList inputs = new DoubleVectorList(); DoubleVectorList outputs = new DoubleVectorList(); foreach (Pattern p in patterns) { inputs.Add(p.Inputs.Scale(0.02, 0.98)); outputs.Add(p.Outputs); } double error = sann.Train(inputs, outputs, iterations); return(new PatternResult(error)); }
public override PatternResult Train(List<Pattern> patterns, int iterations) { double error = 0.0; if (patterns.Count == 0) { return null; } foreach (string c in charsSet) { DoubleVectorList inputs = new DoubleVectorList(); DoubleVectorList outputs = new DoubleVectorList(); foreach (Pattern p in patterns) { // Add every item. The solution is either "yes this is a letter X" or "no this is not a letter X" inputs.Add(p.Inputs.Scale()); if (GetOutputCharacter(p.Outputs) == c) { DoubleVector v = new DoubleVector(1); v[0] = 0.99; outputs.Add(v); } else { DoubleVector v = new DoubleVector(1); v[0] = 0.01; outputs.Add(v); } } // Train only if we have patters for this letter in our character set if (inputs.Count > 0) { // Get the specialized neural network for this specific letter error += sann.Where(nn => nn.Solution == c).ToList()[0].NeuralNet.Train(inputs, outputs, iterations); } } return new PatternResult(error); }
public override PatternResult Train(List<Pattern> patterns, int iterations) { if (patterns.Count == 0) { return null; } DoubleVectorList inputs = new DoubleVectorList(); DoubleVectorList outputs = new DoubleVectorList(); foreach (Pattern p in patterns) { inputs.Add(p.Inputs.Scale(0.02, 0.98)); outputs.Add(p.Outputs); } double error = sann.Train(inputs, outputs, iterations); return new PatternResult(error); }