Пример #1
0
 // read trained codebook vectors from files
 private void ButtonReadFile_Click(object sender, EventArgs e)
 {
     try
     {
         if (checkBoxLVQ1.Checked)
         {
             myLVQ1 = Data.ReadFromBinaryFile <LVQ1>("LVQ1" + ".bin");
         }
         if (checkBoxLVQ2.Checked)
         {
             myLVQ2 = Data.ReadFromBinaryFile <LVQ2>("LVQ2" + ".bin");
         }
         if (checkBoxLVQ3.Checked)
         {
             myLVQ3 = Data.ReadFromBinaryFile <LVQ3>("LVQ3" + ".bin");
         }
     }
     catch
     {
         MessageBox.Show("File not found.");
         return;
     }
     if (checkBoxLVQ1.Checked)
     {
         labelTest1.Text = (myLVQ1.averageAccuracy).ToString();
     }
     if (checkBoxLVQ2.Checked)
     {
         labelTest2.Text = (myLVQ2.averageAccuracy).ToString();
     }
     if (checkBoxLVQ3.Checked)
     {
         labelTest3.Text = (myLVQ3.averageAccuracy).ToString();
     }
     calc = true;
 }
Пример #2
0
        // run algorithms & write trained codebook vectors to files
        private void ButtonTrain_Click(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxLVQ1.Checked)
                {
                    learningRate1        = Single.Parse(textBoxLearningRate1.Text, CultureInfo.InvariantCulture);
                    codebookVectorCount1 = Convert.ToInt16(textBoxCodebookVectors1.Text);
                    iterationCount1      = Convert.ToInt16(textBoxEpochs1.Text);
                    decay1 = textBoxDecay1.Enabled ? Single.Parse(textBoxDecay1.Text, CultureInfo.InvariantCulture) : 1;
                }
                if (checkBoxLVQ2.Checked)
                {
                    learningRate2        = Single.Parse(textBoxLearningRate2.Text, CultureInfo.InvariantCulture);
                    codebookVectorCount2 = Convert.ToInt16(textBoxCodebookVectors2.Text);
                    iterationCount2      = Convert.ToInt16(textBoxEpochs2.Text);
                    window2 = Single.Parse(textBoxWindow2.Text, CultureInfo.InvariantCulture);
                    decay2  = textBoxDecay2.Enabled ? Single.Parse(textBoxDecay2.Text, CultureInfo.InvariantCulture) : 1;
                }
                if (checkBoxLVQ3.Checked)
                {
                    learningRate3        = Single.Parse(textBoxLearningRate3.Text, CultureInfo.InvariantCulture);
                    codebookVectorCount3 = Convert.ToInt16(textBoxCodebookVectors3.Text);
                    iterationCount3      = Convert.ToInt16(textBoxEpochs3.Text);
                    window3  = Single.Parse(textBoxWindow3.Text, CultureInfo.InvariantCulture);
                    epsilon3 = Single.Parse(textBoxEpsilon3.Text, CultureInfo.InvariantCulture);
                    decay3   = textBoxDecay3.Enabled ? Single.Parse(textBoxDecay3.Text, CultureInfo.InvariantCulture) : 1;
                }
            }
            catch
            {
                MessageBox.Show("Invalid parameter(s).");
                return;
            }

            progressBar1.Maximum  = 0;
            progressBar1.Maximum += checkBoxLVQ1.Checked ? iterationCount1 : 0;
            progressBar1.Maximum += checkBoxLVQ2.Checked ? iterationCount2 : 0;
            progressBar1.Maximum += checkBoxLVQ3.Checked ? iterationCount3 : 0;
            progressBar1.Value    = 0;
            LVQ.iteration         = 0;

            if (checkBoxLVQ1.Checked)
            {
                myLVQ1 = new LVQ1(trainData, testData, learningRate1, codebookVectorCount1, iterationCount1, "LVQ1", decay1);
                myLVQ1.Epoch();
                labelTest1.Text = (myLVQ1.averageAccuracy).ToString();
            }
            if (checkBoxLVQ2.Checked)
            {
                myLVQ2 = new LVQ2(trainData, testData, learningRate2, codebookVectorCount2, iterationCount2, "LVQ2", window2, decay2);
                myLVQ2.Epoch();
                labelTest2.Text = (myLVQ2.averageAccuracy).ToString();
            }
            if (checkBoxLVQ3.Checked)
            {
                myLVQ3 = new LVQ3(trainData, testData, learningRate3, codebookVectorCount3, iterationCount3, "LVQ3", window3, epsilon3, decay3);
                myLVQ3.Epoch();
                labelTest3.Text = (myLVQ3.averageAccuracy).ToString();
            }

            try
            {
                if (checkBoxLVQ1.Checked)
                {
                    Data.WriteToBinaryFile("LVQ1", myLVQ1, false);
                }
                if (checkBoxLVQ2.Checked)
                {
                    Data.WriteToBinaryFile("LVQ2", myLVQ2, false);
                }
                if (checkBoxLVQ3.Checked)
                {
                    Data.WriteToBinaryFile("LVQ3", myLVQ3, false);
                }
            }
            catch
            {
                MessageBox.Show("Path not found.");
            }

            calc = true;
        }