Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15362


Ignore:
Timestamp:
09/14/17 07:58:53 (7 years ago)
Author:
gkronber
Message:

#2789 testing Math.Numerics splines

Location:
branches/MathNetNumerics-Exploration-2789
Files:
4 edited

Legend:

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

    r15352 r15362  
    120120      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath>
    121121    </Reference>
     122    <Reference Include="MathNet.Numerics, Version=3.20.0.0, Culture=neutral, processorArchitecture=MSIL">
     123      <HintPath>..\packages\MathNet.Numerics.3.20.0\lib\net40\MathNet.Numerics.dll</HintPath>
     124    </Reference>
    122125    <Reference Include="System" />
    123126    <Reference Include="System.Core" />
  • branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/Splines.cs

    r15352 r15362  
    3636using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3737using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
     38using MathNet.Numerics.Interpolation;
    3839
    3940namespace HeuristicLab.Algorithms.DataAnalysis.Experimental {
     
    5960      var validTypes = new ItemSet<StringValue>(
    6061        new[] {
    61         "Monotone", "Akima", "Catmull-Rom", "Cubic", "Linear"
     62        "Monotone", "Akima", "Catmull-Rom", "Cubic", "Linear",
     63          "Cubic - Natural (Math.NET)",
     64          "Polynomial (Math.NET)",
     65          "Rational (Math.NET)",
     66          "LogLinear (Math.NET)",
     67          "Common (Math.NET)",
    6268      }.Select(s => new StringValue(s)));
    6369
     
    8389        switch (type) {
    8490          case "Monotone":
    85             alglib.spline1dbuildmonotone(x, y, out c); break;
     91            alglib.spline1dbuildmonotone(x, y, out c);
     92            AddAlglibSplineResult(c, inputVars);
     93            break;
    8694          case "Akima":
    87             alglib.spline1dbuildakima(x, y, out c); break;
     95            alglib.spline1dbuildakima(x, y, out c); AddAlglibSplineResult(c, inputVars);
     96            break;
     97            ;
    8898          case "Catmull-Rom":
    89             alglib.spline1dbuildcatmullrom(x, y, out c); break;
     99            alglib.spline1dbuildcatmullrom(x, y, out c); AddAlglibSplineResult(c, inputVars);
     100            break;
     101
    90102          case "Cubic":
    91             alglib.spline1dbuildcubic(x, y, out c); break;
     103            alglib.spline1dbuildcubic(x, y, out c); AddAlglibSplineResult(c, inputVars);
     104            break;
     105
    92106          case "Linear":
    93             alglib.spline1dbuildlinear(x, y, out c); break;
    94 
     107            alglib.spline1dbuildlinear(x, y, out c); AddAlglibSplineResult(c, inputVars);
     108            break;
     109          case "Cubic - Natural (Math.NET)": {
     110              var spline = MathNet.Numerics.Interpolation.CubicSpline.InterpolateNatural(x, y);
     111              AddMathNetSplineResult(spline, inputVars);
     112              break;
     113            }
     114          case "Common (Math.NET)": {
     115              var spline = MathNet.Numerics.Interpolate.Common(x, y);
     116              AddMathNetSplineResult(spline, inputVars);
     117              break;
     118            }
     119          case "LogLinear (Math.NET)": {
     120              var spline = MathNet.Numerics.Interpolate.LogLinear(x, y);
     121              AddMathNetSplineResult(spline, inputVars);
     122              break;
     123            }
     124          case "Polynomial (Math.NET)": {
     125              var spline = MathNet.Numerics.Interpolate.Polynomial(x, y);
     126              AddMathNetSplineResult(spline, inputVars);
     127              break;
     128            }
     129          case "Rational (Math.NET)": {
     130              var spline = MathNet.Numerics.Interpolate.RationalWithoutPoles(x, y);
     131              AddMathNetSplineResult(spline, inputVars);
     132              break;
     133            }
    95134          default: throw new NotSupportedException();
    96135        }
    97136
    98         Results.Add(new Result("Solution", new RegressionSolution(new Spline1dModel(c, Problem.ProblemData.TargetVariable, inputVars),
    99           (IRegressionProblemData)Problem.ProblemData.Clone())));
    100137      }
     138    }
     139
     140    private void AddAlglibSplineResult(alglib.spline1dinterpolant c, string[] inputVars) {
     141      Results.Add(new Result("Solution", new RegressionSolution(new Spline1dModel(c, Problem.ProblemData.TargetVariable, inputVars),
     142        (IRegressionProblemData)Problem.ProblemData.Clone())));
     143
     144    }
     145    private void AddMathNetSplineResult(IInterpolation c, string[] inputVars) {
     146      Results.Add(new Result("Solution", new RegressionSolution(new MathNetSplineModel(c, Problem.ProblemData.TargetVariable, inputVars),
     147        (IRegressionProblemData)Problem.ProblemData.Clone())));
     148
    101149    }
    102150  }
     
    138186    }
    139187  }
     188
     189
     190  // UNFINISHED
     191  public class MathNetSplineModel : NamedItem, IRegressionModel {
     192    private IInterpolation interpolant;
     193
     194    public string TargetVariable { get; set; }
     195
     196    public IEnumerable<string> VariablesUsedForPrediction { get; private set; }
     197
     198    public event EventHandler TargetVariableChanged;
     199
     200    public MathNetSplineModel(MathNetSplineModel orig, Cloner cloner) : base(orig, cloner) {
     201      this.TargetVariable = orig.TargetVariable;
     202      this.VariablesUsedForPrediction = orig.VariablesUsedForPrediction.ToArray();
     203      this.interpolant = orig.interpolant; // TODO COPY!
     204    }
     205    public MathNetSplineModel(IInterpolation interpolant, string targetVar, string[] inputs) : base("SplineModel", "SplineModel") {
     206      this.interpolant = interpolant;
     207      this.TargetVariable = targetVar;
     208      this.VariablesUsedForPrediction = inputs;
     209    }
     210
     211    public override IDeepCloneable Clone(Cloner cloner) {
     212      return new MathNetSplineModel(this, cloner);
     213    }
     214
     215    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     216      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
     217    }
     218
     219    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     220      foreach (var x in dataset.GetDoubleValues(VariablesUsedForPrediction.First(), rows)) {
     221        yield return interpolant.Interpolate(x);
     222      }
     223    }
     224  }
    140225}
  • branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/packages.config

    r15349 r15362  
    44  <package id="FSharp.Core" version="4.0.0.1" targetFramework="net46" />
    55  <package id="FSharp.Quotations.Evaluator" version="1.0.6" targetFramework="net46" />
     6  <package id="MathNet.Numerics" version="3.20.0" targetFramework="net46" />
    67</packages>
  • branches/MathNetNumerics-Exploration-2789/packages

    • Property svn:ignore
      •  

        old new  
        66FSharp.Quotations.Evaluator.1.0.6
        77FSharp.Core.4.0.0.1
         8MathNet.Numerics.3.20.0
Note: See TracChangeset for help on using the changeset viewer.