private static void Main() { try { Console.WriteLine("\nBegin neural network classification demo\n"); Console.WriteLine("Goal is to predict/classify color based on four numeric inputs\n"); _rnd = new Random(159); // 159 makes 'good' output Console.WriteLine("Creating 100 lines of raw data"); string dataFile = "..\\..\\colors.txt"; MakeData(dataFile, 100); Console.WriteLine("\nFirst few rows of raw data file are:"); Helpers.ShowTextFile(dataFile, 4); double[][] trainMatrix; double[][] testMatrix; Console.WriteLine("\nGenerating train and test matrices using an 80%-20% split"); MakeTrainAndTest(dataFile, out trainMatrix, out testMatrix); Console.WriteLine("\nFirst few rows of training matrix are:"); Helpers.ShowMatrix(trainMatrix, 5); Console.WriteLine("\nCreating 4-input 5-hidden 3-output neural network"); var nn = new NeuralNetwork(4, 5, 3); Console.WriteLine("Training to find best neural network weights using PSO with cross entropy error"); double[] bestWeights = nn.Train(trainMatrix); Console.WriteLine("\nBest weights found:"); Helpers.ShowVector(bestWeights, 2, true); Console.WriteLine("\nLoading best weights into neural network"); nn.SetWeights(bestWeights); Console.WriteLine("\nAnalyzing the neural network accuracy on the test data\n"); double accuracy = nn.Test(testMatrix); Console.WriteLine("Prediction accuracy = " + accuracy.ToString("F4")); Console.WriteLine("\nEnd neural network classification demo\n"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("Fatal: " + ex.Message); Console.ReadLine(); } }
static void Main(string[] args) { try { Console.WriteLine("\nBegin neural network classification demo\n"); Console.WriteLine("Goal is to predict result of game"); double[][] trainMatrix = null; double[][] testMatrix = null; Console.WriteLine("\nGenerating train and test matrices using an 80%-20% split"); string dataFile = @"C:\Users\theok\Documents\Projects\NN\NN\nninput.txt"; MakeTrainAndTest(dataFile, out trainMatrix, out testMatrix); Console.WriteLine("\nFirst few rows of training matrix are:"); Helpers.ShowMatrix(trainMatrix, 5); Console.WriteLine("\nCreating 4-input 5-hidden 3-output neural network"); NeuralNetwork nn = new NeuralNetwork(Configuration.howManyInputNeurons, Configuration.howManyHiddenNeurons, Configuration.howManyOutputNeurons); Console.WriteLine("Training to find best neural network weights using PSO with cross entropy error"); double[] bestWeights = nn.Train(trainMatrix); Console.WriteLine("\nBest weights found:"); Helpers.ShowVector(bestWeights, 2, true); Console.WriteLine("\nLoading best weights into neural network"); nn.SetWeights(bestWeights); Console.WriteLine("\nAnalyzing the neural network accuracy on the test data\n"); double accuracy = nn.Test(testMatrix); Console.WriteLine("Prediction accuracy = " + accuracy.ToString("F4")); Console.WriteLine("\nEnd neural network classification demo\n"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("Fatal: " + ex.Message); Console.ReadLine(); } } // Main()