public void Train(List <List <double> > inputs, List <List <double> > outputs, double LearningRate, int epochs, int batchSize, bool writeNet = true) { DateTime startTime = DateTime.Now; DateTime prevTime = DateTime.Now; int procents = 0; Console.ForegroundColor = ConsoleColor.Green; for (int i = 0; i < epochs; ++i) { for (int j = 0; j < inputs.Count; ++j) { Collect(inputs[j], outputs[j], LearningRate); if (i != 0 && j != 0 && (i * j + j) % batchSize == 0) { ApplyBatch(); } } if (i / (epochs / 100) != procents) { procents = i / (epochs / 100); int tms = (int)((DateTime.Now - prevTime).TotalMinutes * (100 - procents)); if (tms != 0) { Console.Write("\rЗавершено на " + procents + "% Осталось " + tms + " минут SSE=" + SSE(inputs, outputs)); } else { tms = (int)((DateTime.Now - prevTime).TotalSeconds * (100 - procents)); Console.Write("\rЗавершено на " + procents + "% Осталось " + tms + " секунд SSE=" + SSE(inputs, outputs)); } prevTime = DateTime.Now; } } ApplyBatch(); Console.Clear(); Console.WriteLine("\rDone!"); DateTime endTime = DateTime.Now; Console.WriteLine("Время обучения: " + (endTime - startTime)); if (writeNet) { ANNSerializer.WriteNet(this, "first_net", "1"); } }
static void Main(string[] args) { List <List <double> > inputs = ReadNetIO(@"input4.txt"); List <List <double> > outputs = ReadNetIO(@"output3.txt"); Shuffle(inputs); Shuffle(outputs); List <List <double> > testin = new List <List <double> >(); List <List <double> > testout = new List <List <double> >(); for (int i = 1; i < 11; ++i) { testin.Add(inputs[inputs.Count - i]); testout.Add(outputs[outputs.Count - i]); inputs.RemoveAt(inputs.Count - i); outputs.RemoveAt(outputs.Count - i); } const bool newNet = true; FeedForwardNet net; if (newNet) { const double LearningRate = 0.1; const int epochs = 10000; const int batchSize = 1; const int type = 1; net = new FeedForwardNet(); if (type == 1) { net.AddSigmoidLayer(10, 4); net.AddSigmoidLayer(5, 10); net.AddSigmoidLayer(3, 5); } else if (type == 2) { net.AddTangentialLayer(10, 4); net.AddTangentialLayer(5, 10); net.AddTangentialLayer(3, 5); } else if (type == 3) { net.AddGaussianLayer(10, 4); net.AddGaussianLayer(5, 10); net.AddGaussianLayer(3, 5); } else if (type == 4) { net.AddGaussianLayer(10, 4); net.AddSigmoidLayer(5, 10); net.AddTangentialLayer(3, 5); } net.Train(inputs, outputs, LearningRate, epochs, batchSize); } else { net = ANNSerializer.ReadNet(@"first_net/1.ann"); } for (int i = 0; i < outputs.Count; ++i) { List <double> result = net.Calculate(inputs[i]); Console.ForegroundColor = ConsoleColor.White; for (int j = 0; j < inputs[i].Count; ++j) { Console.Write(inputs[i][j] + " "); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(i + " " + ConvertToIris(result) + " "); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(ConvertToIris(outputs[i]) + "\n"); } Console.WriteLine("Tests:"); for (int i = 0; i < testin.Count; ++i) { List <double> result = net.Calculate(testin[i]); Console.ForegroundColor = ConsoleColor.White; for (int j = 0; j < testin[i].Count; ++j) { Console.Write(testin[i][j] + " "); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(i + " " + ConvertToIris(result) + " "); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(ConvertToIris(testout[i]) + "\n"); } }