public override IRegressionModel Build(IRegressionProblemData pd, IRandom random, CancellationToken cancellationToken, out int numberOfParameters)
        {
            if (pd.Dataset.Rows < MinLeafSize(pd))
            {
                throw new ArgumentException("The number of training instances is too small to create a Gaussian process model");
            }
            Regression.Problem = new RegressionProblem {
                ProblemData = pd
            };
            var cvscore = double.MaxValue;
            GaussianProcessRegressionSolution sol = null;

            for (var i = 0; i < Tries; i++)
            {
                var res   = RegressionTreeUtilities.RunSubAlgorithm(Regression, random.Next(), cancellationToken);
                var t     = res.Select(x => x.Value).OfType <GaussianProcessRegressionSolution>().FirstOrDefault();
                var score = ((DoubleValue)res["Negative log pseudo-likelihood (LOO-CV)"].Value).Value;
                if (score >= cvscore || t == null || double.IsNaN(t.TrainingRSquared))
                {
                    continue;
                }
                cvscore = score;
                sol     = t;
            }
            Regression.Runs.Clear();
            if (sol == null)
            {
                throw new ArgumentException("Could not create Gaussian process model");
            }

            numberOfParameters = pd.Dataset.Rows + 1
                                 + Regression.CovarianceFunction.GetNumberOfParameters(pd.AllowedInputVariables.Count())
                                 + Regression.MeanFunction.GetNumberOfParameters(pd.AllowedInputVariables.Count());
            return(sol.Model);
        }
示例#2
0
        public override IRegressionModel Build(IRegressionProblemData pd, IRandom random, CancellationToken cancellationToken, out int noParameters)
        {
            if (pd.Dataset.Rows < MinLeafSize(pd))
            {
                throw new ArgumentException("The number of training instances is too small to create a linear model");
            }
            noParameters       = pd.Dataset.Rows + 1;
            Regression.Problem = new RegressionProblem {
                ProblemData = pd
            };
            var res = RegressionTreeUtilities.RunSubAlgorithm(Regression, random.Next(), cancellationToken);
            var t   = res.Select(x => x.Value).OfType <IRegressionSolution>().FirstOrDefault();

            if (t == null)
            {
                throw new ArgumentException("No RegressionSolution was provided by the algorithm");
            }
            return(t.Model);
        }