Ejemplo n.º 1
0
        private void Learn_Shown(object sender, EventArgs e)
        {
            // show the current number of teacher data
            TeacherFile tf = new TeacherFile();

            tf.SetFeatureNumber(NBOFFEATURES);
            NbOfFileNames                   = tf.GetNextDataFileID() - 1;
            label_NbofFiles.Text            = "Number of used image files:  " + Convert.ToString(NbOfFileNames);
            NbofTeachers                    = tf.GetNumberOfTeachers();
            label_NbofTeachers.Text         = "Number of defined teachers:  " + Convert.ToString(NbofTeachers);
            numericUpDown_Convergence.Value = Convert.ToDecimal(factor);

            int NbofWeights = nbOfUnits_1 + nbOfUnits_1 * nbOfUnits_2 + nbOfUnits_2 * nbOfUnits_3;

            Array.Resize(ref Weights, NbofWeights);
            for (int ii = 0; ii < NbofWeights; ii++)
            {
                Weights[ii] = 0.0;
            }

            // Load the weights from data file
            WeightFile wf = new WeightFile();

            Cursor = Cursors.WaitCursor;
            bool bSuccess;

            bSuccess = wf.LoadWeights(Weights, nbOfUnits_1, nbOfUnits_2, nbOfUnits_3);
            Cursor   = Cursors.Default;
            if (!bSuccess)
            {
                MessageBox.Show("'Weights_File' data file is missing or injured - start working with random weights.");
                InitializeWeights();
            }

            timer1.Interval = 1;  // let the teaching timer's interval: 1 msec
            bStarted        = false;
        }
Ejemplo n.º 2
0
        private int LearnNextImage(int CurrentItem, double[] errors)
        {
            int nbofvalidelements = 0;

            TeacherFile tf = new TeacherFile();

            tf.SetFeatureNumber(NBOFFEATURES);
            double[]  CurrentFeatures = new double[NBOFFEATURES];
            Boolean[] UsedFeatures    = new Boolean[NBOFFEATURES];
            UsedFeatures[0] = tf.GetUsedFeatures_RComponent();
            UsedFeatures[1] = tf.GetUsedFeatures_GComponent();
            UsedFeatures[2] = tf.GetUsedFeatures_BComponent();
            UsedFeatures[3] = tf.GetUsedFeatures_Grayscale();
            UsedFeatures[4] = tf.GetUsedFeatures_Area();
            UsedFeatures[5] = tf.GetUsedFeatures_MinDiameter();
            UsedFeatures[6] = tf.GetUsedFeatures_MaxDiameter();
            UsedFeatures[7] = tf.GetUsedfeatures_Aspectratio();
            UsedFeatures[8] = tf.GetUsedfeatures_Circularity();

            double[] Decisions = new double[nbOfUnits_3];

            string filename     = tf.GetFileName(CurrentItem + 1);
            int    nbofteachers = tf.GetNumberOfTeachers(filename);

            if (nbofteachers == 0)
            {
                return(nbofvalidelements);
            }

            int decision   = 0;
            int errorindex = 0;

            for (int ii = 0; ii < nbofteachers; ii++)
            {
                int ExpectedDecision = tf.RetrieveTeacherFeatures(filename, ii + 1, CurrentFeatures, 3, NBOFFEATURES);
                if (ExpectedDecision == -1)
                {
                    continue;
                }

                for (int jj = 0; jj < NBOFFEATURES; jj++)
                {
                    if (UsedFeatures[jj] == false)
                    {
                        CurrentFeatures[jj] = 0.0;  // (discard the extracted value)
                    }
                }

                decision = CImageProcessingUtils.TeachNeuralNetwork(CurrentFeatures, Weights,
                                                                    nbOfUnits_1, nbOfUnits_2, nbOfUnits_3, factor, ExpectedDecision, Decisions);
                Decisions[ExpectedDecision - 1] -= 1.0;  // this element of 'Decisions' vector is the correct answer
                for (int jj = 0; jj < nbOfUnits_3; jj++)
                {
                    errors[errorindex] = Decisions[jj];
                    nbofvalidelements++;
                    errorindex++;
                }
            }

            return(nbofvalidelements);
        }