Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        private void ToolStripMenuItem_OperationsInverse(object sender, EventArgs e)
        {
            cInverse CI = new cInverse();
            CI.SetInputData(this.Input);
            CI.Run();

            cDisplayExtendedTable CDT = new cDisplayExtendedTable();
            CDT.SetInputData(CI.GetOutPut());
            CDT.Run();
        }