Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/17/18 10:03:01 (6 years ago)
Author:
pfleck
Message:

#2906

  • added Offset to log transformation
  • renamed parameter of linear transformation
  • added RescaleTransformation
File:
1 edited

Legend:

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

    r15884 r15938  
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis {
    32   [Item("Linear", "Linear transformation x' = slope * x + intercept")]
     32  [Item("Linear", "Linear transformation x' = Scale * x + Offset")]
    3333  [StorableClass]
    3434  public class LinearTransformation : Transformation<double> {
    3535
    3636    #region Parameters
    37     private FixedValueParameter<DoubleValue> SlopeParameter {
    38       get { return (FixedValueParameter<DoubleValue>)Parameters["Slope"]; }
     37    private FixedValueParameter<DoubleValue> ScaleParameter {
     38      get { return (FixedValueParameter<DoubleValue>)Parameters["Scale"]; }
    3939    }
    4040
    41     private FixedValueParameter<DoubleValue> InterceptParameter {
    42       get { return (FixedValueParameter<DoubleValue>)Parameters["Intercept"]; }
     41    private FixedValueParameter<DoubleValue> OffsetParameter {
     42      get { return (FixedValueParameter<DoubleValue>)Parameters["Offset"]; }
    4343    }
    4444    #endregion
    4545
    4646    #region Properties
    47     public double Slope {
    48       get { return SlopeParameter.Value.Value; }
    49       set { SlopeParameter.Value.Value = value; }
     47    public double Scale {
     48      get { return ScaleParameter.Value.Value; }
     49      set { ScaleParameter.Value.Value = value; }
    5050    }
    5151
    52     public double Intercept {
    53       get { return InterceptParameter.Value.Value; }
    54       set { InterceptParameter.Value.Value = value; }
     52    public double Offset {
     53      get { return OffsetParameter.Value.Value; }
     54      set { OffsetParameter.Value.Value = value; }
    5555    }
    5656    #endregion
     
    5959    public LinearTransformation()
    6060      : base() {
    61       Parameters.Add(new FixedValueParameter<DoubleValue>("Slope", "Slope (multiplicative factor)", new DoubleValue(1.0)));
    62       Parameters.Add(new FixedValueParameter<DoubleValue>("Intercept", "Intercept (additive factor)", new DoubleValue(0.0)));
     61      Parameters.Add(new FixedValueParameter<DoubleValue>("Scale", "Multiplicative factor (Slope)", new DoubleValue(1.0)));
     62      Parameters.Add(new FixedValueParameter<DoubleValue>("Offset", "Additive factor (Intercept)", new DoubleValue(0.0)));
    6363    }
    6464
     
    7777
    7878    public override IEnumerable<double> Apply(IEnumerable<double> data) {
    79       return Apply(data, Slope, Intercept);
     79      return Apply(data, Scale, Offset);
    8080    }
    8181
    8282    public override IEnumerable<double> InverseApply(IEnumerable<double> data) {
    83       return InverseApply(data, Slope, Intercept);
     83      return InverseApply(data, Scale, Offset);
    8484    }
    8585
    8686
    87     public static IEnumerable<double> Apply(IEnumerable<double> data, double slope = 1.0, double intercept = 0.0) {
    88       if (slope.IsAlmost(0.0))
    89         throw new InvalidOperationException($"Cannot transform with a {nameof(slope)} of zero because inverse transformation would be invalid.");
     87    public static IEnumerable<double> Apply(IEnumerable<double> data, double scale = 1.0, double offset = 0.0) {
     88      if (scale.IsAlmost(0.0))
     89        throw new InvalidOperationException($"Cannot transform with a {nameof(scale)} of zero because inverse transformation would be invalid.");
    9090
    91       return data.Select(x => slope * x + intercept);
     91      return data.Select(x => scale * x + offset);
    9292    }
    9393
    94     public static IEnumerable<double> InverseApply(IEnumerable<double> data, double slope = 1.0, double intercept = 0.0) {
    95       if (slope.IsAlmost(0.0))
    96         throw new InvalidOperationException($"Cannot inverse transform with a {nameof(slope)} of zero.");
     94    public static IEnumerable<double> InverseApply(IEnumerable<double> data, double scale = 1.0, double offset = 0.0) {
     95      if (scale.IsAlmost(0.0))
     96        throw new InvalidOperationException($"Cannot inverse transform with a {nameof(scale)} of zero.");
    9797
    98       return data.Select(x => (x - intercept) / slope);
     98      return data.Select(x => (x - offset) / scale);
    9999    }
    100100  }
Note: See TracChangeset for help on using the changeset viewer.