コード例 #1
0
ファイル: InputForm.cs プロジェクト: NadaElawad/OCR
        void EvaluateClassifier(PrinicpleComponentAnalysis PCA)
        {
            string[] classes        = { "G", "L", "R", "Y", "Z" };
            int      testPatterns   = 11;
            double   correctSamples = 0;
            int      classifiedPattern;

            for (int i = 0; i < classes.Length; i++)
            {
                for (int j = 0; j < testPatterns; j++)
                {
                    string path = "img/" + classes[i] + "/Test/" + (j + 45) + ".txt";

                    if (PCA != null)
                    {
                        classifiedPattern = ocrApp.ClassifyReducedData(path);
                    }
                    else
                    {
                        classifiedPattern = ocrApp.Classify(path);
                    }

                    if (classifiedPattern == i)
                    {
                        correctSamples++;
                    }
                }
            }
            accuracy           = correctSamples / (testPatterns * classes.Length);
            misMatchingSamples = testPatterns * classes.Length - correctSamples;
        }
コード例 #2
0
ファイル: InputForm.cs プロジェクト: NadaElawad/OCR
        private void trainButton_Click(object sender, EventArgs e)
        {
            if (IsDataComplete() == false)
            {
                return;
            }

            if (activationFunctionCmbx.SelectedItem.ToString() == "Sigmoid")
            {
                TransferFunction.slope = Double.Parse(valATxt.Text);
            }

            PrinicpleComponentAnalysis PCA = null;

            if (pcaCheckBox.Checked == true)
            {
                int              num_Components   = Int32.Parse(numPCTxtBox.Text);
                double           pcaAlpha         = Double.Parse(pcaAlphaTxtBox.Text);
                TransferFunction transferFunction = new TransferFunction(TransferFunction.Type.Linear);
                PCA = new PrinicpleComponentAnalysis(pcaAlpha, transferFunction, num_Components);
            }
            Train(PCA);
            EvaluateClassifier(PCA);
            output = new OutputForm(this);
            output.Show();
        }
コード例 #3
0
ファイル: InputForm.cs プロジェクト: NadaElawad/OCR
        void Train(PrinicpleComponentAnalysis PCA)
        {
            int    num_HiddenLayers = Int32.Parse(hiddenLayerTxt.Text);
            double alpha            = Double.Parse(learningRateTxt.Text);
            double threshold        = Double.Parse(errorThresholdTxt.Text);

            int[] layers               = new int[num_HiddenLayers + 2];
            int   num_Classes          = 5;
            int   num_TrainingPerClass = 44;

            if (PCA != null)
            {
                layers[0] = PCA.num_Components;
            }
            else
            {
                layers[0] = 30 * 30;
            }
            layers[num_HiddenLayers + 1] = num_Classes;

            for (int i = 0; i < num_HiddenLayers; i++)
            {
                if (neuronsPerLayerGridView.Rows[i].Cells[0].Value == null)
                {
                    MessageBox.Show("Please Enter Number of Neurons Per Each Layer!");
                    return;
                }
                layers[i + 1] = Int32.Parse(neuronsPerLayerGridView.Rows[i].Cells[0].Value.ToString());
            }
            ocrApp = new OCR(layers, num_Classes, alpha, threshold, mainTransferFunction);
            if (PCA != null)
            {
                int num_Epochs = Int32.Parse(numEpochsTxtBox.Text);
                ocrApp.SetPCA(PCA, num_Epochs);
                ocrApp.ReduceData(num_TrainingPerClass);
                meanSquareError = ocrApp.LearnOnReducedData(num_TrainingPerClass);
            }
            else
            {
                meanSquareError = ocrApp.Learn(num_TrainingPerClass);
            }
        }
コード例 #4
0
 public void SetPCA(PrinicpleComponentAnalysis PCA, int num_Epochs)
 {
     this.PCA        = PCA;
     this.num_Epochs = num_Epochs;
 }