private void button2_Click(object sender, EventArgs e) { Random rng = new Random(); int iter = (int)(numIterations.Value); List <NormalizedDonor> norms = new List <NormalizedDonor>(); for (int i = 0; i < iter; i++) { NormalizedDonor d = TrainingDonors[rng.Next(TrainingDonors.Count)]; norms.Add(d); double[] ins = { d.Year, d.OperationYear, d.AxillaryNodes }; double[] ots = { d.Status }; nn.Train(new List <double>(ins), new List <double>(ots)); } int hits = 0; foreach (NormalizedDonor n in norms) { double[] ins = { n.Year, n.OperationYear, n.AxillaryNodes }; double rez = nn.Run(new List <double>(ins))[0]; if (Math.Abs(rez - n.Status) < 0.5) { hits++; } } lblTrainAcc.Text = String.Format("Paskutinio apmokymo tikslumas: {0:0.00}%", (100.0 * hits) / iter); NetworkHelper.ToTreeView(treeView1, nn); NetworkHelper.ToPictureBox(pictureBox1, nn, 400, 100); }
private void button2_Click(object sender, EventArgs e) { List <double> ins = new List <double>(); ins.Add(0); ins.Add(1); List <double> ots = new List <double>(); ots.Add(0); //ots.Add(0); for (int i = 0; i < 100000; i++) { nn.Train(ins, ots); } NetworkHelper.ToTreeView(treeView1, nn); NetworkHelper.ToPictureBox(pictureBox1, nn, 400, 100); }
static void Main(string[] args) { string result_file = @"\\Mac\Home\Desktop\mnist\result.csv"; List <double> accuracyValues = new List <double>(); double[] learningRates = { 0.2, 0.01, 0.1, 0.02, 0.3, 0.03, 0.4, 0.04 }; double learningRate = 0.1; // NeuralNetwork neuralnet = new NeuralNetwork(784, 10, 1, 45); Tuple <double, double> loss_accuracy; List <Tuple <int, double, Tuple <double, double>, Tuple <double, double> > > result = new List <Tuple <int, double, Tuple <double, double>, Tuple <double, double> > >(); //double accuracy = 0; string format = "{0, -15}{1,-15}{2,-15}{3, -25}{4, -25}{5, -25}"; string[] heading = new string[] { "Epoch", "Learning Rate", "Training Loss", "Testing Loss", "Training Accuracy", "Testing Accuracy" }; Console.WriteLine(string.Format(format, heading)); foreach (var learning_rate in learningRates) { NeuralNetwork neuralnet = new NeuralNetwork(784, 10, 1, 45); for (var epoch = 0; epoch < 10; ++epoch) { neuralnet.Train(MnistReader.TrainImagesPath, MnistReader.TrainLabelsPath, learning_rate); // evaluate on training data var trainingMetric = neuralnet.evaluate(MnistReader.TrainImagesPath, MnistReader.TrainLabelsPath); // evaluate on test data var testingMetric = neuralnet.evaluate(MnistReader.TestImagesPath, MnistReader.TestLabelsPath); result.Add(Tuple.Create(epoch, learning_rate, trainingMetric, testingMetric)); string[] row = new string[] { epoch.ToString(), learning_rate.ToString(), trainingMetric.Item1.ToString(), testingMetric.Item1.ToString(), trainingMetric.Item2.ToString(), testingMetric.Item2.ToString() }; Console.WriteLine(string.Format(format, row)); Utils.writeCSv(result_file, result); } } }
private void btnTrain_Click(object sender, EventArgs e) { settings = checkSettings(); System.Threading.Thread t = new System.Threading.Thread(() => { NeuralNetwork n = null; System.Threading.Thread myThread = new System.Threading.Thread(() => { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); n = NeuralNetwork.Train(settings); }); myThread.Start(); myThread.Join(); myNeuralNetwork1 = n; isTraining = false; }); if (settings.containsErrors) { } else if (!isTraining) { this.progressBar1.Maximum = settings.MaxGens + 1; this.progressBar1.Visible = true; t.Name = "NetTrain"; t.Start(); isTraining = true; btnTrain.Text = "Stop"; } else if (isTraining) { NeuralNetwork.Interrupt(); btnTrain.Text = "Train!"; } }