Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15369


Ignore:
Timestamp:
09/19/17 07:15:37 (7 years ago)
Author:
gkronber
Message:

#2789 added penalized regression splines as implemented in alglib.

Location:
branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental
Files:
2 edited

Legend:

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

    r15365 r15369  
    151151      if (problemData.Dataset.VariableHasType<double>(inputVar)) {
    152152        // Umständlich!
    153         return Splines.CalculateSmoothingSplineReinschWithAutomaticTolerance(
     153        return Splines.CalculatePenalizedRegressionSpline(
    154154          problemData.Dataset.GetDoubleValues(inputVar, problemData.TrainingIndices).ToArray(),
    155           (double[])target.Clone(),
    156           new string[] { inputVar },
    157           targetVar: problemData.TargetVariable);
     155          (double[])target.Clone(), lambda,
     156          problemData.TargetVariable, new string[] { inputVar }
     157          );
    158158      } else return new ConstantModel(target.Average(), problemData.TargetVariable);
    159159    }
  • branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/Splines.cs

    r15365 r15369  
    7272          "Smoothing Spline (Reinsch)",
    7373          "Smoothing Spline (Reinsch with automatic tolerance determination using CV)",
    74           "B-Spline Smoothing"
     74          "B-Spline Smoothing",
     75          "Penalized Regression Spline (alglib)"
    7576      }.Select(s => new StringValue(s)));
    7677
     
    158159              break;
    159160            }
     161          case "Penalized Regression Spline (alglib)":
     162          {
     163              var lambda = ((IValueParameter<DoubleValue>)Parameters["Lambda"]).Value.Value; // controls extent of smoothing
     164              var model = CalculatePenalizedRegressionSpline(x, y, lambda, Problem.ProblemData.TargetVariable, inputVars);
     165              var targetVar = Problem.ProblemData.TargetVariable;
     166              var problemData = (IRegressionProblemData)Problem.ProblemData.Clone();
     167              Results.Add(new Result("Solution", model.CreateRegressionSolution(problemData)));
     168
     169              break;
     170          }
    160171          default: throw new NotSupportedException();
    161172        }
    162173
    163174      }
     175    }
     176
     177
     178
     179    public static IRegressionModel CalculatePenalizedRegressionSpline(double[] x, double[] y, double lambda, string targetVar, string[] inputVars)
     180    {
     181      int info;
     182      alglib.spline1dinterpolant interpolant;
     183      alglib.spline1dfitreport rep;
     184      int n = x.Length;
     185      n = (int)Math.Max(50, 3 * Math.Sqrt(n));
     186
     187      alglib.spline1dfitpenalized(x, y, n, lambda, out info, out interpolant, out rep);
     188      return new Spline1dModel(interpolant, targetVar, inputVars);
    164189    }
    165190
Note: See TracChangeset for help on using the changeset viewer.