Changeset 15938 for branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs
- Timestamp:
- 05/17/18 10:03:01 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs
r15884 r15938 30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis { 32 [Item("Linear", "Linear transformation x' = slope * x + intercept")]32 [Item("Linear", "Linear transformation x' = Scale * x + Offset")] 33 33 [StorableClass] 34 34 public class LinearTransformation : Transformation<double> { 35 35 36 36 #region Parameters 37 private FixedValueParameter<DoubleValue> S lopeParameter {38 get { return (FixedValueParameter<DoubleValue>)Parameters["S lope"]; }37 private FixedValueParameter<DoubleValue> ScaleParameter { 38 get { return (FixedValueParameter<DoubleValue>)Parameters["Scale"]; } 39 39 } 40 40 41 private FixedValueParameter<DoubleValue> InterceptParameter {42 get { return (FixedValueParameter<DoubleValue>)Parameters[" Intercept"]; }41 private FixedValueParameter<DoubleValue> OffsetParameter { 42 get { return (FixedValueParameter<DoubleValue>)Parameters["Offset"]; } 43 43 } 44 44 #endregion 45 45 46 46 #region Properties 47 public double S lope {48 get { return S lopeParameter.Value.Value; }49 set { S lopeParameter.Value.Value = value; }47 public double Scale { 48 get { return ScaleParameter.Value.Value; } 49 set { ScaleParameter.Value.Value = value; } 50 50 } 51 51 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; } 55 55 } 56 56 #endregion … … 59 59 public LinearTransformation() 60 60 : base() { 61 Parameters.Add(new FixedValueParameter<DoubleValue>("S lope", "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))); 63 63 } 64 64 … … 77 77 78 78 public override IEnumerable<double> Apply(IEnumerable<double> data) { 79 return Apply(data, S lope, Intercept);79 return Apply(data, Scale, Offset); 80 80 } 81 81 82 82 public override IEnumerable<double> InverseApply(IEnumerable<double> data) { 83 return InverseApply(data, S lope, Intercept);83 return InverseApply(data, Scale, Offset); 84 84 } 85 85 86 86 87 public static IEnumerable<double> Apply(IEnumerable<double> data, double s lope = 1.0, double intercept = 0.0) {88 if (s lope.IsAlmost(0.0))89 throw new InvalidOperationException($"Cannot transform with a {nameof(s lope)} 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."); 90 90 91 return data.Select(x => s lope * x + intercept);91 return data.Select(x => scale * x + offset); 92 92 } 93 93 94 public static IEnumerable<double> InverseApply(IEnumerable<double> data, double s lope = 1.0, double intercept = 0.0) {95 if (s lope.IsAlmost(0.0))96 throw new InvalidOperationException($"Cannot inverse transform with a {nameof(s lope)} 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."); 97 97 98 return data.Select(x => (x - intercept) / slope);98 return data.Select(x => (x - offset) / scale); 99 99 } 100 100 }
Note: See TracChangeset
for help on using the changeset viewer.