예제 #1
0
파일: Model.cs 프로젝트: turn11/gpdotnet
        public void InitNewModel()
        {
            if (ExpData == null)
            {
                throw new Exception("Projects is not initialized in the model.");
            }

            string par = "";

            //first time setting parameter
            if (ExpData.GetOutputColumnType() == ColumnType.Binary)
            {
                par = initBinaryClassParameters();
            }
            else if (ExpData.GetOutputColumnType() == ColumnType.Category)
            {
                par = initMultiClassParameters();
            }
            else
            {
                par = initRegressionParameters();
            }
            //
            var p = Parameters.FromString(par);
            //
            var fs = new Function[4] {
                new Function()
                {
                    Selected = true, Id = 2000, Weight = 1
                },
                new Function()
                {
                    Selected = true, Id = 2001, Weight = 1
                },
                new Function()
                {
                    Selected = true, Id = 2002, Weight = 1
                },
                new Function()
                {
                    Selected = true, Id = 2003, Weight = 1
                },
            };
            var t = terminalSet(p).ToArray();

            //
            Factory             = new Factory();
            Factory.FunctionSet = fs;
            Factory.TerminalSet = t;
            Factory.Parameters  = p;
        }
예제 #2
0
파일: Model.cs 프로젝트: turn11/gpdotnet
        public double[] calculateOutput(bool isTraining, bool probValue = false)
        {
            if (Factory.ProgresReport.BestSolution == null)
            {
                return(null);
            }
            //
            var ch  = Factory.ProgresReport.BestSolution;//.expressionTree;
            var par = Factory.Parameters;

            if (par.RootFunctionNode == null)
            {
                setLearningType(par);
            }
            double[] yc = null;
            if (ch != null)
            {
                yc = Inputs.CalculateOutput(ch, par, isTraining);//gp

                //no testing data set
                if (yc == null)
                {
                    return(null);
                }

                //de normalize output
                double[] output = yc;
                for (int i = 0; i < yc.Length; i++)
                {
                    //calculate de normalization
                    if (ExpData.GetOutputColumnType() == ColumnType.Numeric)
                    {
                        double[] normRow = new double[1] {
                            yc[i]
                        };
                        output[i] = ExpData.GetDecodedOutputRow(normRow)[0];
                    }
                    else
                    {
                        if (par.RootFunctionNode.Id == 2048) //sigmoid
                        {
                            if (probValue)                   //when model is evaluate we need probability f event in order to optimize threshold value
                            {
                                output[i] = yc[i];
                            }
                            else
                            {
                                output[i] = yc[i] > par.RootFunctionNode.Parameter ? 1 : 0;
                            }
                        }
                        else if (par.RootFunctionNode.Id == 2050)//step
                        {
                            output[i] = Math.Truncate(yc[i]);
                        }
                        else
                        {
                            output[i] = Math.Truncate(yc[i]);
                        }
                    }
                }
                return(output);
            }
            return(null);//no solution yet
        }
예제 #3
0
파일: Model.cs 프로젝트: turn11/gpdotnet
        public bool setLearningType(Parameters param)
        {
            //determine the type of ML
            param.OutputType = ExpData.GetOutputColumnType();
            if (param.OutputType == ColumnType.Binary)
            {
                if (param.RootName.StartsWith("Sigm"))
                {
                    param.RootFunctionNode = new Function()
                    {
                        Id = 2048, Name = "Sigmoid", Arity = 1, HasParameter = true, Parameter = param.Threshold, Parameter2 = 2
                    }
                }
                ;
                else if (param.RootName.StartsWith("Step"))
                {
                    param.RootFunctionNode = new Function()
                    {
                        Id = 2049, Name = "Step", Arity = 1, HasParameter = true, Parameter = param.Threshold, Parameter2 = 2
                    }
                }
                ;
                else if (param.RootName.StartsWith("Scal"))
                {
                    param.RootFunctionNode = new Function()
                    {
                        Id = 2050, Name = "SSigmoid", Arity = 1, HasParameter = true, Parameter = param.Threshold, Parameter2 = 2
                    }
                }
                ;
                else if (param.RootName.StartsWith("Soft"))
                {
                    param.RootFunctionNode = new Function()
                    {
                        Id = 2051, Name = "Softmax", Arity = 2, Parameter2 = 2
                    }
                }
                ;
            }
            else if (param.OutputType == ColumnType.Category)
            {
                var clss = ExpData.GetColumnsFromOutput().FirstOrDefault().Statistics.Categories.Count;

                if (param.RootName.StartsWith("Scal"))
                {
                    param.RootFunctionNode = new Function()
                    {
                        Id = 2050, Name = "SSigmoid", Arity = 1, HasParameter = true, Parameter = clss, Parameter2 = clss
                    }
                }
                ;
                else if (param.RootName.StartsWith("Soft"))
                {
                    param.RootFunctionNode = new Function()
                    {
                        Id = 2051, Name = "Softmax", Arity = clss, Parameter2 = clss
                    }
                }
                ;
                else
                {
                    throw new Exception("Predefined Root Node is not compatible with multi class classification modeling!");
                }
            }
            else if (param.OutputType == ColumnType.Numeric)
            {
                if (param.RootName.StartsWith("Pol3"))
                {
                    param.RootFunctionNode = Globals.GetFunction(2039);// new Function() { Id = 2050, Name = "P3", Arity = 1, HasParameter = true, Parameter = clss, Parameter2 = clss };
                }
            }
            return(true);
        }