private void DisplayTrainingLibraryImagesBottomClass(Object sender, EventArgs e) { PicesClass bottomClass = GetSelectedBottomClass(); if ((bottomClass == null) || (trainingModel == null)) { return; } String dir = trainingModel.DirectoryPathForClass(bottomClass); if (String.IsNullOrEmpty(dir)) { return; } DisplayPicesImages dpi = new DisplayPicesImages(dir); String[] svNames = trainingModel.SupportVectorNames(selectedTopClass, bottomClass); if (svNames != null) { dpi.SummportVectorNames(svNames); } dpi.ShowDialog(); dpi.Dispose(); dpi = null; } /* DisplayTrainingLibraryImagesBottomClass */
} /* InitializeTrainAndPredLevelFields */ private void ValidateTrainingModel() { if (string.IsNullOrEmpty(TrainingModelSelected.Text)) { return; } trainingModelName = TrainingModelSelected.Text; curSelModel = new PicesTrainingConfigManaged(trainingModelName, runLog); trainingModelValid = curSelModel.Valid(); if (!trainingModelValid) { String alarmMsg = "Error Loading Configuration File"; alarmMsg += "\n\n"; alarmMsg += curSelModel.LoadLogStream(); MessageBox.Show(this, alarmMsg, "Could not load Config file", MessageBoxButtons.OK); } else { otherClass = curSelModel.OtherClass(); if (crossValidation) { GroundTruth.Text = "F:\\Pices\\SavedImages\\Cruise-WB0812_Station-DWH"; } //GroundTruth.Text = curSelModel.RootDir (); origClassifierClasses = curSelModel.ExtractClassList(); InitializeTrainAndPredLevelFields(); } } /* ValidateTrainingModel */
public ConfusionMatrix(PicesTrainingConfigManaged _config, PicesClassList _classifierClasses, /**< List of classes in origianl Classifier before reduction due to training level. */ TrainingModel2 _trainingModel, String _modelName, String _groundTruthRootDir, uint _trainLevel, uint _predLevel ) { config = _config; trainingModel = _trainingModel; groundTruthRootDir = _groundTruthRootDir; trainLevel = _trainLevel; predLevel = _predLevel; classifierClasses = _classifierClasses; if (config != null) { otherClass = config.OtherClass(); } InitializeComponent(); classes = new PicesClassList(); classes.Clear(); ModelName.Text = _modelName; GroundTruth.Text = _groundTruthRootDir; }
} /* UpdateProcessDelete */ private void UpdateProcessMerge(PicesDataBase updDbConn) { RunLogAddMsg("Merging Class [" + selectedClass.Name + "] into [" + mergeClass.Name + "]" + "\n"); // First: Update the Images table. // Second: Update Classes table. String sqlCmd = "Call MLClassMergeComprehensive (" + "\"" + selectedClass.Name + "\"" + ", " + "\"" + mergeClass.Name + "\"" + ")"; updDbConn.QueryStatement(sqlCmd, null); PicesClassList.UpdateParent(mergeClass, selectedClass); if (mergeClass.Parent != null) { if (mergeClass.Parent.Children != null) { mergeClass.Parent.Children.Remove(mergeClass); } } selectedClass.StoredOnDataBase = false; selectedClass = mergeClass; } /* UpdateProcessMerge */
public ChartSizeDistribution(String _cruise, String _station, String _deployment, PicesClass _classToPlot, PicesClassList _classes, PicesClassList _activeClasses, String _rootDir ) { cruise = _cruise; station = _station; deployment = _deployment; classToPlot = _classToPlot; classes = _classes; activeClasses = _activeClasses; rootDir = _rootDir; lastSaveDirectory = OSservices.AddSlash(PicesSipperVariables.PicesReportDir()) + "AbundanceReports"; statusMsgs = new PicesMsgQueue("ChartSizeDistribution-StatusMsgs"); msgQueue = new PicesMsgQueue("ChartSizeDistribution-RunLog"); runLog = new PicesRunLog(msgQueue); mainWinConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); configFileName = OSservices.AddSlash(PicesSipperVariables.ConfigurationDirectory()) + "ChartSizeDistribution.cfg"; InitializeComponent(); }
private float FractionThatIsAMatch(PicesClass knownClass, PicesClass predClass ) { String[] knownLevels = knownClass.NameUpper.Split('_'); String[] predLevels = predClass.NameUpper.Split('_'); if (knownLevels.Length < 1) { return(0); } int zed = Math.Min(knownLevels.Length, predLevels.Length); int numMatchedLevels = 0; for (int x = 0; x < zed; ++x) { if (knownLevels[x] == predLevels[x]) { numMatchedLevels = x; } else { break; } } return((float)numMatchedLevels / (float)knownLevels.Length); } /* FractionThatIsAMatch */
PlanktonClassStatisticsLoader statsLoader = null; // To determine total number of images that will be saved. public SavePlanktonData(PicesDataBase _dbConn, PicesDataBaseImageGroup _group, String _cruise, String _station, String _deployment, String _sipperFileName, PicesClass _mlClass, char _classKeyToUse, float _probMin, float _probMax, int _sizeMin, int _sizeMax, float _depthMin, float _depthMax ) { dbConn = _dbConn; group = _group; cruise = (_cruise == null) ? "" : _cruise; station = (_station == null) ? "" : _station; deployment = (_deployment == null) ? "" : _deployment; sipperFileName = (_sipperFileName == null) ? "" : _sipperFileName; mlClass = _mlClass; classKeyToUse = _classKeyToUse; probMin = _probMin; probMax = _probMax; sizeMin = _sizeMin; sizeMax = _sizeMax; depthMin = _depthMin; depthMax = _depthMax; runLog = new PicesRunLog(); InitializeComponent(); }
} /* ValidateParentName */ private void ValidateMergeWithAnotherClass() { if (MergeCheckBox.Checked) { MergeClass.Visible = true; MergeClass.ReadOnly = true; MergeSearchButton.Visible = true; MergeSearchButton.Enabled = true; MergeHelpTextLabel.Visible = true; MergeHelpTextLabel.Enabled = true; MergeLabel.Visible = true; MergeLabel.Enabled = true; ClassName.Text = selectedClass.Name; Description.Text = selectedClass.Description; ParentName.Text = selectedClass.ParentName; MandatoryBox.Checked = selectedClass.Mandatory; SummarizeBox.Checked = selectedClass.Summarize; } else { MergeClass.Enabled = false; MergeClass.Visible = false; MergeClass.ReadOnly = true; mergeClass = null; MergeSearchButton.Visible = false; MergeSearchButton.Enabled = false; MergeHelpTextLabel.Visible = false; MergeHelpTextLabel.Enabled = false; MergeLabel.Visible = false; MergeLabel.Enabled = false; } } /* ValidateMergeWithAnotherClass */
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; } }
} /* InitiateClass */ public void Increment(PicesClass mlClass, float areaMM ) { if (mlClass == null) { mlClass = PicesClassList.GetUnKnownClassStatic(); } ClassTotals2 classTotals = totals.LookUp(mlClass.Name); if (classTotals == null) { classTotals = new ClassTotals2(mlClass.Name, sizeInitial, sizeGrowthFactor, sizeEndRange, bucketCount, sizeBucketStart, sizeBucketEnd ); totals.Add(classTotals); } classTotals.Increment(areaMM); } /* Increment */
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); } }
} /* AddFamilyOfClassesToSizeClassTotals */ /// <summary> /// Returns an instance of 'ClassTotals' that contains the ClassTotals that belong to the family of 'ancestor'. /// The newly instantiated instance will point to the same instances of 'ClassTotals' that this instance points to. /// As a result you should only call this method after you are done accumulating data. /// </summary> /// <param name="ancestor"></param> /// <returns></returns> public SizeDistribution2 ExtractFamilyOfClasses(PicesClass ancestor) { SizeDistribution2 family = new SizeDistribution2(sizeInitial, sizeGrowthFactor, sizeEndRange); ExtractFamily(family, ancestor); return(family); } /* ExtractFamilyOfClasses */
/// <summary> /// Returns an instance of 'ClassTotals' that contains a summary of the classes that are decedent of 'ancestor'. /// </summary> /// <param name="ancestor"></param> /// <returns></returns> public ClassTotals2 SummarizeFamilyOfClasses(PicesClass ancestor) { ClassTotals2 familySummary = new ClassTotals2(ancestor.Name, sizeInitial, sizeGrowthFactor, sizeEndRange, bucketCount, sizeBucketStart, sizeBucketEnd); AddFamilyOfClassesToSizeClassTotals(familySummary, ancestor); return(familySummary); } /* SummarizeFamilyOfClasses */
/// <summary> /// /// </summary> /// <param name="classes"></param> /// <param name="_rootDir">Root directory of training library that contains examples for the classes.</param> /// <param name="_activeClasses">List of classes that current classifier supports; these classes will be highlighted.</param> public SelectAPicesClass(PicesClassList classes, String _rootDir, PicesClassList _activeClasses ) { activeClasses = _activeClasses; rootDir = OSservices.AddSlash(_rootDir); InitializeComponent(); activeClassFont = new Font(MLClassChoices.Font.FontFamily, MLClassChoices.Font.SizeInPoints + 1, FontStyle.Bold); selectedNode = null; PicesClass root = classes.RootNode; bool activeClass = false; AddSubTreeToClassChoser(root, MLClassChoices.Nodes, ref activeClass, 0); if (selectedNode != null) { MLClassChoices.SelectedNode = selectedNode; } MLClassChoices.ExpandAll(); //foreach (PicesClass pc in root.Children) // AddSubTreeToClassChoser (pc, MLClassChoices.Nodes, ref activeClass); }
} /* DetermineKnownIdxAndPredIdx */ private void ExploreMatrixCell(int mouseRow, int mouseCol ) { int knownIDX = 0; int predIDX = 0; int matrixRowIdx = 0; if (matrixRowClassAssigned == null) { return; } DetermineKnownIdxAndPredIdx(mouseRow, mouseCol, ref matrixRowIdx, ref predIDX); if ((knownIDX < 0) || (matrixRowIdx >= matrixRowClassAssigned.Count) || (predIDX < 0) || (predIDX >= numPredClasses)) { return; } PicesClass knownClass = matrixRowClassAssigned[matrixRowIdx]; knownIDX = classesPredLevel.IndexOf(knownClass); if (knownIDX < 0) { return; } ImageListDisplay imagesDisplay = new ImageListDisplay(groundTruthRootDir, imagesByPred[knownIDX][predIDX], trainingModel ); imagesDisplay.ShowDialog(); } /* ExploreMatrixCell */
} /* 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 */
} /* 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 */
} /* 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 */
} /* SumUpFamilyOfClassesForBucket */ /// <summary> /// Returns an instance of 'ClassTotals' that contains a summary of the classes that are decedent of 'ancestor'. /// The newly instantiated instance will point to the same instances of 'ClassTotals' that this instance points to. /// As a result you should only call this method after you are done accumulating data. /// </summary> /// <param name="ancestor"></param> /// <returns></returns> public ClassTotals SumUpFamilyOfClasses(PicesClass ancestor) { ClassTotals familySummary = new ClassTotals(ancestor.Name, bucketCount, bucketSize); AddFamilyOfClassesToSizeClassTotals(familySummary, ancestor); return(familySummary); } /* ExtractFamilyOfClasses */
public ChartAbundanceByDeployment(String _cruise, String _station, String _deployment, PicesClass _classToPlot, int _sizeMin, int _sizeMax, float _probMin, float _probMax, float _depthMin, float _depthMax, char _classKeyToUse, PicesClassList _classes, PicesClassList _activeClasses, String _rootDir ) { cruise = _cruise; station = _station; deployment = _deployment; classToPlot = _classToPlot; sizeMin = _sizeMin; sizeMax = _sizeMax; probMin = _probMin; probMax = _probMax; depthMin = _depthMin; depthMax = _depthMax; classKeyToUse = _classKeyToUse; classes = _classes; activeClasses = _activeClasses; rootDir = _rootDir; if ((sizeMin > 0) && (sizeMax <= 0)) { sizeMax = int.MaxValue; } if ((probMin >= 0.0f) && (probMax <= 0.0f)) { probMax = 1.0f; } if ((depthMin > 0.0f) && (depthMax <= 0.0f)) { depthMax = float.MaxValue; } filterSize = (sizeMin > 0) || ((sizeMax > 0) && (sizeMax > sizeMin)); filterProb = ((probMin > 0.0f) || (probMax < 1.0f)) && (probMax > probMin); filterDepth = ((depthMax > 0) && (depthMax > depthMin)); statusMsgs = new PicesMsgQueue("ChartAbundanceByDeployment-StatusMsgs"); msgQueue = new PicesMsgQueue("ChartAbundanceByDeployment-RunLog"); runLog = new PicesRunLog(msgQueue); mainWinConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); configFileName = OSservices.AddSlash(PicesSipperVariables.ConfigurationDirectory()) + "ChartAbundanceByDeployment.cfg"; BuildCriteriaString(); InitializeComponent(); }
private void SizeDistributionForAClass(PicesClass c, bool includeChildren, ref PicesImageSizeDistribution downCastAcumulated, ref PicesImageSizeDistribution upCastAcumulated ) { statusMsgs.AddMsg("Extracting for Class[" + c.Name + "]"); sbyte ch = (sbyte)statistic; PicesImageSizeDistribution classDownCast = null; PicesImageSizeDistribution classUpCast = null; threadConn.ImagesSizeDistributionByDepth(this.cruise, this.station, this.deployment, c.Name, 0.0f, // MaxDepth 5.0f, ch, initialSizeValue, growthRate, (float)MaxSizeField.Value, ref classDownCast, ref classUpCast ); if (classDownCast != null) { if (downCastAcumulated == null) { downCastAcumulated = classDownCast; } else { downCastAcumulated.AddIn(classDownCast, runLog); } } if (classUpCast != null) { if (upCastAcumulated == null) { upCastAcumulated = classUpCast; } else { upCastAcumulated.AddIn(classUpCast, runLog); } } if (includeChildren) { foreach (PicesClass pc in c.Children) { if (cancelRequested) { break; } SizeDistributionForAClass(pc, includeChildren, ref downCastAcumulated, ref upCastAcumulated); } } } /* SizeDistributionForAClass */
public void SetTrainingModel(TrainingModel2 _trainingModel) { trainingModel = _trainingModel; if (otherClass == null) { otherClass = PicesClassList.GetUniqueClass("Other", ""); } }
private void SelectClassButton_Click(object sender, EventArgs e) { if (MLClassChoices.SelectedNode != null) { selectionMade = true; selectedClass = PicesClassList.GetUniqueClass(MLClassChoices.SelectedNode.Text, ""); Close(); return; } }
private void InsertAClass(Object sender, EventArgs e) { addingNewClass = true; MergeCheckBox.Checked = false; PicesClass newSelectedClass = new PicesClass("", selectedClass); selectedClass = newSelectedClass; EnableAllFields(); PopulateClassMaintenancePanel(selectedClass); ClassName.Focus(); } /* InsertAClass */
} /* DisplayWorstTrainingImages */ private void DisplayWorstTrainingImages2(Object sender, EventArgs e) { PicesClass bottomClass = GetSelectedBottomClass(); if (bottomClass == null) { return; } DisplayWorstTrainingImages2(bottomClass); } /* DisplayWorstTrainingImages */
} /* SetSelectTreeNode */ private void AddSubTreeToClassChoser(PicesClass pc, TreeNodeCollection nodes, ref bool activeClass ) { bool iAmActive = false; if (activeClasses != null) { iAmActive = (activeClasses.LookUpIndex(pc) >= 0); } bool oneOfMyChildrenAreActive = false; TreeNode tn = new TreeNode(pc.Name); nodes.Add(tn); if (pc == selectedClass) { selectedNode = tn; } if (pc.Children != null) { foreach (PicesClass child in pc.Children) { bool childActive = false; AddSubTreeToClassChoser(child, tn.Nodes, ref childActive); if (childActive) { oneOfMyChildrenAreActive = true; } } } if (iAmActive || oneOfMyChildrenAreActive) { activeClass = true; if (iAmActive) { tn.ForeColor = Color.DarkGreen; tn.NodeFont = activeClassFont; } else if (oneOfMyChildrenAreActive) { tn.ForeColor = Color.Green; } } else { tn.ForeColor = Color.Gray; } }
public void AddOne(PicesClass pc) { int index = IndexOfKey(pc.Name); if (index >= 0) { this[pc.Name].count += 1; } else { Add(pc.Name, new ClassStat(pc, 1)); } } /* AddOne */
} /* ValidateMergeWithAnotherClass */ private void ValidateMergeClass() { if (MergeCheckBox.Checked) { errorProvider1.SetError(MergeClass, null); mergeClass = mainDbConn.MLClassLoad(MergeClass.Text); if (mergeClass == null) { errorProvider1.SetError(MergeClass, "You must select a valid class to merge to."); validationErrorsFound = true; } } } /* ValidateMergeClass */
} /* ImportValidatedClassAssignments */ private PicesClass GetClassFromName(PicesDataBase threadConn, String _name ) { PicesClass pc = threadConn.MLClassLoad(_name); if (pc == null) { pc = new PicesClass(_name, ""); threadConn.MLClassInsert(pc); } return(pc); }
} /* ValidClassNameFormat */ private void ValidateClassName() { errorProvider1.SetError(ClassName, null); if (String.IsNullOrEmpty(ClassName.Text)) { errorProvider1.SetError(ClassName, "Can not leave the name blank."); validationErrorsFound = true; return; } if (addingNewClass) { String errMsg = ValidClassNameFormat(ClassName.Text); if (errMsg != null) { errorProvider1.SetError(ClassName, errMsg); validationErrorsFound = true; } else { PicesClass existingClass = mainDbConn.MLClassLoad(ClassName.Text); if (existingClass != null) { errorProvider1.SetError(ClassName, "This name is already in use."); validationErrorsFound = true; } } } else if (ClassName.Text.ToUpper() != selectedClass.Name.ToUpper()) { // Looks like user has changed the class name; make sure it is not already in use." PicesClass existingClass = mainDbConn.MLClassLoad(ClassName.Text); if (existingClass != null) { errorProvider1.SetError(ClassName, "This name is already in use."); validationErrorsFound = true; } else { String errMsg = ValidClassNameFormat(ClassName.Text); if (errMsg != null) { errorProvider1.SetError(ClassName, errMsg); validationErrorsFound = true; } } } return; } /* ValidateClassName */