Example #1
0
        } /* ExploreMatrixCell */

        public void  MakePrediction(PicesClass knownClass,
                                    PicesClass predictedClass,
                                    double predProb,
                                    PicesFeatureVector fv,
                                    TrainingModel2 trainModel
                                    )
        {
            bool partOfOriginalClassifier = ClassInClassifierClasses(knownClass);

            if (!partOfOriginalClassifier)
            {
                String notPartClassName = "(V)" + knownClass.Name;
                knownClass = PicesClassList.GetUniqueClass(notPartClassName, "");
            }

            int x = classes.LookUpIndex(knownClass);

            if (x < 0)
            {
                classes.Add(knownClass);
            }

            x = classes.LookUpIndex(predictedClass);
            if (x < 0)
            {
                classes.Add(predictedClass);
            }

            Prediction p = new Prediction(knownClass, predictedClass, predProb, fv, trainModel, partOfOriginalClassifier);

            predictions.Add(p);
        } /* featureVector */
Example #2
0
        private void SelectClassButtom_Click(object sender, EventArgs e)
        {
            String         rootDir       = "";
            PicesClassList activeClasses = null;

            if (ActiveTrainingLibraries.Model1() != null)
            {
                rootDir       = ActiveTrainingLibraries.Model1().RootDir;
                activeClasses = ActiveTrainingLibraries.Model1().MLClasses();
            }

            if (classes == null)
            {
                classes = dbConn.MLClassLoadList();
            }
            SelectAPicesClass sapc = new SelectAPicesClass(classes, rootDir, activeClasses);

            if (!String.IsNullOrEmpty(ValidatedClassName.Text))
            {
                sapc.SelectedClass = PicesClassList.GetUniqueClass(ValidatedClassName.Text, "");
            }

            sapc.ShowDialog(this);
            if (sapc.SelectionMade && (sapc.SelectedClass != null))
            {
                PicesClass validatdClass = sapc.SelectedClass;
                ValidatedClassName.Text = validatdClass.Name;
                image.ValidatedClass    = validatdClass;
                dbConn.ImagesUpdateValidatedClass(image.ImageFileName, validatdClass);
                classUserValidatesAs = validatdClass;
            }
        }
Example #3
0
        } /* UpdateDetailProbabilityDisplay */

        private void  UpdateBinaryClassifierProbabilities(String className)
        {
            PicesClass leftClass = PicesClassList.GetUniqueClass(className, "");

            BinaryClassName.Text = "";

            BinaryProbabilities.Rows.Clear();

            Prediction pred = GetPrediction(curSelImageFileName);

            PicesPredictionList binaryPredictions = pred.trainModel.BinaryProbailitiesForClass(leftClass);

            if (binaryPredictions == null)
            {
                return;
            }

            BinaryClassName.Text = leftClass.Name;

            foreach (PicesPrediction p in binaryPredictions)
            {
                if (leftClass == p.MLClass)
                {
                    continue;
                }

                Object[] data = new Object[2];

                data[0] = p.ClassName;
                double probForRightSide = 1.0 - p.Probability;
                data[1] = probForRightSide;
                BinaryProbabilities.Rows.Add(data);
            }
        } /* UpdateBinaryClassifierProbabilities */
Example #4
0
        } /* ClassTree_AfterSelect */

        private void  StartUpdateProcedure()
        {
            if (!allowUpdates)
            {
                MessageBox.Show(this, "Updates are not allowed.", "Class Maintenance", MessageBoxButtons.OK);
                return;
            }

            if (addingNewClass)
            {
                newClassEntry = new PicesClass(ClassName.Text, ParentName.Text);
            }
            else
            {
                newClassEntry = selectedClass;
            }

            newClassEntry.Description = Description.Text;
            newClassEntry.Parent      = PicesClassList.GetUniqueClass(ParentName.Text, null);

            newClassEntry.Mandatory = MandatoryBox.Checked;
            newClassEntry.Summarize = SummarizeBox.Checked;

            DisableAllFields();
            updateThread = new Thread(new ThreadStart(UpdateProcess));
            updateThread.Start();
            Thread.Sleep(50);
            updateTimer.Enabled = true;

            UpdatingProgressBar.Value   = 0;
            UpdatingProgressBar.Visible = true;
        } /* PerformUpdate */
