static void Main(string[] args) { FeedforwardNetwork network = new FeedforwardNetwork(); network.AddLayer(new FeedforwardLayer(2)); network.AddLayer(new FeedforwardLayer(3)); network.AddLayer(new FeedforwardLayer(1)); network.Reset(); // train the neural network TrainingSetNeuralGeneticAlgorithm train = new TrainingSetNeuralGeneticAlgorithm( network, true, XOR_INPUT, XOR_IDEAL, 5000, 0.1, 0.25); int epoch = 1; do { train.Iteration(); Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error); epoch++; } while ((epoch < 5000) && (train.Error > 0.001)); network = train.Network; // test the neural network Console.WriteLine("Neural Network Results:"); for (int i = 0; i < XOR_IDEAL.Length; i++) { double [] actual = network.ComputeOutputs(XOR_INPUT[i]); Console.WriteLine(XOR_INPUT[i][0] + "," + XOR_INPUT[i][1] + ", actual=" + actual[0] + ",ideal=" + XOR_IDEAL[i][0]); } }
/// <summary> /// Create, train and use a neural network for XOR. /// </summary> /// <param name="args">Not used</param> static void Main(string[] args) { FeedforwardNetwork network = new FeedforwardNetwork(); network.AddLayer(new FeedforwardLayer(2)); network.AddLayer(new FeedforwardLayer(3)); network.AddLayer(new FeedforwardLayer(1)); network.Reset(); // train the neural network Train train = new HeatonResearchNeural.Feedforward.Train.Backpropagation.Backpropagation(network, XOR_INPUT, XOR_IDEAL, 0.7, 0.9); int epoch = 1; do { train.Iteration(); Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error); epoch++; } while ((epoch < 5000) && (train.Error > 0.001)); // test the neural network Console.WriteLine("Neural Network Results:"); for (int i = 0; i < XOR_IDEAL.Length; i++) { double[] actual = network.ComputeOutputs(XOR_INPUT[i]); Console.WriteLine(XOR_INPUT[i][0] + "," + XOR_INPUT[i][1] + ", actual=" + actual[0] + ",ideal=" + XOR_IDEAL[i][0]); } }
private Suit ScanSuit(Bitmap bmp) { int height = bmp.Height; int width = bmp.Width; var lista = new List <double>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var c = bmp.GetPixel(x, y); if (c.R < 200) { lista.Add(1.0); } else { lista.Add(0.0); } } } double[] saida = NetworkSuits.ComputeOutputs(lista.ToArray()); double comp = 0.0; int pos = 0; for (int i = 0; i < saida.Length; i++) { if (saida[i] > 0.3 && saida[i] > comp) { comp = saida[i]; pos = i + 1; } } if (pos == 1) { return(Suit.Hearts); } if (pos == 2) { return(Suit.Spades); } if (pos == 3) { return(Suit.Diamonds); } if (pos == 4) { return(Suit.Clubs); } return(Suit.NOT_RECOGNIZED); }
/// <summary> /// Scans rank of face cards /// </summary> /// <param name="cardImage"></param> /// <returns></returns> private Rank ScanFaceRank(Bitmap bmp) { int height = bmp.Height; int width = bmp.Width; var lista = new List <double>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var c = bmp.GetPixel(x, y); if (c.R < 200) { lista.Add(1.0); } else { lista.Add(0.0); } } } double comp = 0.0; int pos = 0; double[] saida = NetworkLetra.ComputeOutputs(lista.ToArray()); for (int i = 0; i < saida.Length; i++) { if (saida[i] > 0.3 && saida[i] > comp) { comp = saida[i]; pos = i + 1; } } if (pos == 1) { return(Rank.Ace); } if (pos == 2) { return(Rank.Jack); } if (pos == 3) { return(Rank.King); } if (pos == 4) { return(Rank.Queen); } return(Rank.NOT_RECOGNIZED); }
static void Main(string[] args) { input = GetInput(); label = GetLabel(); FeedforwardNetwork network = new FeedforwardNetwork(); network.AddLayer(new FeedforwardLayer(4)); network.AddLayer(new FeedforwardLayer(5)); network.AddLayer(new FeedforwardLayer(1)); network.Reset(); // train the neural network TrainingSetNeuralGeneticAlgorithm train = new TrainingSetNeuralGeneticAlgorithm( network, false, input, label, 5000, 0.1, 0.25); int epoch = 1; do { train.Iteration(); Console.WriteLine("Epoch #" + epoch + " Error:" + train.Error); epoch++; } while ((epoch < 5000) && (train.Error > 0.001)); network = train.Network; // test the neural network Console.WriteLine("Neural Network Results:"); for (int i = 0; i < label.Length; i++) { double[] actual = network.ComputeOutputs(input[i]); Console.WriteLine(input[i][0] + "," + input[i][1] + ", actual=" + actual[0] + ",ideal=" + label[i][0]); } }
/// <summary> /// Scans rank of card and returns result. /// For recognizing rank, counts suits on image /// </summary> /// <param name="cardImage">Card image to be scanned</param> /// <returns>Rank of card</returns> private Rank ScanRank(Bitmap bmp) { int height = bmp.Height; int width = bmp.Width; var lista = new List <double>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var c = bmp.GetPixel(x, y); if (c.R < 200) { lista.Add(1.0); } else { lista.Add(0.0); } } } double comp = 0.0; int pos = 0; double[] saida = NetworkNumero.ComputeOutputs(lista.ToArray()); for (int i = 0; i < saida.Length; i++) { if (saida[i] > 0.5 && saida[i] > comp) { comp = saida[i]; pos = i + 1; } } if (comp > 0.5) { if (pos == 1) { return(Rank.Two); } if (pos == 2) { return(Rank.Three); } if (pos == 3) { return(Rank.Four); } if (pos == 4) { return(Rank.Five); } if (pos == 5) { return(Rank.Six); } if (pos == 6) { return(Rank.Seven); } if (pos == 7) { return(Rank.Eight); } if (pos == 8) { return(Rank.Nine); } if (pos == 9) { return(Rank.Ten); } if (pos == 10) { return(Rank.Ace); } } return(Rank.NOT_RECOGNIZED); }