Ejemplo n.º 1
0
        public cFeedBackMessage Run()
        {
            base.Start();
            if (!FeedBackMessage.IsSucceed) return FeedBackMessage;
            if (this.Input.Count > 1)
            {
                this.FeedBackMessage = new cFeedBackMessage(false, this);
                return this.FeedBackMessage;
            }

            #region parameters initialization
            //object _firstValue = base.ListProperties.FindByName("Number of Clusters");
            //int NumOfClusters = 0;
            //if (_firstValue == null)
            //{
            //    base.GenerateError("-Number of Clusters- not found !");
            //    return base.FeedBackMessage;
            //}
            //try
            //{
            //    cProperty TmpProp = (cProperty)_firstValue;
            //    NumOfClusters = (int)TmpProp.GetValue();
            //}
            //catch (Exception)
            //{
            //    base.GenerateError("-Number of Clusters- cast didn't work");
            //    return base.FeedBackMessage;
            //}
            #endregion

            cMachineLearning MachineLearning = new cMachineLearning(/*cWell.GlobalInfo*/null);

            if (ParamAlgoForClustering == null)
                ParamAlgoForClustering = MachineLearning.AskAndGetClusteringAlgo();

            if (ParamAlgoForClustering == null)
            {
                FeedBackMessage.IsSucceed = false;
                FeedBackMessage.Message = "Invalid Parameters";
                return FeedBackMessage;
            }

            MachineLearning.SelectedClusterer = MachineLearning.BuildClusterer(ParamAlgoForClustering, this.Input);

            if (MachineLearning.SelectedClusterer != null)
            {
                cLinearize L = new cLinearize();
                L.SetInputData(this.Input);
                L.Run();
                cExtendedTable Test = L.GetOutPut();

                ClusterEvaluation CE = MachineLearning.EvaluteAndDisplayClusterer(/*richTextBoxInfoClustering*/null,
                                                         null,
                                                         MachineLearning.CreateInstancesWithoutClass(this.Input));

                double[] Assign = CE.getClusterAssignments();

                base.Output = new cExtendedTable(this.Input);
                cExtendedList CL = new cExtendedList("Class ID");
                CL.SetInfo(CE.clusterResultsToString());
                base.Output.Add(CL);

                for (int i = 0; i < Assign.Length; i++)
                    base.Output[base.Output.Count-1].Add(Assign[i]);
            }

            base.End();
            return FeedBackMessage;
        }
Ejemplo n.º 2
0
        private void ToolStripMenuItem_DisplayHistograms(object sender, EventArgs e)
        {
            cDesignerTab DT = new cDesignerTab();

            cListExtendedTable ListTables = new cListExtendedTable(this.AssociatedImage);

            for (int i = 0; i < ListTables.Count; i++)
            {
                cLinearize LI = new cLinearize();
                LI.SetInputData(ListTables[i]);
                LI.Run();

                cViewerStackedHistogram VH = new cViewerStackedHistogram();
                VH.SetInputData(LI.GetOutPut());
                VH.Title = ListTables[i].Name;
                if (!VH.Run().IsSucceed) return;

                DT.SetInputData(VH.GetOutPut());
            }
            DT.Run();

            cDisplayToWindow MyDisplay = new cDisplayToWindow();
            MyDisplay.SetInputData(DT.GetOutPut());
            MyDisplay.Title = "Histograms(" + this.AssociatedImage.Name + ")";
            MyDisplay.Run();
            MyDisplay.Display();
        }
Ejemplo n.º 3
0
        private void ToolStripMenuItem_OperationsStatistics(object sender, EventArgs e)
        {
            cExtendedTable ET = new cExtendedTable();
            ET.Name = " Statistics(" + this.Input.Name + ")";

            cLinearize L = new cLinearize();
            L.SetInputData(this.Input);
            L.Run();

            cStatistics S = new cStatistics();
            S.SetInputData(L.GetOutPut());
            S.Run();

            cDisplayExtendedTable CDT = new cDisplayExtendedTable();
            CDT.SetInputData(S.GetOutPut());
            CDT.Run();
        }
