Free cookie consent management tool by TermsFeed Policy Generator

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

#2906

  • added Offset to log transformation
  • renamed parameter of linear transformation
  • added RescaleTransformation
Location:
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r15870 r15938  
    231231    <Compile Include="Implementation\Transformations\LinearTransformation.cs" />
    232232    <Compile Include="Implementation\Transformations\LogarithmTransformation.cs" />
     233    <Compile Include="Implementation\Transformations\RescaleTransformation.cs" />
    233234    <Compile Include="Implementation\Transformations\Transformation.cs" />
    234235    <Compile Include="Implementation\Transformations\ZNormalizationTransformation.cs" />
  • 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  }
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LogarithmTransformation.cs

    r15865 r15938  
    3737      get { return (FixedValueParameter<DoubleValue>)Parameters["Base"]; }
    3838    }
     39    private FixedValueParameter<DoubleValue> OffsetParameter {
     40      get { return (FixedValueParameter<DoubleValue>)Parameters["Offset"]; }
     41    }
    3942    #endregion
    4043
     
    4447      set { BaseParameter.Value.Value = value; }
    4548    }
     49    public double Offset {
     50      get { return OffsetParameter.Value.Value; }
     51      set { OffsetParameter.Value.Value = value; }
     52    }
    4653    #endregion
    4754
     
    5057      : base() {
    5158      Parameters.Add(new FixedValueParameter<DoubleValue>("Base", "Base the logarithm", new DoubleValue(Math.E)));
     59      Parameters.Add(new FixedValueParameter<DoubleValue>("Offset", "Offset before the logarithm", new DoubleValue(0.0)));
    5260    }
    5361
     
    6674
    6775    public override bool Check(IEnumerable<double> data, out string errorMessage) {
    68       if (data.Any(x => x <= 0)) {
     76      if (data.Any(x => x + Offset <= 0)) {
    6977        errorMessage = "Log is not available for zero or negative values";
    7078        return false;
     
    7482
    7583    public override IEnumerable<double> Apply(IEnumerable<double> data) {
    76       return Apply(data, Base);
     84      return Apply(data, Base, Offset);
    7785    }
    7886
    7987    public override IEnumerable<double> InverseApply(IEnumerable<double> data) {
    80       return InverseApply(data, Base);
     88      return InverseApply(data, Base, Offset);
    8189    }
    8290
    8391
    84     public static IEnumerable<double> Apply(IEnumerable<double> data, double @base = Math.E) {
    85       return data.Select(x => Math.Log(x, @base));
     92    public static IEnumerable<double> Apply(IEnumerable<double> data, double @base = Math.E, double offset = 0.0) {
     93      return data.Select(x => Math.Log(x + offset, @base));
    8694    }
    8795
    88     public static IEnumerable<double> InverseApply(IEnumerable<double> data, double @base = Math.E) {
    89       return ExponentialTransformation.Apply(data, @base);
     96    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);
    9098    }
    9199  }
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisTransformationModel.cs

    r15884 r15938  
    2626    IDataAnalysisModel OriginalModel { get; }
    2727
    28     /// <summary>
    29     /// Transformations that are used on the model's inputs.
    30     /// </summary>
    3128    IEnumerable<IDataAnalysisTransformation> InputTransformations { get; }
    3229  }
Note: See TracChangeset for help on using the changeset viewer.