Example #5
0
        private List <String> ValidateFields()
        {
            List <String> errors = new List <string> ();

            weightByVolume    = WeightByVolume.Checked;
            includeSubClasses = IncludeSubClasses.Checked;

            depthIncrement = (int)DepthIncr.Value;
            if (depthIncrement < 1)
            {
                errors.Add("Depth Increment must be greater than zero.");
            }

            if (String.IsNullOrEmpty(ClassToPlot.Text))
            {
                errors.Add("You must specify class to plot.");
            }
            else
            {
                classToPlot = PicesClassList.GetUniqueClass(ClassToPlot.Text, "");
            }

            ValidateDepthAxisSettings(ref errors);

            if (errors.Count < 1)
            {
                return(null);
            }
            else
            {
                return(errors);
            }
        }
Example #6
0
        public void  SetTrainingModel(TrainingModel2 _trainingModel)
        {
            trainingModel = _trainingModel;

            if (otherClass == null)
            {
                otherClass = PicesClassList.GetUniqueClass("Other", "");
            }
        }
Example #7
0
 private void SelectClassButton_Click(object sender, EventArgs e)
 {
     if (MLClassChoices.SelectedNode != null)
     {
         selectionMade = true;
         selectedClass = PicesClassList.GetUniqueClass(MLClassChoices.SelectedNode.Text, "");
         Close();
         return;
     }
 }
        } /* BuildThumbnailGridViewConetextMenu */

        private PicesClass  GetSelectedBottomClass()
        {
            if (BinaryProbabilities.SelectedCells.Count != 1)
            {
                return(null);
            }

            int    row       = BinaryProbabilities.SelectedCells[0].RowIndex;
            String className = BinaryProbabilities.Rows[row].Cells[0].Value.ToString();

            return(PicesClassList.GetUniqueClass(className, ""));
        } /* GetSelectedBottomClass */
Example #9
0
        private void MergeSearchButton_Click(object sender, EventArgs e)
        {
            SelectAPicesClass sac = new SelectAPicesClass(classes, "", null);

            sac.SelectedClass = PicesClassList.GetUniqueClass(MergeClass.Text, "");
            sac.ShowDialog();
            if (sac.SelectedClass != null)
            {
                MergeClass.Text = sac.SelectedClass.Name;
                ValidateMergeClass();
            }
        }
Example #10
0
        public GetRunTimeParameters()
        {
            msgQueue = new PicesMsgQueue("GradeTrainingModel");
            runLog   = new PicesRunLog(msgQueue);

            InitializeComponent();
            noAgreementClass = PicesClassList.GetUniqueClass("NoAgreement", "");

            configFileName = OSservices.AddSlash(PicesSipperVariables.ConfigurationDirectory()) + "GradeTrainingModel.txt";

            LoadTrainingModelComboBox();
            InitializeTrainAndPredLevelFields();
            EnableComponentsForParameterEntry();
        }
Example #11
0
        } /* LoadConfigurationFile */

        private List <String> ValidateFields()
        {
            List <String> errors = new List <string> ();

            switch (SizeStatisticField.Text)
            {
            case "Pixel Area":   statistic = '0';   break;

            case "Diameter":     statistic = '1';   break;

            case "Volume (SBv)": statistic = '2';   break;

            case "Volume (EBv)": statistic = '3';   break;
            }

            cast = CastField.Text;

            growthRate       = (float)GrowthRateField.Value;
            initialSizeValue = (float)InitialSizeField.Value;
            // KKKK Did this soi that we are the same as the volume report I sent to kendra a couple weeks ago.
            if (statistic == '2')
            {
                growthRate       = 1.331f;
                initialSizeValue = 0.000523599f;
            }

            includeSubClasses = IncludeSubClasses.Checked;

            if (String.IsNullOrEmpty(ClassToPlot.Text))
            {
                errors.Add("You must specify class to plot.");
            }
            else
            {
                classToPlot = PicesClassList.GetUniqueClass(ClassToPlot.Text, "");
            }

            if (errors.Count < 1)
            {
                return(null);
            }
            else
            {
                return(errors);
            }
        }
