Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17889


Ignore:
Timestamp:
03/12/21 14:43:07 (4 years ago)
Author:
mkommend
Message:

#2898: Minor changes in Spline1dModel (added field for inputVariable, and named model and solution more appropriately).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/GAM/Spline1dModel.cs

    r17867 r17889  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Problems.DataAnalysis;
     28using System;
    2829
    2930namespace HeuristicLab.Algorithms.DataAnalysis {
     
    3536    private alglib.spline1d.spline1dinterpolant interpolant;
    3637
     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];
     43      }
     44    }
     45
    3746    [Storable]
    38     private readonly string[] variablesUsedForPrediction;
    39     public override IEnumerable<string> VariablesUsedForPrediction => variablesUsedForPrediction;
     47    private string inputVariable;
     48    public override IEnumerable<string> VariablesUsedForPrediction => new[] { inputVariable };
    4049
    4150    [StorableConstructor]
     
    4554
    4655    private Spline1dModel(Spline1dModel orig, Cloner cloner) : base(orig, cloner) {
    47       this.variablesUsedForPrediction = orig.VariablesUsedForPrediction.ToArray();
     56      this.inputVariable = orig.inputVariable;
    4857      this.interpolant = (alglib.spline1d.spline1dinterpolant)orig.interpolant.make_copy();
    4958    }
    5059    public Spline1dModel(alglib.spline1d.spline1dinterpolant interpolant, string targetVar, string inputVar)
    51       : base(targetVar, "Spline model (1d)") {
     60      : base(targetVar, $"Spline model ({inputVar})") {
    5261      this.interpolant = (alglib.spline1d.spline1dinterpolant)interpolant.make_copy();
    53       this.variablesUsedForPrediction = new string[] { inputVar };
     62      this.inputVariable = inputVar;     
    5463    }
    5564
     
    5867
    5968    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    60       return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
     69      var solution =  new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
     70      solution.Name = $"Regression Spline ({inputVariable})";
     71
     72      return solution;
    6173    }
    6274
     
    6476
    6577    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    66       return dataset.GetDoubleValues(VariablesUsedForPrediction.First(), rows).Select(GetEstimatedValue);
     78      return dataset.GetDoubleValues(inputVariable, rows).Select(GetEstimatedValue);
    6779    }
    6880
Note: See TracChangeset for help on using the changeset viewer.