private static void Train(BasicNetwork network, BasicMLDataSet trainingSet) { var propagation = new StochasticGradientDescent(network, trainingSet); var epoch = 1; for (var i = 0; i < 200; i++) { propagation.Iteration(1000); Console.WriteLine($"Epoch: {epoch} Error: {propagation.Error}"); epoch++; } propagation.FinishTraining(); }
void ItWorks() { var network2 = new BasicNetwork(); var data = LoadData(); var label = LoadLabel(); var network = new BasicNetwork(); network.AddLayer(new BasicLayer(null, true, 4)); network.AddLayer(new BasicLayer(new ActivationReLU(), true, 8)); network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 1)); network.Structure.FinalizeStructure(); network.Reset(); var trainingSet = new BasicMLDataSet(data, label); var propagation = new StochasticGradientDescent(network, trainingSet); var epoch = 1; for (var i = 0; i < 5000; i++) { propagation.Iteration(); Console.WriteLine($"Epoch: {epoch} Error: {propagation.Error}"); epoch++; } propagation.FinishTraining(); var weights = network.Flat.Weights; var biases = network.Flat.BiasActivation; foreach (var pair in trainingSet) { var output = network.Compute(pair.Input); Debug.Log(pair.Input[0] + "," + pair.Input[1] + ", actual=" + output[0] + ",ideal=" + pair.Ideal[0]); } }