Beispiel #1
0
        public void Start(TrainingOptions options)
        {
            if (state == SessionState.Stopped)
            {
                History.Add("Training Starting", status, options);

                string[] inputColumns  = AdaptiveSystem.Interface.GetNames(InputOutput.Input);
                string[] outputColumns = AdaptiveSystem.Interface.GetNames(InputOutput.Output);

                object dataInput  = DataSource.GetData(inputColumns, DataSourceSet.Training);
                object dataOutput = DataSource.GetData(outputColumns, DataSourceSet.Training);

                AdaptiveSystem.Preprocess.Apply(dataInput);
                AdaptiveSystem.Postprocess.Reverse(dataOutput);

                TrainingThreadParameters parameters = new TrainingThreadParameters();
                parameters.Options = this.Options.Copy();
                //parameters.Inputs = convert(dataInput);
                //parameters.Outputs = convert(dataOutput);


                backgroundWorker.RunWorkerAsync(parameters);
            }
            else if (state == SessionState.Paused)
            {
                History.Add("Training Resumed", status);
                state = SessionState.Running;
            }
        }
Beispiel #2
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TrainingThreadParameters parameters = (TrainingThreadParameters)e.Argument;
            TrainingOptions          options    = parameters.Options;

            double[][] inputs  = parameters.Inputs;
            double[][] outputs = parameters.Outputs;


            //Create Teacher
            BackPropagationLearning networkTeacher = new BackPropagationLearning(activationNetwork);

            networkTeacher.LearningRate = options.LearningRate1;
            networkTeacher.Momentum     = options.Momentum;

            //Start Training
            bool stop              = false;
            bool complete          = false;
            int  lastStatusEpoch   = 0;
            int  lastSaveEpoch     = 0;
            int  lastValidateEpoch = 0;

            backgroundWorker.ReportProgress(0, BackgroundWorkerUpdate.Starting);


            #region Main Training Loop

            while (!stop)
            {
                // Run training epoch
                status.TrainingError = networkTeacher.RunEpoch(inputs, outputs);

                if (options.Validate && status.Epoch >= lastValidateEpoch + options.ValidateEpochs)
                {
                    status.ValidationError = networkTeacher.MeasureEpochError(inputs, outputs);
                }

                // Adjust Training Rate
                if (options.ChangeLearningRate)
                {
                    networkTeacher.LearningRate = options.LearningRate2;
                }



                // Register Savepoint
                if (options.MarkSavepoints &&
                    status.Epoch >= lastSaveEpoch + options.MarkSavepointsEpochs)
                {
                    backgroundWorker.ReportProgress(0, BackgroundWorkerUpdate.NetworkSave);
                    lastSaveEpoch = status.Epoch;
                }


                // Progress Indicator
                if (options.ReportProgress &&
                    status.Epoch >= lastStatusEpoch + options.ReportProgressEpochs)
                {
                    if (options.Limit == TrainingOptions.TrainingLimit.ByError)
                    {
                        if (status.TrainingError != 0) // Check to avoid division by zero
                        {
                            status.Progress = Math.Max(Math.Min((int)((options.LimitByError * 100) / status.TrainingError), 100), 0);
                        }
                    }
                    else if (options.Limit == TrainingOptions.TrainingLimit.ByEpoch)
                    {
                        if (status.Epoch != 0) // Check to avoid division by zero
                        {
                            status.Progress = Math.Max(Math.Min((int)((status.Epoch * 100) / options.LimitByEpochs), 100), 0);
                        }
                    }

                    backgroundWorker.ReportProgress(0, BackgroundWorkerUpdate.Progress);
                    lastStatusEpoch = status.Epoch;
                }


                // Increment epoch counter
                ++status.Epoch;

                if (options.Delay)
                {
                    // Sleep thread according to specified delay
                    System.Threading.Thread.Sleep(options.DelayMilliseconds);
                }


                // Check stop conditions
                if ((options.Limit == TrainingOptions.TrainingLimit.ByError &&
                     status.TrainingError <= options.LimitByError) ||
                    (options.Limit == TrainingOptions.TrainingLimit.ByEpoch &&
                     status.Epoch >= options.LimitByEpochs))
                {
                    complete = true;
                    stop     = true;
                }

                // Check for cancellation requests
                if (backgroundWorker.CancellationPending)
                {
                    e.Cancel = true;
                    stop     = true;
                }
                while (state == SessionState.Paused)
                {
                    System.Threading.Thread.Sleep(1000);
                }
            } // End main training loop
            #endregion


            // Do a last update before exiting the thread
            if (complete)
            {
                backgroundWorker.ReportProgress(0, BackgroundWorkerUpdate.Completed);
            }
            else
            {
                backgroundWorker.ReportProgress(0, BackgroundWorkerUpdate.Progress);
            }
        }