Ejemplo n.º 1
0
        private void ResetSimulations()
        {
            foreach (var simulation in simulations)
            {
                simulation.Reset();
            }

            TrainSeriesSource.Clear();
            TestSeriesSource.Clear();
            latexFile.Clear();
            EnableButtons();
        }
Ejemplo n.º 2
0
        private void TrainSimulation(int simulationNumber, bool allSimlations = false)
        {
            if (trainTimer != null)
            {
                trainTimer.Stop();
                trainTimer = null;
            }

            int epoch      = 0;
            var simulation = simulations[simulationNumber];
            int maxEpoch   = allSimlations ? simulation.MaxEpoch : -1;

            currentSimulationNumber = simulationNumber;

            if (simulation.Config.Network == "SOMNetwork")
            {
                ShowColorWindow();
                colorWindow?.Update(simulations?[currentSimulationNumber]?.GetFeature(0, new List <float>()));
            }

            trainTimer          = new Timer();
            trainTimer.Interval = 1;
            trainTimer.Tick    += (s, args) =>
            {
                float error = 0;

                if (simulations?[currentSimulationNumber]?.Config.Network == "SOMNetwork")
                {
                    error = simulation.TrainSOM();

                    if (true || epoch % 10 == 0)
                    {
                        colorWindow?.Update(simulations?[currentSimulationNumber]?.GetFeature(0, new List <float>()));
                    }
                }
                else
                {
                    error = simulation.TrainAutoencoder(imageParser.TrainData);
                    //float correctTrain = simulation.TestSoftMax(imageParser.TrainData);
                    //float correctTest = simulation.TestSoftMax(imageParser.TestData);

                    //AddTrainSeriesValue(correctTrain);
                    //AddTestSeriesValue(correctTest);
                }

                AddTrainSeriesValue(error);

                //LogSimulationTrainStep(simulation, simulationNumber, epoch, correctTrain, correctTest);

                epoch++;
                if (maxEpoch > 0 && epoch >= maxEpoch)
                {
                    trainTimer.Dispose();
                }
            };

            trainTimer.Start();
            trainTimer.Disposed += (sender, args) =>
            {
                if (simulationNumber + 1 < simulations.Count)
                {
                    TrainSeriesSource.Clear();
                    TestSeriesSource.Clear();
                    epoch = 0;
                    TrainSimulation(simulationNumber + 1, allSimlations);
                }
                else
                {
                    latexFile.Generate(imageParser.TestData);
                    StopBtn.IsEnabled = false;
                    LoadBtn.IsEnabled = true;
                    EnableButtons();
                    MessageBox.Show("Success");
                }
            };
        }