Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/21/18 15:24:15 (7 years ago)
Author:
pfleck
Message:

#2906 Added backwards compatability

Location:
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs

    r15938 r15939  
    7474      : base(deserializing) {
    7575    }
     76
     77    [StorableHook(HookType.AfterDeserialization)]
     78    private void AfterDeserialization() {
     79      if (Parameters.TryGetValue("Slope", out IParameter slopeParameter)) {
     80        Parameters.Add(new FixedValueParameter<DoubleValue>("Scale", "Multiplicative factor (Slope)", ((IValueParameter<DoubleValue>)slopeParameter).Value));
     81        Parameters.Remove("Slope");
     82      }
     83      if (Parameters.TryGetValue("Intercept", out IParameter interceptParameter)) {
     84        Parameters.Add(new FixedValueParameter<DoubleValue>("Offset", "Additive factor (Intercept)", ((IValueParameter<DoubleValue>)interceptParameter).Value));
     85        Parameters.Remove("Intercept");
     86      }
     87    }
    7688    #endregion
     89
    7790
    7891    public override IEnumerable<double> Apply(IEnumerable<double> data) {
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LogarithmTransformation.cs

    r15938 r15939  
    7171      : base(deserializing) {
    7272    }
     73    [StorableHook(HookType.AfterDeserialization)]
     74    private void AfterDeserialization() {
     75      if (!Parameters.ContainsKey("Offset"))
     76        Parameters.Add(new FixedValueParameter<DoubleValue>("Offset", "Offset before the logarithm", new DoubleValue(0.0)));
     77    }
    7378    #endregion
     79
    7480
    7581    public override bool Check(IEnumerable<double> data, out string errorMessage) {
     
    95101
    96102    public static IEnumerable<double> InverseApply(IEnumerable<double> data, double @base = Math.E, double offset = 0.0) {
    97       return ExponentialTransformation.InverseApply(data, @base).Select(x => x - offset);
     103      return ExponentialTransformation.Apply(data, @base).Select(x => x - offset);
    98104    }
    99105  }
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/RescaleTransformation.cs

    r15938 r15939  
    121121      if (double.IsNaN(originalMax)) originalMax = data.Max();
    122122
    123       GetLinearTransformationParameters(targetMin, targetMax, originalMin, originalMax, out double scale, out double offset);
     123      var originalRange = originalMax - originalMin;
     124      var targetRange = targetMax - targetMin;
    124125
    125       return LinearTransformation.Apply(data, scale, offset);
     126      return data
     127        .Select(x => (x - originalMin) / originalRange) // scale to [0-1]
     128        .Select(x => x * targetRange + targetMin);
    126129    }
    127130
    128131    public static IEnumerable<double> InverseApply(IEnumerable<double> data, double targetMin, double targetMax, double originalMin, double originalMax) {
    129       GetLinearTransformationParameters(targetMin, targetMax, originalMin, originalMax, out double scale, out double offset);
    130 
    131       return LinearTransformation.InverseApply(data, scale, offset);
    132     }
    133 
    134     private static void GetLinearTransformationParameters(double targetMin, double targetMax, double originalMin, double originalMax,
    135         out double scale, out double offset) {
    136       var originalRange = originalMax - originalMin;
    137       var targetRange = targetMax - targetMin;
    138 
    139       scale = targetRange / originalRange;
    140       offset = targetMin - originalMin * scale;
     132      return Apply(data, originalMin, originalMax, targetMin, targetMax);
    141133    }
    142134  }
Note: See TracChangeset for help on using the changeset viewer.