Changeset 15938 for branches/2906_Transformations
- Timestamp:
- 05/17/18 10:03:01 (7 years ago)
- 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 231 231 <Compile Include="Implementation\Transformations\LinearTransformation.cs" /> 232 232 <Compile Include="Implementation\Transformations\LogarithmTransformation.cs" /> 233 <Compile Include="Implementation\Transformations\RescaleTransformation.cs" /> 233 234 <Compile Include="Implementation\Transformations\Transformation.cs" /> 234 235 <Compile Include="Implementation\Transformations\ZNormalizationTransformation.cs" /> -
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 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LogarithmTransformation.cs
r15865 r15938 37 37 get { return (FixedValueParameter<DoubleValue>)Parameters["Base"]; } 38 38 } 39 private FixedValueParameter<DoubleValue> OffsetParameter { 40 get { return (FixedValueParameter<DoubleValue>)Parameters["Offset"]; } 41 } 39 42 #endregion 40 43 … … 44 47 set { BaseParameter.Value.Value = value; } 45 48 } 49 public double Offset { 50 get { return OffsetParameter.Value.Value; } 51 set { OffsetParameter.Value.Value = value; } 52 } 46 53 #endregion 47 54 … … 50 57 : base() { 51 58 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))); 52 60 } 53 61 … … 66 74 67 75 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)) { 69 77 errorMessage = "Log is not available for zero or negative values"; 70 78 return false; … … 74 82 75 83 public override IEnumerable<double> Apply(IEnumerable<double> data) { 76 return Apply(data, Base );84 return Apply(data, Base, Offset); 77 85 } 78 86 79 87 public override IEnumerable<double> InverseApply(IEnumerable<double> data) { 80 return InverseApply(data, Base );88 return InverseApply(data, Base, Offset); 81 89 } 82 90 83 91 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)); 86 94 } 87 95 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); 90 98 } 91 99 } -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisTransformationModel.cs
r15884 r15938 26 26 IDataAnalysisModel OriginalModel { get; } 27 27 28 /// <summary>29 /// Transformations that are used on the model's inputs.30 /// </summary>31 28 IEnumerable<IDataAnalysisTransformation> InputTransformations { get; } 32 29 }
Note: See TracChangeset
for help on using the changeset viewer.