Changeset 17970 for branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/GAM/Spline1dModel.cs
- Timestamp:
- 04/30/21 12:18:19 (3 years ago)
- Location:
- branches/3106_AnalyticContinuedFractionsRegression
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3106_AnalyticContinuedFractionsRegression
- Property svn:mergeinfo changed
-
branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/GAM/Spline1dModel.cs
r17839 r17970 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Problems.DataAnalysis; 28 using System; 28 29 29 30 namespace HeuristicLab.Algorithms.DataAnalysis { … … 35 36 private alglib.spline1d.spline1dinterpolant interpolant; 36 37 37 [Storable ]38 private readonly string[] variablesUsedForPrediction;39 public override IEnumerable<string> VariablesUsedForPrediction{40 get {41 return variablesUsedForPrediction;38 [Storable(OldName = "variablesUsedForPrediction")] 39 private string[] StorableVariablesUsedForPrediction { 40 set { 41 if (value.Length > 1) throw new ArgumentException("A one-dimensional spline model supports only one input variable."); 42 inputVariable = value[0]; 42 43 } 43 44 } 45 46 [Storable] 47 private string inputVariable; 48 public override IEnumerable<string> VariablesUsedForPrediction => new[] { inputVariable }; 44 49 45 50 [StorableConstructor] … … 49 54 50 55 private Spline1dModel(Spline1dModel orig, Cloner cloner) : base(orig, cloner) { 51 this. variablesUsedForPrediction = orig.VariablesUsedForPrediction.ToArray();52 this.interpolant = (alglib.spline1d.spline1dinterpolant)orig.interpolant.make_copy();56 this.inputVariable = orig.inputVariable; 57 if(orig.interpolant != null) this.interpolant = (alglib.spline1d.spline1dinterpolant)orig.interpolant.make_copy(); 53 58 } 54 59 public Spline1dModel(alglib.spline1d.spline1dinterpolant interpolant, string targetVar, string inputVar) 55 : base(targetVar, "Spline model (1d)") {56 this.interpolant = (alglib.spline1d.spline1dinterpolant)interpolant.make_copy(); 57 this. variablesUsedForPrediction = new string[] { inputVar };60 : base(targetVar, $"Spline model ({inputVar})") { 61 this.interpolant = (alglib.spline1d.spline1dinterpolant)interpolant.make_copy(); 62 this.inputVariable = inputVar; 58 63 } 59 64 60 65 61 public override IDeepCloneable Clone(Cloner cloner) { 62 return new Spline1dModel(this, cloner); 66 public override IDeepCloneable Clone(Cloner cloner) => new Spline1dModel(this, cloner); 67 68 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 69 var solution = new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 70 solution.Name = $"Regression Spline ({inputVariable})"; 71 72 return solution; 63 73 } 64 74 65 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 66 return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 67 } 68 69 public double GetEstimatedValue(double x) { 70 return alglib.spline1d.spline1dcalc(interpolant, x); 71 } 75 public double GetEstimatedValue(double x) => alglib.spline1d.spline1dcalc(interpolant, x, null); 72 76 73 77 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 74 var x = dataset.GetDoubleValues(VariablesUsedForPrediction.First(), rows).ToArray(); 75 foreach (var xi in x) { 76 yield return GetEstimatedValue(xi); 77 } 78 return dataset.GetDoubleValues(inputVariable, rows).Select(GetEstimatedValue); 78 79 } 79 80
Note: See TracChangeset
for help on using the changeset viewer.