Beispiel #1
0
        private void testForData_Click(object sender, EventArgs e)
        {
            if (worker != null && worker.IsBusy)
            {
                info = Resource.Inst.Get("r189");
                return;
            }
            var file = Common.Dialog.Open(Resource.Inst.Get("r190"), Resource.Inst.Get("r191"), "dat");
            if (file.Length > 0 && File.Exists(file))
            {
                RepeatWindowChoice rwc = new RepeatWindowChoice();
                rwc.Text = Resource.Inst.Get("r192");
                rwc.FormClosing += (owner, args) =>
                {
                    var w = (RepeatWindowChoice)owner;
                    if (w.Repeat)
                    {
                        var repeats = w.NumberOfRepeats;
                        NeuronNumberWindow nnw = new NeuronNumberWindow();
                        nnw.FormClosing += (nnnwOwner, nnwArgs) => {
                            var nw = (NeuronNumberWindow)nnnwOwner;
                            if (nw.IsSelected)
                            {
                                var neurons = nw.NumberOfNeurons;

                                worker = new BackgroundWorker();
                                worker.WorkerReportsProgress = true;
                                worker.WorkerSupportsCancellation = true;
                                worker.DoWork += (a, b) =>
                                {
                                    var data = ((String)b.Argument).Split(";".ToCharArray());
                                    var inputFile = data[0];
                                    var numberRepeats = int.Parse(data[1]);
                                    var maxNeurons = int.Parse(data[2]);
                                    List<LearnResult> results = new List<LearnResult>();

                                    int counter = 0;
                                    for (int nn = 1; nn < maxNeurons; nn++)
                                    {
                                        for (int r = 0; r < numberRepeats; r++)
                                        {
                                            NBN nbn = new NBN(nn, file);
                                            results.Add(nbn.Run(1));
                                            ((BackgroundWorker)a).ReportProgress(++counter);
                                        }
                                    }

                                    List<ReportData> items = new List<ReportData>();

                                    for (int nn = 2; nn <= maxNeurons; nn++)
                                    {
                                        var list = results.Where(q => q.Info != null && q.Info.nn == nn).ToList();

                                        var avgLearnRMSE = list.Average(q => q.AverageLearnRMSE);
                                        var avgTestRMSE = list.Average(q => q.AverageTestRMSE);
                                        ReportData r = new ReportData();
                                        r.LearnData = file;
                                        r.LearnRMSE = avgLearnRMSE.ToString();
                                        r.NeuronNumber = nn.ToString();
                                        r.TestRMSE = avgTestRMSE.ToString();
                                        r.Trials = numberRepeats.ToString();
                                        r.LearnTime = list.GetLearnTime();
                                        r.TestTime = list.GetTestTime();
                                        items.Add(r);
                                    }
                                    b.Result = items;
                                };
                                worker.ProgressChanged += (a, b) =>
                                {
                                    info = b.ProgressPercentage.ToString() + " z " + maxTmp;
                                };
                                worker.RunWorkerCompleted += (a, b) =>
                                {
                                    info = Resource.Inst.Get("r193");
                                    var report = ((List<ReportData>)b.Result);
                                    GridWindow gw = new GridWindow();
                                    gw.SetData(Resource.Inst.Get("r194"), report);
                                    gw.ShowDialog();
                                };

                                var arguments = String.Format("{0};{1};{2}", file, repeats, neurons);
                                maxTmp = (repeats * neurons).ToString();
                                worker.RunWorkerAsync(arguments);

                            }
                            else
                            {
                                info = Resource.Inst.Get("r195");
                            }
                        };
                        nnw.ShowDialog();
                    }
                    else
                    {
                        info = Resource.Inst.Get("r195");
                    }
                };
                rwc.ShowDialog();
            }
            else
            {
                info = Resource.Inst.Get("r196");
            }
        }
Beispiel #2
0
        private void testForData_Click(object sender, EventArgs e)
        {
            if (worker != null && worker.IsBusy)
            {
                info = Resource.Inst.Get("r189");
                return;
            }
            var file = Common.Dialog.Open(Resource.Inst.Get("r190"), Resource.Inst.Get("r191"), "dat");

            if (file.Length > 0 && File.Exists(file))
            {
                RepeatWindowChoice rwc = new RepeatWindowChoice();
                rwc.Text         = Resource.Inst.Get("r192");
                rwc.FormClosing += (owner, args) =>
                {
                    var w = (RepeatWindowChoice)owner;
                    if (w.Repeat)
                    {
                        var repeats            = w.NumberOfRepeats;
                        NeuronNumberWindow nnw = new NeuronNumberWindow();
                        nnw.FormClosing += (nnnwOwner, nnwArgs) => {
                            var nw = (NeuronNumberWindow)nnnwOwner;
                            if (nw.IsSelected)
                            {
                                var neurons = nw.NumberOfNeurons;

                                worker = new BackgroundWorker();
                                worker.WorkerReportsProgress      = true;
                                worker.WorkerSupportsCancellation = true;
                                worker.DoWork += (a, b) =>
                                {
                                    var data                   = ((String)b.Argument).Split(";".ToCharArray());
                                    var inputFile              = data[0];
                                    var numberRepeats          = int.Parse(data[1]);
                                    var maxNeurons             = int.Parse(data[2]);
                                    List <LearnResult> results = new List <LearnResult>();

                                    int counter = 0;
                                    for (int nn = 1; nn < maxNeurons; nn++)
                                    {
                                        for (int r = 0; r < numberRepeats; r++)
                                        {
                                            NBN nbn = new NBN(nn, file);
                                            results.Add(nbn.Run(1));
                                            ((BackgroundWorker)a).ReportProgress(++counter);
                                        }
                                    }

                                    List <ReportData> items = new List <ReportData>();

                                    for (int nn = 2; nn <= maxNeurons; nn++)
                                    {
                                        var list = results.Where(q => q.Info != null && q.Info.nn == nn).ToList();

                                        var        avgLearnRMSE = list.Average(q => q.AverageLearnRMSE);
                                        var        avgTestRMSE  = list.Average(q => q.AverageTestRMSE);
                                        ReportData r            = new ReportData();
                                        r.LearnData    = file;
                                        r.LearnRMSE    = avgLearnRMSE.ToString();
                                        r.NeuronNumber = nn.ToString();
                                        r.TestRMSE     = avgTestRMSE.ToString();
                                        r.Trials       = numberRepeats.ToString();
                                        r.LearnTime    = list.GetLearnTime();
                                        r.TestTime     = list.GetTestTime();
                                        items.Add(r);
                                    }
                                    b.Result = items;
                                };
                                worker.ProgressChanged += (a, b) =>
                                {
                                    info = b.ProgressPercentage.ToString() + " z " + maxTmp;
                                };
                                worker.RunWorkerCompleted += (a, b) =>
                                {
                                    info = Resource.Inst.Get("r193");
                                    var        report = ((List <ReportData>)b.Result);
                                    GridWindow gw     = new GridWindow();
                                    gw.SetData(Resource.Inst.Get("r194"), report);
                                    gw.ShowDialog();
                                };

                                var arguments = String.Format("{0};{1};{2}", file, repeats, neurons);
                                maxTmp = (repeats * neurons).ToString();
                                worker.RunWorkerAsync(arguments);
                            }
                            else
                            {
                                info = Resource.Inst.Get("r195");
                            }
                        };
                        nnw.ShowDialog();
                    }
                    else
                    {
                        info = Resource.Inst.Get("r195");
                    }
                };
                rwc.ShowDialog();
            }
            else
            {
                info = Resource.Inst.Get("r196");
            }
        }