Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17390


Ignore:
Timestamp:
12/20/19 13:21:43 (5 years ago)
Author:
djoedick
Message:

#3044: Added new implementation for transformation of input variables in KernelRidgeRegressionModel and added helper methods in transformation base class.

Location:
branches/3044_variableScaling
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3044_variableScaling/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelRidgeRegressionModel.cs

    r17180 r17390  
    2727using HEAL.Attic;
    2828using HeuristicLab.Problems.DataAnalysis;
     29using HeuristicLab.Data;
    2930
    3031namespace HeuristicLab.Algorithms.DataAnalysis {
     
    155156      this.kernel = (ICovarianceFunction)kernel.Clone();
    156157      this.lambda = lambda;
    157       if (scaleInputs) scaling = CreateScaling(dataset, rows, this.allowedInputVariables);
     158      if (scaleInputs) {
     159        var trans = new ShiftToRangeTransformation(allowedInputVariables);
     160        trans.Range.Start = 0;
     161        trans.Range.End = 1;
     162        scaling = Transformation.CreateTransformations(trans, dataset, rows, this.allowedInputVariables);
     163      }
     164
    158165      trainX = ExtractData(dataset, rows, this.allowedInputVariables, scaling);
    159166      var y = dataset.GetDoubleValues(targetVariable, rows).ToArray();
     
    201208    }
    202209
    203     private static ITransformation<double>[] CreateScaling(IDataset dataset, int[] rows, IReadOnlyCollection<string> allowedInputVariables) {
    204       var trans = new ITransformation<double>[allowedInputVariables.Count];
    205       int i = 0;
    206       foreach (var variable in allowedInputVariables) {
    207         var lin = new LinearTransformation(allowedInputVariables);
    208         var max = dataset.GetDoubleValues(variable, rows).Max();
    209         var min = dataset.GetDoubleValues(variable, rows).Min();
    210         lin.Multiplier = 1.0 / (max - min);
    211         lin.Addend = -min / (max - min);
    212         trans[i] = lin;
    213         i++;
    214       }
    215       return trans;
    216     }
    217 
    218210    private static double[,] ExtractData(IDataset dataset, IEnumerable<int> rows, IReadOnlyCollection<string> allowedInputVariables, ITransformation<double>[] scaling = null) {
    219211      double[][] variables;
  • branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs

    r17389 r17390  
    6161    protected Transformation(IEnumerable<string> allowedColumns) {
    6262      var allowed = new ItemSet<StringValue>(allowedColumns.Select(e => new StringValue(e)));
    63       Parameters.Add(new ConstrainedValueParameter<StringValue>(ColumnParameterName, "Column used for the Transformation", allowed));
     63      Parameters.Add(new ConstrainedValueParameter<StringValue>(ColumnParameterName, "Column used for the Transformation", allowed, allowed.First()));
    6464    }
     65
     66
     67    //TODO: Fill XML comments
     68    /// <summary>
     69    /// Creates transformation for the provided input variables.
     70    /// </summary>
     71    /// <param name="transformation"></param>
     72    /// <param name="dataset"></param>
     73    /// <param name="rows"></param>
     74    /// <param name="allowedInputVariables"></param>
     75    /// <returns></returns>
     76    public static ITransformation<double>[] CreateTransformations(ITransformation<double> transformation, IDataset dataset, int[] rows, IReadOnlyCollection<string> allowedInputVariables) {
     77      var trans = new ITransformation<double>[allowedInputVariables.Count];
     78      int i = 0;
     79      foreach (var variable in allowedInputVariables) {
     80        var trans_clone = (ITransformation<double>)transformation.Clone();
     81        trans_clone.Column = variable;
     82        trans_clone.ConfigureParameters(dataset.GetDoubleValues(variable, rows));
     83        trans[i] = trans_clone;
     84        i++;
     85      }
     86      return trans;
     87    }
     88
    6589  }
    6690
     
    85109
    86110    public abstract bool Check(IEnumerable<T> data, out string errorMsg);
     111
     112
    87113  }
    88114}
  • branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/ITransformation.cs

    r17180 r17390  
    2828  public interface ITransformation : IParameterizedItem {
    2929    string ShortName { get; }
    30     string Column { get; }
     30    string Column { get; set; }
    3131  }
    3232
Note: See TracChangeset for help on using the changeset viewer.