Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/22/12 16:12:32 (12 years ago)
Author:
gkronber
Message:

#1902: fixed an issue that occurs in scaling if a variable is effectively constant in the training partition

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/Scaling.cs

    r8463 r8829  
    4444      foreach (var variable in variables) {
    4545        var values = ds.GetDoubleValues(variable, rows);
    46         var min = values.Min();
    47         var max = values.Max();
     46        var min = values.Where(x => !double.IsNaN(x)).Min();
     47        var max = values.Where(x => !double.IsNaN(x)).Max();
    4848        scalingParameters[variable] = Tuple.Create(min, max);
    4949      }
     
    5757      double min = scalingParameters[variable].Item1;
    5858      double max = scalingParameters[variable].Item2;
    59       return ds.GetDoubleValues(variable, rows).Select(x => (x - min) / (max - min));
     59      if (min.IsAlmost(max)) return rows.Select(i => 0.0); // return enumerable of zeros
     60      return ds.GetDoubleValues(variable, rows).Select(x => (x - min) / (max - min));  // scale to range [0..1]
    6061    }
    6162
Note: See TracChangeset for help on using the changeset viewer.