Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/03/17 20:28:37 (6 years ago)
Author:
gkronber
Message:

#2789 created x64 build of CUBGCV algorithm, fixed some bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/Splines.cs

    r15442 r15449  
    6868          "Smoothing Spline (Reinsch with automatic tolerance determination using LOOCV)",
    6969          "B-Spline Smoothing",
    70           "Penalized Regression Spline (alglib)"
     70          "Penalized Regression Spline (alglib)",
     71          "CUBGCV"
    7172      }.Select(s => new StringValue(s)));
    7273
    73       Parameters.Add(new ConstrainedValueParameter<StringValue>("Type", "The type of spline (as supported by alglib)", validTypes, validTypes.First()));
     74      Parameters.Add(new ConstrainedValueParameter<StringValue>("Type", "The type of spline (as supported by alglib)", validTypes, validTypes.Last()));
    7475      Parameters.Add(new ValueParameter<DoubleValue>("Lambda", "Regularization parameter for smoothing splines (0..+inf)", new DoubleValue(100)));
    7576      Parameters.Add(new ValueParameter<DoubleValue>("StdDev (noise)", "Known error in y values. Used only be Reinsch Smoothing Splines", new DoubleValue(0.1)));
     
    151152              Results.Add(new Result("Optimal tolerance", new DoubleValue(optTol)));
    152153              Results.Add(new Result("RMSE (LOO-CV)", new DoubleValue(looRMSE)));
     154              break;
     155            }
     156          case "CUBGCV": {
     157              CubicSplineGCV.CubGcvReport report;
     158              var model =
     159                CubicSplineGCV.CalculateCubicSpline(x, y,
     160                Problem.ProblemData.TargetVariable, inputVars, out report);
     161              var targetVar = Problem.ProblemData.TargetVariable;
     162              var problemData = (IRegressionProblemData)Problem.ProblemData.Clone();
     163              Results.Add(new Result("Solution", model.CreateRegressionSolution(problemData)));
     164              Results.Add(new Result("GCV", new DoubleValue(report.generalizedCrossValidation)));
     165              Results.Add(new Result("Estimated error variance", new DoubleValue(report.estimatedErrorVariance)));
     166              Results.Add(new Result("Estimated RSS degrees of freedom", new DoubleValue(report.estimatedRSSDegreesOfFreedom)));
     167              Results.Add(new Result("Estimated treu mean squared error at data points", new DoubleValue(report.estimatedTrueMeanSquaredErrorAtDataPoints)));
     168              Results.Add(new Result("Mean square of DF", new DoubleValue(report.meanSquareOfDf)));
     169              Results.Add(new Result("Mean square residual", new DoubleValue(report.meanSquareResiudal)));
     170              Results.Add(new Result("Smoothing parameter (optimized for GCV)", new DoubleValue(report.smoothingParameter)));
    153171              break;
    154172            }
     
    489507      }
    490508
     509      // extrapolate for xx > x[n2]
     510      b[b.Length] = b[b.Length - 1];
     511      d[1] = 0;
     512
    491513      return new ReinschSmoothingSplineModel(a, b, c, d, x, targetVar, inputVars);
    492514    }
     
    550572    }
    551573
    552     private static void SortAndBin(double[] x, double[] y, double[] w, out double[] x2, out double[] y2, out double[] w2, bool scaling = false) {
     574    public static void SortAndBin(double[] x, double[] y, double[] w, out double[] x2, out double[] y2, out double[] w2, bool scaling = false) {
    553575      var sortedIdx = Enumerable.Range(0, x.Length).ToArray();
    554576      // sort by x
     
    679701      this.scale = scale;
    680702      this.offset = offset;
    681 
    682       // extrapolate for xx > x[n2]
    683       b[b.Length] = b[b.Length - 1];
    684       d[1] = 0;
    685       // d[b.Length] = -d[d.Length - 1];
    686703    }
    687704
     
    695712
    696713    public double GetEstimatedValue(double xx) {
    697       int n = x.Length;
     714      int n = a.Length;
    698715      if (xx <= x[1]) {
    699716        double h = xx - x[1];
Note: See TracChangeset for help on using the changeset viewer.