Example #12
0
        } /* ReportByClassCollumns */

        private PicesClassList  BuildMLClassList()
        {
            PicesClassList mlClasses = new PicesClassList();

            int cIDX;

            //for  (cIDX = 0;  cIDX <  totals->end ();  cIDX++)
            for (cIDX = 0; cIDX < totals.Count; cIDX++)
            {
                ClassTotals ct = totals[cIDX];
                mlClasses.Add(PicesClassList.GetUniqueClass(ct.Name, ""));
            }

            mlClasses.SortByName();

            return(mlClasses);
        } /* BuildMLClassList */
Example #13
0
        private void SelectClassButton_Click(object sender, EventArgs e)
        {
            SelectAPicesClass sapc = new SelectAPicesClass(classes, rootDir, activeClasses);

            if (!String.IsNullOrEmpty(ClassToPlot.Text))
            {
                sapc.SelectedClass = PicesClassList.GetUniqueClass(ClassToPlot.Text, "");
            }
            sapc.ShowDialog(this);
            if (sapc.SelectionMade)
            {
                PicesClass pc = sapc.SelectedClass;
                if (pc != null)
                {
                    ClassToPlot.Text = pc.Name;
                }
            }
        }
        } /* AddDeploymentToSeries */

        /// <summary>
        /// This method will be ran as a separate thread; it is responsible for collecting all the data needed to generate the plot.
        /// </summary>
        private void  BuildPlotData()
        {
            if (buildPlotDataRunning)
            {
                return;
            }

            PicesDataBase.ThreadInit();

            threadConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog);

            buildPlotDataRunning = true;

            depthIncrement = (int)DepthIncr.Value;
            classToPlot    = PicesClassList.GetUniqueClass(ClassToPlot.Text, "");

            series = new List <DataSeriesToPlot> ();

            foreach (PlotRequest pr in plotRequests)
            {
                if (cancelRequested)
                {
                    break;
                }
                AddDeploymentToSeries(pr.deployment);
            }

            threadConn.Close();
            threadConn = null;
            GC.Collect();
            PicesDataBase.ThreadEnd();

            if (cancelRequested)
            {
                statusMsgs.AddMsg("Plotting of data CANCELLED!!!");
            }
            else
            {
                statusMsgs.AddMsg("Building of plot data completed !!!");
            }

            buildPlotDataRunning = false;
            buildPlotDataDone    = true;
        } /* BuildPlotData */
        private void BinaryProbabilities_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                DataGridView dgv = (DataGridView)sender;

                DataGridViewSelectedCellCollection dgvscc = dgv.SelectedCells;
                if ((dgvscc == null) || (dgvscc.Count != 1))
                {
                    return;
                }

                String     className = (String)dgvscc[0].Value;
                PicesClass pc        = PicesClassList.GetUniqueClass(className, "");
                if (pc != null)
                {
                    DisplayTrainingImages(pc);
                }
            }
        }
        } /* UpdateDetailProbabilityDisplay */

        private void  UpdateBinaryClassifierProbabilities(String className)
        {
            PicesClass leftClass = PicesClassList.GetUniqueClass(className, "");

            BinaryClassName.Text = "";

            BinaryProbabilities.Rows.Clear();

            PicesPredictionList binaryPredictions = trainingModel.BinaryProbailitiesForClass(leftClass);

            if (binaryPredictions == null)
            {
                return;
            }

            BinaryClassName.Text = leftClass.Name;

            selectedTopClass = leftClass;

            foreach (PicesPrediction p in binaryPredictions)
            {
                if (leftClass == p.MLClass)
                {
                    continue;
                }

                Object[] data = new Object[2];

                data[0] = p.ClassName;
                double probForRightSide = 1.0 - p.Probability;
                data[1] = probForRightSide;
                BinaryProbabilities.Rows.Add(data);
            }

            BuildBinaryProbabilitiesGridViewConetextMenu();
        } /* UpdateBinaryClassifierProbabilities */
