private void mahalanobisDistanceToolStripMenuItem_Click(object sender, EventArgs e) { FormForMahalanobisDistance MainWindow = new FormForMahalanobisDistance(); PanelForClassSelection ClassSelectionPanel = new PanelForClassSelection(true, eClassType.WELL); ClassSelectionPanel.Height = MainWindow.panelForSourceCloud.Height; MainWindow.panelForSourceCloud.Controls.Add(ClassSelectionPanel); PanelForClassSelection HitClassSelectionPanel = new PanelForClassSelection(false, eClassType.WELL); HitClassSelectionPanel.Height = MainWindow.panelHitClass.Height; HitClassSelectionPanel.ListRadioButtons[1].Checked = true; MainWindow.panelHitClass.Controls.Add(HitClassSelectionPanel); if (MainWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; cExtendedList ListClassSelected = new cExtendedList(); for (int i = 0; i < ClassSelectionPanel.ListCheckBoxes.Count; i++) if (ClassSelectionPanel.ListCheckBoxes[i].Checked) ListClassSelected.Add(1); else ListClassSelected.Add(0); int IdxClassForOutliers = 0; for (int i = 0; i < HitClassSelectionPanel.ListRadioButtons.Count; i++) if (HitClassSelectionPanel.ListRadioButtons[i].Checked) { IdxClassForOutliers = i; break; } if (ListClassSelected.Sum() < 1) { MessageBox.Show("At least one classe has to be selected.", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // start by computing the inversed covariance matrix //if (checkedListBoxActiveDescriptors.CheckedItems.Count <= 1) //{ // MessageBox.Show("At least two descriptors have to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} cCovarianceMatrix CM = new cCovarianceMatrix(); cExtendedTable NewTable = null; if (this.ProcessModeplateByPlateToolStripMenuItem.Checked) { //foreach (cPlate TmpPlate in CompleteScreening.ListPlatesActive) //{ // cListWells ListWellsToProcess = new cListWells(null); // foreach (cWell item in TmpPlate.ListActiveWells) // if ((item.GetClassIdx() != -1) && (ListClassSelected[item.GetClassIdx()] == 1)) ListWellsToProcess.Add(item); // cExtendedTable NewTable = new cExtendedTable(ListWellsToProcess, true); // CM.SetInputData(NewTable); //} } else if (this.ProcessModeEntireScreeningToolStripMenuItem.Checked) { cListWells ListWellsToProcess = new cListWells(null); foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesActive) foreach (cWell item in TmpPlate.ListActiveWells) if ((item.GetCurrentClassIdx() != -1) && (ListClassSelected[item.GetCurrentClassIdx()] == 1)) ListWellsToProcess.Add(item); NewTable = new cExtendedTable(ListWellsToProcess, true); // cTwoSampleFTest CM = new cTwoSampleFTest(); CM.SetInputData(NewTable); } else { cListWells ListWellsToProcess = new cListWells(null); foreach (cWell item in cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().ListActiveWells) if ((item.GetCurrentClassIdx() != -1) && (ListClassSelected[item.GetCurrentClassIdx()] == 1)) ListWellsToProcess.Add(item); NewTable = new cExtendedTable(ListWellsToProcess, true); // cTwoSampleFTest CM = new cTwoSampleFTest(); CM.SetInputData(NewTable); } CM.Run(); cInverse cI = new cInverse(); cI.SetInputData(CM.GetOutPut()); cI.Run(); // get the cloud center cStatistics cstat = new cStatistics(); cstat.UnselectAll(); cstat.IsMean = true; cstat.SetInputData(NewTable); cstat.Run(); if (cstat.GetOutPut() == null) return; cExtendedList ListMeans = cstat.GetOutPut().GetRow(0); cDescriptorType MahalanobisType = new cDescriptorType("Mahalanobis Distance", true, 1); #region Compute the Threshold int DegreeOfFreedom = cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptors().Count; cExtendedTable T = new cExtendedTable(); T.Add(new cExtendedList()); T[0].Add((double)MainWindow.numericUpDownPValue.Value); cFunctions F = new cFunctions(); F.SetInputData(T); F.IsInverse = true; F.DegreeOfFreedom = DegreeOfFreedom; F.Run(); double ThresholdForMahalanobis = Math.Sqrt(F.GetOutPut()[1][0]); #endregion int IdxClassForNonOutliers = 1; foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { for (int Col = 0; Col < cGlobalInfo.CurrentScreening.Columns; Col++) for (int Row = 0; Row < cGlobalInfo.CurrentScreening.Rows; Row++) { cWell TmpWell = TmpPlate.GetWell(Col, Row, false); if (TmpWell == null) continue; double ValueDistance = TmpWell.GetAverageValuesList(true)[0].Dist_Mahalanobis(ListMeans, cI.GetOutPut()); if (ValueDistance > ThresholdForMahalanobis || double.IsNaN(ValueDistance) ) // that's an outlier { TmpWell.SetClass(IdxClassForOutliers); } else { TmpWell.SetClass(IdxClassForNonOutliers); } if (MainWindow.checkBoxDistAsDesc.Checked) { cListSignature LDesc = new cListSignature(); cSignature NewDesc = new cSignature(ValueDistance, MahalanobisType, cGlobalInfo.CurrentScreening); LDesc.Add(NewDesc); TmpWell.AddSignatures(LDesc); } } } if (MainWindow.checkBoxDistAsDesc.Checked) { cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(MahalanobisType); } cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay(); cGlobalInfo.CurrentScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; idxP++) cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax(); }
private void covarianceMatrixToolStripMenuItem_Click(object sender, EventArgs e) { if (checkedListBoxActiveDescriptors.CheckedItems.Count <= 1) { MessageBox.Show("At least two descriptors have to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } cGUI_ListClasses GUI_ListClasses = new cGUI_ListClasses(); GUI_ListClasses.IsCheckBoxes = true; GUI_ListClasses.IsSelectAll = true; if (GUI_ListClasses.Run().IsSucceed == false) return; cExtendedList ListClassSelected = GUI_ListClasses.GetOutPut()[0]; if (ListClassSelected.Sum() < 1) { MessageBox.Show("At least one classe has to be selected.", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } cDisplayToWindow vD = new cDisplayToWindow(); cDesignerTab DT = new cDesignerTab(); cCovarianceMatrix CM = new cCovarianceMatrix(); // CM.FTestTails = eFTestTails.BOTH; if (this.ProcessModeplateByPlateToolStripMenuItem.Checked) { foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesActive) { cListWells ListWellsToProcess = new cListWells(null); foreach (cWell item in TmpPlate.ListActiveWells) if ((item.GetCurrentClassIdx() != -1) && (ListClassSelected[item.GetCurrentClassIdx()] == 1)) ListWellsToProcess.Add(item); cExtendedTable NewTable = new cExtendedTable(ListWellsToProcess, true); CM.SetInputData(NewTable); CM.Run(); //cViewerHeatMap VHM = new cViewerHeatMap(); cViewerTable VHM = new cViewerTable(); VHM.SetInputData(CM.GetOutPut()); //VHM.IsDisplayValues = true; vD.Title = "Covariance - " + TmpPlate.GetName() + " (" + ListWellsToProcess.Count + " wells)"; VHM.Run(); DT.SetInputData(VHM.GetOutPut()); } } else if (this.ProcessModeEntireScreeningToolStripMenuItem.Checked) { cListWells ListWellsToProcess = new cListWells(null); foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesActive) { foreach (cWell item in TmpPlate.ListActiveWells) if ((item.GetCurrentClassIdx() != -1) && (ListClassSelected[item.GetCurrentClassIdx()] == 1)) ListWellsToProcess.Add(item); } cExtendedTable NewTable = new cExtendedTable(ListWellsToProcess, true); // cTwoSampleFTest CM = new cTwoSampleFTest(); CM.SetInputData(NewTable); CM.Run(); // cViewerHeatMap VHM = new cViewerHeatMap(); cViewerTable VHM = new cViewerTable(); VHM.SetInputData(CM.GetOutPut()); //VHM.IsDisplayValues = true; vD.Title = "Covariance - Entire screening (" + ListWellsToProcess.Count + " wells)"; VHM.Run(); DT.SetInputData(VHM.GetOutPut()); } else { cListWells ListWellsToProcess = new cListWells(null); foreach (cWell item in cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().ListActiveWells) if ((item.GetCurrentClassIdx() != -1) && (ListClassSelected[item.GetCurrentClassIdx()] == 1)) ListWellsToProcess.Add(item); cExtendedTable NewTable = new cExtendedTable(ListWellsToProcess, true); // cTwoSampleFTest CM = new cTwoSampleFTest(); CM.SetInputData(NewTable); CM.Run(); //cViewerHeatMap VHM = new cViewerHeatMap(); cViewerTable VHM = new cViewerTable(); VHM.SetInputData(CM.GetOutPut()); //VHM.IsDisplayValues = true; vD.Title = "Covariance - " + cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().GetName() + " (" + ListWellsToProcess.Count + " wells)"; VHM.Run(); DT.SetInputData(VHM.GetOutPut()); } DT.Run(); vD.SetInputData(DT.GetOutPut()); // vD.Title = "F-Test"; vD.Run(); vD.Display(); }