Beispiel #1
0
        private void HandleAlgorithmResult(Task task)
        {
            ButtonStop.Dispatcher?.Invoke(() => ButtonStop.IsEnabled = false);

            var trainedNetwork = _algorithm.GetTrainedNeuralNetwork();
            var testingData    = _algorithm.DataSet[DataType.Testing];

            var predictions = testingData.Attributes
                              .Select(testingDataAttribute => trainedNetwork.GetResult(testingDataAttribute).ToList())
                              .ToList();

            RectangleDataGridTest.Dispatcher?.Invoke(() => RectangleDataGridTest.Visibility = Visibility.Visible);
            DataGridTest.Dispatcher?.Invoke(() =>
            {
                DataGridHelper.SetTableData(DataGridTest, new TableData(predictions, testingData));
                DataGridTest.Visibility = Visibility.Visible;
            });

            _algorithm = null;

            ButtonStart.Dispatcher?.Invoke(() =>
            {
                ButtonStart.IsChecked = false;
                ButtonStart.IsEnabled = true;
            });
        }
Beispiel #2
0
        private void ButtonStartAlgorithm_Click(object sender, RoutedEventArgs e)
        {
            if (_algorithm != null)
            {
                var s = ((ToggleButton)sender).IsChecked;
                _algorithm.IsPaused = !s ?? !_algorithm.IsPaused;
                return;
            }

            RectangleDataGridTest.Dispatcher?.Invoke(() => RectangleDataGridTest.Visibility = Visibility.Collapsed);
            DataGridTest.Dispatcher?.Invoke(() =>
            {
                DataGridTest.Visibility = Visibility.Collapsed;
            });

            AlgorithmErrorValues.Clear();
            AlgorithmValidationValues.Clear();

            var neuralNetwork    = SmartGenAlgorithm.CreateNeuralNetwork();
            var geneticAlgorithm = SmartGenAlgorithm.CreateGeneticAlgorithm(neuralNetwork.GetConnectionCount());

            if (Settings.Default.InputLayerSize < Data.Attributes.First().Count)
            {
                var correlation = Correlation.GetCorrelation(Data);
                Data = Data.RemoveLeastRelevantColumn(correlation, Settings.Default.InputLayerSize);
            }

            var dataSets = Data.SplitData(Settings.Default.TrainingRatio,
                                          Settings.Default.TestRatio,
                                          Settings.Default.ValidationRatio);

            _algorithm = new SmartGenAlgorithm(geneticAlgorithm, neuralNetwork)
            {
                DataSet        = dataSets,
                ErrorTolerance = Settings.Default.ErrorTolerance,
                MaxIterations  = Settings.Default.MaxGenerationCount
            };

            _algorithm.IterationEvent += (iteration, error, validationError) =>
            {
                var current = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                if (current - _milliseconds < 500)
                {
                    return;
                }
                _milliseconds = current;

                AlgorithmErrorValues.Add(new ObservablePoint(iteration, error));
                AlgorithmValidationValues.Add(new ObservablePoint(iteration, validationError));

                if (AlgorithmErrorValues.Count <= 11)
                {
                    return;
                }

                AlgorithmErrorValues.RemoveAt(0);
                AlgorithmValidationValues.RemoveAt(0);
            };

            _algorithmTask = Task.Run(() => _algorithm.Run());
            _algorithmTask.ContinueWith(HandleAlgorithmResult);
            ButtonStop.IsEnabled = true;
        }