Beispiel #1
0
        // 機械学習の関数
        private void train()
        {
            GraphInit();
            loadData();
            nn.InitWeight();    // 重みを初期化
            // 学習データの数だけ機械学習を行うグループ
            for (int i = 0; i < num_training_data; i++)
            {
                nn.CalcForward(pixel[i]);
                nn.CalcError(label[i]);
                nn.UpdateWeight(alpha);
                // 100個ごとに精度を検証して表示する
                if (i % 100 == 0)
                {
                    Test(100, i);
                    setText1(i.ToString());
                }
            }
            // 機械学習完了後に、最終的な制度を表示する
            setText1("Testing...");
            double score = Test(num_test_data, num_training_data);

            setText1((score * 100.0).ToString("F2") + "%");
            // weight.dat と label.txt の作成(結果の保存)
            DialogResult result = MessageBox.Show("学習結果を保存しますか?", "save", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                nn.SaveWeight();
                SaveLabelName(new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" });
            }
            buttonEnable(true);
        }