コード例 #1
0
ファイル: History.cs プロジェクト: DrZeil/nbn-csharp
        /// <summary>
        /// Read all from table action
        /// </summary>
        /// <returns>list of positions</returns>
        public static List<History> ReadAll()
        {
            List<History> list = new List<History>();
            try
            {
                String sql = String.Format(SQL.History.ReadAll, SQL.General.Names.HistoryTableName);
                using (SQLiteConnection con = Manager.Instance.Connection)
                {
                    con.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(sql, con))
                    {
                        using (SQLiteDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                History item = new History();
                                item.Id = rdr.GetInt32(0);
                                item.Name = rdr.GetString(1);
                                item.Data = rdr.GetString(2);
                                list.Add(item);
                            }
                        }
                    }

                    con.Close();
                }
            }
            catch (Exception ex)
            {
                Common.Log.Write(ex);
            }
            return list;
        }
コード例 #2
0
ファイル: HistoryWindow.cs プロジェクト: DrZeil/nbn-csharp
 /// <summary>
 /// Selection action - selecting learning result
 /// </summary>
 /// <param name="sender">who</param>
 /// <param name="e">arguments</param>
 private void list_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         History h = new History();
         h.Id = items[history.SelectedIndex];
         h.Read();
         result = marekbar.Xml.Deserialize<LearnResult>(h.Data);
         loadIntoInterface(result);
     }
     catch (Exception ex)
     {
         ex.ToLog();
     }
 }
コード例 #3
0
ファイル: HistoryWindow.cs プロジェクト: DrZeil/nbn-csharp
 /// <summary>
 /// Delete learing history for position
 /// </summary>
 /// <param name="sender">who</param>
 /// <param name="e">arguments</param>
 private void cmhDelete_Click(object sender, EventArgs e)
 {
     status.Text = "";
     if (MessageBox.Show(LearnByError.Internazional.Resource.Inst.Get("r66"), LearnByError.Internazional.Resource.Inst.Get("r67"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly) == System.Windows.Forms.DialogResult.Yes)
     {
         blockInterface();
         History h = new History();
         int index = history.SelectedIndex;
         h.Id = items[index];
         h.Delete();
         history.Items.RemoveAt(index);
         items.RemoveAt(index);
         history.SelectedIndex = 0;
         unblockInterface();
         this.BringToFront();
     }
     else
     {
         status.Text = "";
         this.BringToFront();
     }
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: DrZeil/nbn-csharp
        private void RunLearningProcess(bool IsResearch = false)
        {
            try
            {
                AppSetting app = new AppSetting();

                if (inputDataFilename == "")
                {
                    OpenDataFile();
                }
                if (inputDataFilename == "") return;
                blockInterface();
                NBN nbn = new NBN(app.NeuronNumber, inputDataFilename);

                nbn.NBN_Gain = app.Gain;
                nbn.NBN_Activation = app.ActivationFunction;
                nbn.NBN_Topography = app.TopologyType;
                nbn.Threshold = app.Threshold;
                nbn.IsClassification = app.IsClassification;

                nbn.IsResearchMode = IsResearch;
                nbn.MatLabCompareDataFolder = MatLabCompareDataFolder;
                string tmpMLF = MatLabCompareDataFolder;
                MatLabCompareDataFolder = "";//thanks got it
                nbn.OnErrorChange += (s, error) =>
                {
                    SetText(error.Format());
                };

                if (app.ShowConsole)
                {
                    nbn.OnDebug += (s, msg) =>
                    {
                        SetDebug(msg);
                    };
                }
                if (app.DontDrawChart == false)
                {
                    nbn.OnChartUpdate += (s, title, x, y) =>
                    {

                        SetChart(title, x, y);
                    };
                }
                if (app.ShowConsole)
                {
                    console = new DebugConsole();
                    console.Show();
                    console.Hide();
                }
                chart.Series.Clear();
                nbn.settings = new NeuralNetworkSettings(app.MaxIterations, app.MU, app.MUL, app.MUH, app.Scale, app.MaxError);
                var result = nbn.Run(app.LearnTrials);
                if (tmpMLF.Length > 0)
                {
                    string file = tmpMLF + "\\wyniki_z_nbn_csharp.txt";
                    if (File.Exists(file)) File.Delete(file);
                    using (var w = new System.IO.StreamWriter(file, true))
                    {
                        w.WriteLine("Dane: " + Path.GetFileNameWithoutExtension(result.Filename));
                        w.WriteLine("Liczba neuronów: " + result.Info.nn.ToString());
                        w.WriteLine(string.Format("Średnie RMSE uczenia: {0}", result.AverageLearnRMSE));
                        w.WriteLine(string.Format("Średnie RMSE testowania: {0}", result.AverageTestRMSE));
                        w.WriteLine(string.Format("Średnie czas uczenia: {0}", result.AverageLearnTime));
                        w.WriteLine(string.Format("Średnie czas testowania: {0}", result.AverageTestTime));
                        w.WriteLine(string.Format("Odchylenie standardowe uczenia: {0}", double.IsNaN(result.StandardDeviation) ? 0 : result.StandardDeviation));
                        w.WriteLine(string.Format("Odchylenie standardowe testowania: {0}", double.IsNaN(result.StandardDeviationTest) ? 0 : result.StandardDeviationTest));
                        w.WriteLine(string.Format("Wskaźnik sukcesu: {0}", result.SuccessRate));
                    }
                }

                std.Text = string.Format("Odchylenie standardowe uczenia: {0} oraz testowania: {1}", double.IsNaN(result.StandardDeviation) ? 0 : result.StandardDeviation, double.IsNaN(result.StandardDeviationTest) ? 0 : result.StandardDeviationTest);
                String runResult = String.Format(Resource.Inst.Get("r29"),
                    result.AverageLearnRMSE, result.AverageTestRMSE, result.Settings.MaxError);

                runResult += " " + String.Format(Resource.Inst.Get("r167"),
                    (result.AverageLearnRMSE <= result.Settings.MaxError ? Resource.Inst.Get("r169") : Resource.Inst.Get("r170")));

                runResult += ", " + String.Format(Resource.Inst.Get("r168"),
                    (result.AverageTestRMSE <= result.Settings.MaxError ? Resource.Inst.Get("r169") : Resource.Inst.Get("r170")));

                try
                {
                    times.Text = String.Format(String.Format(Resource.Inst.Get("r172"), result.SuccessRate)) + ", " + String.Format(Resource.Inst.Get("r171"),
                            result.AverageLearnTime.TrimEnd(new char[] { '0', '.' }),
                            result.AverageTestTime.TrimEnd(new char[] { '0', '.' }));
                }
                catch (Exception ex)
                {
                    ex.ToLog();
                }
                status.Text = runResult;

                if (app.AutoSaveLearningResults)
                {
                    String file = Common.File.GetXmlFileNameForHistory();
                    DateTime d = DateTime.Now;
                    History h = new History();
                    h.Name = String.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}", Path.GetFileNameWithoutExtension(result.Filename),
                        d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second);
                    h.Data = marekbar.Xml.Serialize<LearnResult>(result);
                    h.Insert();
                }

                if (app.ShowConsole) { console.Show(); }

                toolSSE.Items.Clear();
                for (int i = 0; i < result.SSE.Count; i++)
                {
                    toolSSE.Items.Add(Resource.Inst.Get("r182") + (i + 1).ToString());
                    int position = 1;
                    foreach (var sse in result.SSE[i])
                    {
                        toolSSE.Items.Add(String.Format(Resource.Inst.Get("r183"), position, Math.Round(sse,4).ToString().Replace(",",".")));
                        position++;
                    }
                }

                toolRMSE.Items.Clear();
                for (int i = 0; i < result.RMSE.Count; i++)
                {
                    toolRMSE.Items.Add(Resource.Inst.Get("r184") + (i + 1).ToString());
                    int position = 1;
                    foreach (var rmse in result.RMSE[i])
                    {
                        toolRMSE.Items.Add(String.Format(Resource.Inst.Get("r185"), position, Math.Round(rmse, 4).ToString().Replace(",", ".")));
                        position++;
                    }
                }

            }
            catch (Exception ex)
            {
                info = ex.ToLog().Message;
            }
            finally
            {
                unblockInterface();
            }
        }
