public void straight() { int size = 25; vnn nn = new vnn(size, 500, size, addon.RandomizeWeights); var tr = new trainerModern(nn); List <double[]> history = new List <double[]>(); trainingSet tset; Stopwatch sw = Stopwatch.StartNew(); int counter = 0; var rand = new Random(); do { var data = new double[size]; data[rand.Next(0, data.Length)] = 1.0; history.Add(data); tset = new trainingSet(history.ToArray(), history.ToArray()); tr.TrainEpoch(tset.inputs, tset.outputs, 0.02, 0.9); //tr.TrainOne(data, data, 0.1, 0.9); counter++; Console.Title = $"{counter} ({counter * tset.size})"; }while (tset.getAccuracy(nn, 0.1) < 0.9); WriteLine("Elapsed = " + sw.ElapsedMilliseconds + " ms."); WriteLine("MSE = " + tset.getMSE(nn)); WriteLine("Random MSE = " + tset.getRandomMSE(nn, 500)); nn.TestLoop(new Func <double[], double[]>(arr => new double[] { arr[0] > 0.5 ? 1 : 0, Sin(arr[0] + arr[1]) * arr[0] })); }
public sortingTest() { int n = 3; var nn = new vnn(n, 100, n); var tr = new trainer(nn, data.DataSets.sorting(n), 0.1, 0.9); tr.TrainFor(10000); System.IO.File.WriteAllBytes("E:\\OneDrive\\Other\\Temp\\tempNN", nn.ToBytes()); WriteLine("MSE = " + tr.getMSE()); WriteLine("Acc = " + tr.getAccuracy(1 / (double)n)); nn.TestLoop(); }
public void bounded_substraction() { /// <summary> /// WORKS!!!! :) /// Testing if hearthstone health and atack should be one in one input neuron or in whole 'one-hot' input vector /// </summary> vnn nn = new vnn(2, 100, 1, addon.RandomizeWeights); var tr = new trainerModern(nn); var tset = getSet(1000); Stopwatch sw = Stopwatch.StartNew(); int counter = 0; do { tr.TrainEpoch(tset.inputs, tset.outputs, 0.1, 0.9); counter++; Console.Title = $"{counter} ({counter * tset.size})"; }while (tset.getAccuracy(nn, 0.05) < 1); WriteLine("Elapsed = " + sw.ElapsedMilliseconds + " ms."); WriteLine("MSE = " + tset.getMSE(nn)); nn.TestLoop(input_translator, output_translator); //nn.TestLoop(); const int maxVal = 10; string output_translator(double[] arr) { int output = (int)Round(arr[0] * maxVal); return(output.ToString()); } double[] input_translator(string text) { string[] split = text.Split(' '); int a = int.Parse(split[0]); double da = a / (double)maxVal; int b = int.Parse(split[1]); double db = b / (double)maxVal; return(new double[] { da, db }); } trainingSet getSet(int size) { var rand = new Random(); double[][] inp = new double[size][], outp = new double[size][]; for (int i = 0; i < size; i++) { int a = rand.Next(0, maxVal); double da = a / (double)maxVal; int b = rand.Next(0, maxVal); double db = b / (double)maxVal; int answer = Max(0, a - b); double dansw = answer / (double)maxVal; inp[i] = new double[] { da, db }; outp[i] = new double[] { dansw }; } return(new trainingSet(inp, outp)); } }