Ejemplo n.º 4
0
        public cFeedBackMessage Run()
        {
            FeedBackMessage = base.Run();
            if (!FeedBackMessage.IsSucceed) return FeedBackMessage;

            if (base.IsColumnByColum)
            {
                if (Input[0].Count < 3)
                {
                    FeedBackMessage.IsSucceed = false;
                    FeedBackMessage.Message = "This process requires at least 3 values";
                    return FeedBackMessage;
                }

                this.Output = new cExtendedTable();

                foreach (var item in this.Input)
                {
                    double p = Anderson_Darling(item);

                    cExtendedList NewRes = new cExtendedList(item.Name);
                    NewRes.Add(p);

                    this.Output.Add(NewRes);
                }
            }
            else
            {
                cLinearize L = new cLinearize();
                L.SetInputData(this.Input);
                FeedBackMessage = L.Run();
                if (!FeedBackMessage.IsSucceed) return FeedBackMessage;

                if (L.GetOutPut()[0].Count < 5)
                {
                    FeedBackMessage.IsSucceed = false;
                    FeedBackMessage.Message = "This process requires at least 5 values";
                    return FeedBackMessage;
                }

                this.Output = new cExtendedTable();

                double p = Anderson_Darling(L.GetOutPut()[0]);
                //alglib.jarqueberatest(L.GetOutPut()[0].ToArray(), L.GetOutPut()[0].Count, out p);

                cExtendedList NewRes = new cExtendedList(base.Input.Name);
                NewRes.Add(p);

                this.Output.Add(NewRes);
            }

            this.Output.ListRowNames = new List<string>();
            this.Output.ListRowNames.Add("Value");

            this.Output.Name = "Anderson-Darling Test(" + this.Input + ")";
            return FeedBackMessage;
        }
Ejemplo n.º 5
0
        public cFeedBackMessage Run()
        {
            FeedBackMessage = base.Run();
            if (!FeedBackMessage.IsSucceed) return FeedBackMessage;

            /*************************************************************************
            Jarque-Bera test

            This test checks hypotheses about the fact that a  given  sample  X  is  a
            sample of normal random variable.

            Requirements:
                * the number of elements in the sample is not less than 5.

            Input parameters:
                X   -   sample. Array whose index goes from 0 to N-1.
                N   -   size of the sample. N>=5

            Output parameters:
                BothTails   -   p-value for two-tailed test.
                                If BothTails is less than the given significance level
                                the null hypothesis is rejected.
                LeftTail    -   p-value for left-tailed test.
                                If LeftTail is less than the given significance level,
                                the null hypothesis is rejected.
                RightTail   -   p-value for right-tailed test.
                                If RightTail is less than the given significance level
                                the null hypothesis is rejected.

            Accuracy of the approximation used (5<=N<=1951):

            p-value  	    relative error (5<=N<=1951)
            [1, 0.1]            < 1%
            [0.1, 0.01]         < 2%
            [0.01, 0.001]       < 6%
            [0.001, 0]          wasn't measured

            For N>1951 accuracy wasn't measured but it shouldn't be sharply  different
            from table values.

              -- ALGLIB --
                 Copyright 09.04.2007 by Bochkanov Sergey
            *************************************************************************/
            if (base.IsColumnByColum)
            {
                if (Input[0].Count < 5)
                {
                    FeedBackMessage.IsSucceed = false;
                    FeedBackMessage.Message = "This process requires at least 5 values";
                    return FeedBackMessage;
                }

                this.Output = new cExtendedTable();

                foreach (var item in this.Input)
                {
                    double p;
                    alglib.jarqueberatest(item.ToArray(), item.Count, out p);

                    cExtendedList NewRes = new cExtendedList(item.Name);
                    NewRes.Add(p);

                    this.Output.Add(NewRes);
                }
            }
            else
            {
                cLinearize L = new cLinearize();
                L.SetInputData(this.Input);
                FeedBackMessage = L.Run();
                if (!FeedBackMessage.IsSucceed) return FeedBackMessage;

                if (L.GetOutPut()[0].Count < 5)
                {
                    FeedBackMessage.IsSucceed = false;
                    FeedBackMessage.Message = "This process requires at least 5 values";
                    return FeedBackMessage;
                }

                this.Output = new cExtendedTable();

                double p;
                alglib.jarqueberatest(L.GetOutPut()[0].ToArray(), L.GetOutPut()[0].Count, out p);

                cExtendedList NewRes = new cExtendedList(base.Input.Name);
                NewRes.Add(p);

                this.Output.Add(NewRes);
            }

            this.Output.ListRowNames = new List<string>();
            this.Output.ListRowNames.Add("p-value");

            this.Output.Name = "Jarque-Bera Test(" + this.Input + ")";
            return FeedBackMessage;
        }
Ejemplo n.º 6
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;
        }