コード例 #5
0
ファイル: ResearchNBN.cs プロジェクト: DrZeil/nbn-csharp
        public void Run()
        {
            int counter = 0;

            Parallel.ForEach(Items, file =>
                 {
                     for (int nn = 1; nn < NeuronNumber; nn++)//neuron number
                     {
                         for (int i = 0; i < RepeatForEachFile; i++)//learning tests for file with x neurons in network
                         {
                             try
                             {
                                 NBN nbn = new NBN(nn, file);
                                 var result = nbn.Run(1);

                                 DateTime d = DateTime.Now;
                                 History h = new History();
                                 h.Name = String.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}", Path.GetFileNameWithoutExtension(result.Filename),
                                     d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second, d.Millisecond);
                                 h.Data = marekbar.Xml.Serialize<LearnResult>(result);
                                 h.Insert();

                                 if (PDF)
                                 {
                                     try
                                     {
                                         string filename = Common.Folder.Data + "\\" + h.Name + ".pdf";

                                         PDFGenerate data = new PDFGenerate();
                                         data.Filename = filename;
                                         data.Result = result;
                                         data.ChartFilename = GeneratePlot(result.RMSE[0], Path.GetFileNameWithoutExtension(result.Filename));
                                         HistoryPDF pdf = new HistoryPDF(data.Result, data.ChartFilename, true);
                                         pdf.Save(data.Filename);
                                     }
                                     catch
                                     { //don't care about it
                                     }
                                 }
                             }
                             catch (Exception ex)
                             {
                                 ex.GetError();
                             }
                             finally
                             {
                                 counter++;
                                 if (OnUpdate != null)
                                 {
                                     OnUpdate(counter);
                                 }
                             }
                         }
                     }
                 });
        }