- Timestamp:
- 05/07/14 14:23:28 (11 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Transformations/3.3
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Transformations/3.3/HeuristicLab.Problems.DataAnalysis.Transformations-3.3.csproj
r10805 r10815 48 48 <ItemGroup> 49 49 <Compile Include="CopyColumnTransformation.cs" /> 50 <Compile Include=" DeviationTransformation.cs" />50 <Compile Include="StandardDeviationTransformation.cs" /> 51 51 <Compile Include="PowerTransformation.cs" /> 52 52 <Compile Include="ExponentialTransformation.cs" /> -
branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Transformations/3.3/StandardDeviationTransformation.cs
r10814 r10815 1 using System; 2 using System.Collections.Generic; 1 using System.Collections.Generic; 3 2 using System.Linq; 4 3 using HeuristicLab.Common; … … 9 8 10 9 namespace HeuristicLab.Problems.DataAnalysis.Transformations { 11 [Item("DeviationTransformation", "Represents a linear Transformation using deviation Parameters")] 12 public class DeviationTransformation : LinearTransformation { 10 [Item("StandardDeviationTransformation", "f(x) = ((x - m_org) / s_org ) * s_tar + m_tar | Represents Transformation to unit standard deviation and additional linear transformation to a target Mean and Standard deviation")] 11 public class StandardDeviationTransformation : Transformation<double> { 12 protected const string OriginalMeanParameterName = "OriginalMean"; 13 protected const string OriginalStandardDeviationParameterName = "OriginalStandardDeviation"; 13 14 protected const string MeanParameterName = "Mean"; 14 protected const string VarianceParameterName = "Variance";15 protected const string StandardDeviationParameterName = "StandardDeviation"; 15 16 16 17 #region Parameters 18 public IValueParameter<DoubleValue> OriginalMeanParameter { 19 get { return (IValueParameter<DoubleValue>)Parameters[OriginalMeanParameterName]; } 20 } 21 public IValueParameter<DoubleValue> OriginalStandardDeviationParameter { 22 get { return (IValueParameter<DoubleValue>)Parameters[OriginalStandardDeviationParameterName]; } 23 } 17 24 public IValueParameter<DoubleValue> MeanParameter { 18 25 get { return (IValueParameter<DoubleValue>)Parameters[MeanParameterName]; } 19 26 } 20 public IValueParameter<DoubleValue> VarianceParameter {21 get { return (IValueParameter<DoubleValue>)Parameters[ VarianceParameterName]; }27 public IValueParameter<DoubleValue> StandardDeviationParameter { 28 get { return (IValueParameter<DoubleValue>)Parameters[StandardDeviationParameterName]; } 22 29 } 23 30 #endregion 24 31 25 32 #region properties 33 public double OriginalMean { 34 get { return OriginalMeanParameter.Value.Value; } 35 set { OriginalMeanParameter.Value.Value = value; } 36 } 37 public double OriginalStandardDeviation { 38 get { return OriginalStandardDeviationParameter.Value.Value; } 39 set { OriginalStandardDeviationParameter.Value.Value = value; } 40 } 26 41 public double Mean { 27 42 get { return MeanParameter.Value.Value; } 28 43 } 29 public double Variance{30 get { return VarianceParameter.Value.Value; }44 public double StandardDeviation { 45 get { return StandardDeviationParameter.Value.Value; } 31 46 } 32 47 #endregion 33 48 34 49 [StorableConstructor] 35 protected DeviationTransformation(bool deserializing) : base(deserializing) { }36 protected DeviationTransformation(Transformation<double> original, Cloner cloner)50 protected StandardDeviationTransformation(bool deserializing) : base(deserializing) { } 51 protected StandardDeviationTransformation(Transformation<double> original, Cloner cloner) 37 52 : base(original, cloner) { 38 53 } 39 public DeviationTransformation(IEnumerable<string> allowedColumns)54 public StandardDeviationTransformation(IEnumerable<string> allowedColumns) 40 55 : base(allowedColumns) { 41 MultiplierParameter.Hidden = true; 42 AddendParameter.Hidden = true; 43 Parameters.Add(new ValueParameter<DoubleValue>(MeanParameterName, "Mean value for the target deviation.", new DoubleValue(0.0))); 44 Parameters.Add(new ValueParameter<DoubleValue>(VarianceParameterName, "Variance for the target deviation.", new DoubleValue(1.0))); 56 Parameters.Add(new ValueParameter<DoubleValue>(OriginalMeanParameterName, "m_org | Mean value of the original data's deviation.", new DoubleValue())); 57 Parameters.Add(new ValueParameter<DoubleValue>(OriginalStandardDeviationParameterName, "s_org | Standard deviation of the original data.", new DoubleValue())); 58 OriginalMeanParameter.Hidden = true; 59 OriginalStandardDeviationParameter.Hidden = true; 60 Parameters.Add(new ValueParameter<DoubleValue>(MeanParameterName, "m_tar | Mean value for the target deviation.", new DoubleValue(0.0))); 61 Parameters.Add(new ValueParameter<DoubleValue>(StandardDeviationParameterName, "s_tar | Standard deviation for the target data.", new DoubleValue(1.0))); 45 62 } 46 63 47 64 public override IDeepCloneable Clone(Cloner cloner) { 48 return new DeviationTransformation(this, cloner);65 return new StandardDeviationTransformation(this, cloner); 49 66 } 50 67 68 // http://en.wikipedia.org/wiki/Standard_deviation 69 // http://www.statistics4u.info/fundstat_germ/ee_ztransform.html 70 // https://www.uni-due.de/~bm0061/vorl12.pdf p5 51 71 public override IEnumerable<double> Apply(IEnumerable<double> data) { 52 72 ConfigureParameters(data); 53 return base.Apply(data); 73 if (OriginalStandardDeviation == 0.0) { 74 foreach (var e in data) { 75 yield return e; 76 } 77 yield break; 78 } 79 80 foreach (var e in data) { 81 double unitNormalDistributedValue = (e - OriginalMean) / OriginalStandardDeviation; 82 yield return unitNormalDistributedValue * StandardDeviation + Mean; 83 } 54 84 } 55 85 56 86 public override bool Check(IEnumerable<double> data, out string errorMsg) { 57 87 ConfigureParameters(data); 58 return base.Check(data, out errorMsg); 88 errorMsg = ""; 89 if (OriginalStandardDeviation == 0.0) { 90 errorMsg = "Standard deviaton for the original data is 0.0"; 91 return false; 92 } else { 93 return true; 94 } 59 95 } 60 96 61 97 protected void ConfigureParameters(IEnumerable<double> data) { 62 double standardDeviation = data.StandardDeviation(); 63 double middle = data.Average(); 64 // TODO: 65 // http://en.wikipedia.org/wiki/Standard_deviation 66 // http://www.statistics4u.info/fundstat_germ/ee_ztransform.html 67 // https://www.uni-due.de/~bm0061/vorl12.pdf p5 68 throw new NotImplementedException(); 98 OriginalStandardDeviation = data.StandardDeviation(); 99 OriginalMean = data.Average(); 69 100 } 70 71 101 } 72 102 }
Note: See TracChangeset
for help on using the changeset viewer.