protected async Task BeginTrainNetwork() { await Task.Factory.StartNew(() => { lock (locker) { ReadyToTrain = false; Training = true; IsRunning = true; Status = "Training"; var localIteration = 0; var rand = new Random(); var width = (int)Math.Sqrt(network.Layers[0].Neurons.Length); var trainer = new SOMTrainer(width, width, network); var fixedLearningRate = LearningRate / 10.0; var driftingLearningRate = fixedLearningRate * 9.0; var maxIterations = Iterations + CurrentIteration; var input = new double[3]; while (CurrentIteration < maxIterations && IsRunning) { trainer.LearningRate = driftingLearningRate * (Iterations - localIteration) / Iterations + this.LearningRate; trainer.LearningRadius = (double)ClusterRadius * (Iterations - localIteration) / Iterations; for (var i = 0; i < input.Length; i++) { input[i] = rand.NextDouble(); } trainer.Run(input); if (CurrentIteration % RefreshRate == 0) { try { BitMap.Dispatcher.Invoke(UpdateMap); } catch (TaskCanceledException) { } } CurrentIteration++; localIteration++; } BitMap.Dispatcher.Invoke(UpdateMap); Status = "Ready"; Training = false; ReadyToTrain = true; } }); }