Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/15/16 21:23:43 (8 years ago)
Author:
gkronber
Message:

#2697:

  • removed AlglibUtil.cs and added an extension method .ToArray(names, rows) to IDataset instead.
  • refactored transformation so that it is possible to apply an transformation without resetting the parameters
  • Used transformations instead of Scaling as far as possible.
  • Moved TakeEvery extension method to HL.Common
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r14322 r14393  
    119119      if (IsCompatibilityLoaded) {
    120120        // no scaling
    121         inputMatrix = AlglibUtil.PrepareInputMatrix(dataset,
     121        inputMatrix = dataset.ToArray(
    122122          this.allowedInputVariables.Concat(new string[] { targetVariable }),
    123123          rows);
     
    167167
    168168    private static double[,] CreateScaledData(IDataset dataset, IEnumerable<string> variables, IEnumerable<int> rows, double[] offsets, double[] factors) {
    169       var x = new double[rows.Count(), variables.Count()];
    170       var colIdx = 0;
    171       foreach (var variableName in variables) {
    172         var rowIdx = 0;
    173         foreach (var val in dataset.GetDoubleValues(variableName, rows)) {
    174           x[rowIdx, colIdx] = (val + offsets[colIdx]) * factors[colIdx];
    175           rowIdx++;
    176         }
    177         colIdx++;
    178       }
    179       return x;
     169      var transforms =
     170        variables.Select(
     171          (_, colIdx) =>
     172            new LinearTransformation(variables) { Addend = offsets[colIdx] * factors[colIdx], Multiplier = factors[colIdx] });
     173      return dataset.ToArray(variables, transforms, rows);
    180174    }
    181175
     
    187181      double[,] inputData;
    188182      if (IsCompatibilityLoaded) {
    189         inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
     183        inputData = dataset.ToArray(allowedInputVariables, rows);
    190184      } else {
    191185        inputData = CreateScaledData(dataset, allowedInputVariables, rows, offsets, weights);
     
    223217      double[,] inputData;
    224218      if (IsCompatibilityLoaded) {
    225         inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
     219        inputData = dataset.ToArray(allowedInputVariables, rows);
    226220      } else {
    227221        inputData = CreateScaledData(dataset, allowedInputVariables, rows, offsets, weights);
Note: See TracChangeset for help on using the changeset viewer.