Changeset 15369
- Timestamp:
- 09/19/17 07:15:37 (7 years ago)
- 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 151 151 if (problemData.Dataset.VariableHasType<double>(inputVar)) { 152 152 // Umständlich! 153 return Splines.Calculate SmoothingSplineReinschWithAutomaticTolerance(153 return Splines.CalculatePenalizedRegressionSpline( 154 154 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 ); 158 158 } else return new ConstantModel(target.Average(), problemData.TargetVariable); 159 159 } -
branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/Splines.cs
r15365 r15369 72 72 "Smoothing Spline (Reinsch)", 73 73 "Smoothing Spline (Reinsch with automatic tolerance determination using CV)", 74 "B-Spline Smoothing" 74 "B-Spline Smoothing", 75 "Penalized Regression Spline (alglib)" 75 76 }.Select(s => new StringValue(s))); 76 77 … … 158 159 break; 159 160 } 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 } 160 171 default: throw new NotSupportedException(); 161 172 } 162 173 163 174 } 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); 164 189 } 165 190
Note: See TracChangeset
for help on using the changeset viewer.