Exemplo n.º 1
0
        private void ToolStripMenuItem_OperationsClustering(object sender, EventArgs e)
        {
            cClustering CC = new cClustering();

            cExtendedTable CET = new cExtendedTable();
            foreach (DataGridViewColumn item in GridView.SelectedColumns)
                CET.Add(Input[item.Index]);

            if (this.Input.ListRowNames != null)
            {
                CET.ListRowNames = new List<string>();
                foreach (var item in this.Input.ListRowNames)
                    CET.ListRowNames.Add(item);
            }
            if (this.Input.ListTags != null)
            {
                CET.ListTags = new List<object>();
                foreach (var item in this.Input.ListTags)
                    CET.ListTags.Add(item);
            }

            CET.Name = "Sub["+this.Input.Name+"]";

            CC.SetInputData(CET);
            //CC.ListProperties.FindByName("Number of Clusters").SetNewValue((int)3);
            //CC.ListProperties.FindByName("Number of Clusters").IsGUIforValue = true;

            if (!CC.Run().IsSucceed) return;

            cDisplayExtendedTable CDT = new cDisplayExtendedTable();
            CDT.SetInputData(CC.GetOutPut());
            CDT.Run();
        }
Exemplo n.º 2
0
        private cExtendedTable GenerateArtifactMessage(cExtendedTable TmpTable, cPlate PlateToProcess)
        {
            cLinearize Lin = new cLinearize();
            Lin.SetInputData(TmpTable);
            Lin.Run();
            cExtendedTable LINTable = Lin.GetOutPut();

            cClustering Cluster = new cClustering();
            Cluster.SetInputData(LINTable);
            Cluster.ParamAlgoForClustering = this.ParamAlgoForClustering;
            if (Cluster.Run().IsSucceed == false) return null;

            this.ClusteredTable = Cluster.GetOutPut();

            // now clustering
            //if (!KMeans((int)cGlobalInfo.OptionsWindow.numericUpDownSystErrorIdentKMeansClasses.Value, PlateToProcess, CurrentDescSel))
            //{
            //    List<string> ListMessageError = new List<string>();
            //    ListMessageError.Add("K-Means Error");
            //    return ListMessageError;
            //}

            //// and finally classification

            //    return this.ComputePlateBasedClassification(MinObjectsNumber);

            //}

            cExtendedTable ET = PlateToProcess.ListWells.GetPositionRelatedSignatures();

            ET.Add(this.ClusteredTable[this.ClusteredTable.Count - 1]);

            weka.core.Instances insts = ET.CreateWekaInstancesWithClasses(); //CurrentPlateToProcess.CreateInstancesWithClassesWithPlateBasedDescriptor(Classes);
            weka.classifiers.trees.J48 ClassificationModel = new weka.classifiers.trees.J48();
            ClassificationModel.setMinNumObj(MinObjectsNumber);

            weka.core.Instances train = new weka.core.Instances(insts, 0, insts.numInstances());
            ClassificationModel.buildClassifier(train);

            string DotString = ClassificationModel.graph().Remove(0, ClassificationModel.graph().IndexOf("{") + 2);
            int DotLenght = DotString.Length;

            string NewDotString = DotString.Remove(DotLenght - 3, 3);

            // display the tree is requested
            //cDisplayTree DT = new cDisplayTree();
            //DT.SetInputData(NewDotString);
            //DT.Run();

            cExtendedTable ToReturn = new cExtendedTable(4, 1, 0);
            ToReturn.ListRowNames = new List<string>();
            ToReturn.ListTags = new List<object>();

            int CurrentPos = 0;
            int NextReturnPos = CurrentPos;
            List<int> ListNodeId = new List<int>();
            string TmpDotString = NewDotString;

            int TmpClass = 0;
            string ErrorString = "";
            int ErrorMessage = 0;

            ToReturn[0].Name = "Edge artifact";   // edge
            ToReturn[1].Name = "Column artifact";   // col
            ToReturn[2].Name = "Row artifact";   // row
            ToReturn[3].Name = "Bowl artifact";   // bowl

            #region build message
            while (NextReturnPos != -1)
            {
                int NextBracket = NewDotString.IndexOf("[");
                string StringToProcess = NewDotString.Remove(NextBracket - 1);
                string StringToProcess1 = StringToProcess.Remove(0, 1);

                if (StringToProcess1.Contains("N") == false)
                {
                    int Id = Convert.ToInt32(StringToProcess1);

                    int LabelPos = NewDotString.IndexOf("label=\"");
                    string LabelString = NewDotString.Remove(0, LabelPos + 7);
                    LabelPos = LabelString.IndexOf("\"");
                    string FinalLabel = LabelString.Remove(LabelPos);

                    // if (TmpClass < Classes)
                    {
                        if ((FinalLabel == "Dist_To_Border") || (FinalLabel == "Col_Pos") || (FinalLabel == "Row_Pos") || (FinalLabel == "Dist_To_Center"))
                        {
                            if ((FinalLabel == "Dist_To_Border") && (!ErrorString.Contains(" an edge effect")) && (!ErrorString.Contains(" a bowl effect")) && (ErrorMessage < 2))
                            {
                                if (TmpClass > 0) ErrorString += " combined with";
                                ErrorString += " an " + cGlobalInfo.ListArtifacts[0];
                                ErrorMessage++;
                                ToReturn[0][0] = 1;
                            }
                            else if ((FinalLabel == "Col_Pos") && (!ErrorString.Contains(" a column artifact")) && (ErrorMessage < 2))
                            {
                                if (TmpClass > 0) ErrorString += " combined with";
                                ErrorString += " a " + cGlobalInfo.ListArtifacts[1];
                                ErrorMessage++;
                                ToReturn[1][0] = 1;

                            }
                            else if ((FinalLabel == "Row_Pos") && (!ErrorString.Contains(" a row artifact")) && (ErrorMessage < 2))
                            {
                                if (TmpClass > 0) ErrorString += " combined with";
                                ErrorString += " a " + cGlobalInfo.ListArtifacts[2];
                                ErrorMessage++;
                                ToReturn[2][0] = 1;

                            }
                            else if ((FinalLabel == "Dist_To_Center") && (!ErrorString.Contains(" a bowl effect")) && (!ErrorString.Contains(" an edge effect")) && (ErrorMessage < 2))
                            {
                                if (TmpClass > 0) ErrorString += " combined with";
                                ErrorString += " a " + cGlobalInfo.ListArtifacts[3];
                                ErrorMessage++;
                                ToReturn[3][0] = 1;

                            }
                            TmpClass++;
                        }
                    }
                }

                NextReturnPos = NewDotString.IndexOf("\n");
                if (NextReturnPos != -1)
                {
                    string TmpString = NewDotString.Remove(0, NextReturnPos + 1);
                    NewDotString = TmpString;
                }
            }

            if (TmpClass == 0)
            {
                string NoError = "No systematic error detected !";
                ToReturn.ListTags.Add(NoError);
                //ToReturn.Add(NoError);
                return ToReturn;
            }

            string FinalString = "You have a systematic error !\nThis is " + ErrorString;

            NewDotString = TmpDotString;
            NextReturnPos = 0;
            while (NextReturnPos != -1)
            {
                int NextBracket = NewDotString.IndexOf("[");
                string StringToProcess = NewDotString.Remove(NextBracket - 1);
                string StringToProcess1 = StringToProcess.Remove(0, 1);

                if (StringToProcess1.Contains("N"))
                {
                    //// this is an edge
                    string stringNodeIdxStart = StringToProcess1.Remove(StringToProcess1.IndexOf("-"));
                    int NodeIdxStart = Convert.ToInt32(stringNodeIdxStart);

                    string stringNodeIdxEnd = StringToProcess1.Remove(0, StringToProcess1.IndexOf("N") + 1);
                    int NodeIdxSEnd = Convert.ToInt32(stringNodeIdxEnd);

                    int LabelPos = NewDotString.IndexOf("label=");
                    LabelPos += 7;

                    string CurrLabelString = NewDotString.Remove(0, LabelPos);
                }
                NextReturnPos = NewDotString.IndexOf("\n");

                if (NextReturnPos != -1)
                {
                    string TmpString = NewDotString.Remove(0, NextReturnPos + 1);
                    NewDotString = TmpString;
                }
            }

            ToReturn.ListTags.Add(FinalString + ".");
            #endregion

            return ToReturn;
        }