Exemple #1
0
        void testOnce()
        {
            if (this.TestDataSets == null)
            {
                this.btnTest.IsEnabled = false;
                return;
            }

            int right = 0;
            int sum   = 0;

            ProgressDialogResult result = ProgressDialog.ProgressDialog.Execute(this, "Testing Network", () =>
            {
                for (int i = 0; i < TestDataSets.Count(); i++)
                {
                    ProgressDialog.ProgressDialog.Current.Report("Testing Number {0}/{1}... \n ", i, TestDataSets.Count());
                    double[] a = this.Network.Compute(TestDataSets[i].Values);
                    if (findMaxIndex(a) == findMaxIndex(TestDataSets[i].Targets))
                    {
                        right++;
                    }
                    sum++;
                }
            }, ProgressDialogSettings.WithSubLabel);

            if (result.OperationFailed)
            {
                MessageBox.Show("Test failed.");
            }
            else
            {
                MessageBox.Show("Total test sample Number:" + sum.ToString() + "\n" + "Right number:" + right.ToString() + "\n"
                                + "Wrong number:" + (sum - right).ToString() + "\n"
                                + "Accuracy:" + (right / (double)sum).ToString());
            }

            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                SeriesCollectionAccuracy[0].Values.Add(right / (double)sum);
                if (SeriesCollectionAccuracy[0].Values.Count > 50)
                {
                    SeriesCollectionAccuracy[0].Values.RemoveAt(0);
                }
            }));
        }
Exemple #2
0
        void trainEpoch(Object EpochNumber, bool isTest)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                TrainEpocNum.Content    = "0";
                TrainElapseTime.Content = "0";
            }));


            ProgressDialogResult result = ProgressDialog.ProgressDialog.Execute(this, "Trainning Network", () =>
            {
                for (int i = 0; i < (int)EpochNumber; i++)
                {
                    ProgressDialog.ProgressDialog.Current.Report("Trained Epoch {0}/{1}... \n ", i, (int)EpochNumber);
                    int j = 0;
                    foreach (var dataSet in TrainDataSets)
                    {
                        if (this.stopTrain == true)
                        {
                            break;
                        }
                        this.Network.TrainOneStep(dataSet);
                        j++;
                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            TrainNum.Content        = j.ToString();
                            TrainEpocNum.Content    = i.ToString();
                            TrainElapseTime.Content = (sw.ElapsedMilliseconds / 60.0).ToString("0.00") + "s";
                            TotalError.Content      = string.Format("{0:N3}", this.Network.TotalError);
                        }));
                    }

                    if (isTest)
                    {
                        if (this.TestDataSets == null)
                        {
                            this.btnTest.IsEnabled = false;
                            return;
                        }

                        int right = 0;
                        int sum   = 0;

                        for (int k = 0; k < TestDataSets.Count(); k++)
                        {
                            ProgressDialog.ProgressDialog.Current.Report("Testing {0}/{1}... \n ", k, (int)TestDataSets.Count());
                            double[] a = this.Network.Compute(TestDataSets[k].Values);
                            if (findMaxIndex(a) == findMaxIndex(TestDataSets[k].Targets))
                            {
                                right++;
                            }
                            sum++;
                        }

                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            SeriesCollectionAccuracy[0].Values.Add(right / (double)sum);
                            if (SeriesCollectionAccuracy[0].Values.Count > 50)
                            {
                                SeriesCollectionAccuracy[0].Values.RemoveAt(0);
                            }
                        }));
                    }


                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        EpochNum.Add(i);
                        SeriesCollectionEpoch[0].Values.Add(this.Network.TotalError);
                        if (SeriesCollectionEpoch[0].Values.Count > 50)
                        {
                            SeriesCollectionEpoch[0].Values.RemoveAt(0);
                        }


                        TimeElapse.Add(DateTime.Now.ToString("mm-ss"));
                        SeriesCollectionCPUUsage[0].Values.Add(theCPUCounter.NextValue() / Environment.ProcessorCount);
                        if (SeriesCollectionCPUUsage[0].Values.Count > 50)
                        {
                            SeriesCollectionCPUUsage[0].Values.RemoveAt(0);
                        }
                    }));
                }
            }, ProgressDialogSettings.WithSubLabel);

            if (result.OperationFailed)
            {
                MessageBox.Show("Train failed.");
            }
            else
            {
                MessageBox.Show("Train successfully.");
            }

            sw.Stop();
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                resetAllButtonState();

                this.btnTrainOneStep.IsEnabled = true;
                this.btnTrain.IsEnabled        = true;
                this.btnLoadTestData.IsEnabled = true;
                this.btnSave.IsEnabled         = true;
                if (this.TestDataSets != null)
                {
                    this.btnTest.IsEnabled = true;
                }
            }));
        }