Example #17
0
        private void MLClassChoices_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                selectionMade = true;
                selectedClass = PicesClassList.GetUniqueClass(e.Node.Text, "");
                Close();
                return;
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (String.IsNullOrEmpty(rootDir))
                {
                    return;
                }

                String fullDirPath = rootDir + e.Node.Text;

                DisplayPicesImages dpi = new DisplayPicesImages(fullDirPath);
                dpi.ShowDialog();
                dpi.Dispose();
                dpi = null;
            }
        }
Example #18
0
        } /* ProcessOneFeatureVector */

        private PicesClass  UpdateClassId(PicesClass mlClass)
        {
            // We lock 'predictionUpdateQueue' because all other classification processes refer to it.
            //
            lock  (predictionUpdateQueue)
            {
                // Maybe another Classification process already updated the database and hence updated the classId field.
                if (mlClass.ClassId >= 0)
                {
                    //int zed = 888;
                }
                else
                {
                    String className  = mlClass.Name;
                    String parentName = mlClass.ParentName;
                    if (String.IsNullOrEmpty(parentName))
                    {
                        parentName     = "AllClasses";
                        mlClass.Parent = PicesClassList.GetUniqueClass(parentName, "");
                    }

                    if (runLog == null)
                    {
                        runLog = new PicesRunLog();
                    }
                    PicesDataBase dbConn = null;
                    if (dbServer == null)
                    {
                        dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog);
                    }
                    else
                    {
                        dbConn = new PicesDataBase(dbServer, runLog);
                    }

                    mlClass.Description = "Added by 'Classification'";

                    dbConn.MLClassInsert(mlClass);

                    if (mlClass.ClassId < 0)
                    {
                        PicesClass pc = dbConn.MLClassLoad(className);
                        if (mlClass.ClassId < 0)
                        {
                            runLog.Writeln("ClassifierProcess.UpdateClassId    ***ERROR***     mlClass.ClassId < 0      ClassName[" + className + "]");
                        }
                    }

                    // I do not know what the impact of opening and closing a lot of connections
                    // to the MySQL data base will be, and since this method should only get called
                    // when a new MLClass is introduced I want to sleep a little to make
                    // sure that we do not over stress resources that I am not aware of.
                    Thread.Sleep(100);
                    //dbConn.Close ();
                    dbConn = null;
                    GC.Collect();
                }
            }

            return(mlClass);
        }
Example #19
0
        } /* SizeDistributionForAClass */

        /// <summary>
        /// This method will be ran as a separate thread; it is responsible for collecting all the data needed to generate the plot.
        /// </summary>
        private void  BuildPlotData()
        {
            if (buildPlotDataRunning)
            {
                return;
            }

            PicesDataBase.ThreadInit();

            threadConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog);

            buildPlotDataRunning = true;

            classToPlot = PicesClassList.GetUniqueClass(ClassToPlot.Text, "");

            sbyte ch = (sbyte)statistic;

            downCast = null;
            upCast   = null;

            goalie.StartBlock();

            SizeDistributionForAClass(classToPlot,
                                      IncludeSubClasses.Checked,
                                      ref downCast,
                                      ref upCast
                                      );

            if (cast == "Down")
            {
                bucketsDisplayed = downCast;
            }

            else if (cast == "Up")
            {
                bucketsDisplayed = upCast;
            }

            else
            {
                bucketsDisplayed = new PicesImageSizeDistribution(downCast);
                bucketsDisplayed.AddIn(upCast, runLog);
            }

            integratedDensityDistribution = bucketsDisplayed.IntegratedDensityDistribution();

            threadConn.Close();
            threadConn = null;
            GC.Collect();
            PicesDataBase.ThreadEnd();

            goalie.EndBlock();

            if (cancelRequested)
            {
                statusMsgs.AddMsg("Plotting of data CANCELLED!!!");
            }
            else
            {
                statusMsgs.AddMsg("Building of plot data completed !!!");
            }

            buildPlotDataRunning = false;
            buildPlotDataDone    = true;
        } /* BuildPlotData */