public static void simple_portable(vnn nn) { //var tr = new trainerModern(nn); var tr = new trainerNoMomentum(nn); var tset = data.DataSets.twoParamTest; Stopwatch sw = Stopwatch.StartNew(); const double ACCRATE = 0.05; for (int i = 0; i < 500; i++) { //tr.TrainEpoch(tset.inputs, tset.outputs, 0.1, 0.9); for (int j = 0, to = tset.size; j < to; j++) { tr.TrainOne(tset.inputs[j], tset.outputs[j], 0.1); } } var acc = tset.getAccuracy(nn, ACCRATE); // if (acc < 0.9) { throw new Exception($"Not enought accuracy: {acc.ToString("N2")}"); } WriteLine("Elapsed = " + sw.ElapsedMilliseconds + " ms."); WriteLine($"Accuracy (+-{ACCRATE}) = {acc.ToString("N2")}"); WriteLine("Random MSE = " + tset.getRandomMSE(nn, 500)); }
public void backpropagate(GameLog game) { lock (locker) { nncopy.CopyFrom(nn); } int[] idx = Enumerable.Range(0, game.ALog.Count + game.BLog.Count).ToArray(); GameEngine.rng.ShuffleRandomly(idx); double[] desired = new double[1]; double[] inputs; for (int i = 0, to = game.ALog.Count + game.BLog.Count, alen = game.ALog.Count; i < to; i++) { int index = idx[i]; if (index < alen) { inputs = game.ALog[index]; desired[0] = game.AWon.Value ? 1 : 0; } else { inputs = game.BLog[index - alen]; desired[0] = game.AWon.Value ? 0 : 1; } tr.TrainOne(inputs, desired, learningRate); } lock (locker) { nn.CopyFrom(nncopy); } }
void TrainingLoop() { while (true) { while (Pause) { Thread.Sleep(1); } if (End) { return; } lock (prog.TestingLock) { if (GetNextGame(stream, len, out var inp, out var res)) { tr.TrainOne(inp, res, 0.05); n++; }