Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10815


Ignore:
Timestamp:
05/07/14 14:23:28 (11 years ago)
Author:
tsteinre
Message:
  • implemented StandardDeviationTransformation logic.
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  
    4848  <ItemGroup>
    4949    <Compile Include="CopyColumnTransformation.cs" />
    50     <Compile Include="DeviationTransformation.cs" />
     50    <Compile Include="StandardDeviationTransformation.cs" />
    5151    <Compile Include="PowerTransformation.cs" />
    5252    <Compile Include="ExponentialTransformation.cs" />
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Transformations/3.3/StandardDeviationTransformation.cs

    r10814 r10815  
    1 using System;
    2 using System.Collections.Generic;
     1using System.Collections.Generic;
    32using System.Linq;
    43using HeuristicLab.Common;
     
    98
    109namespace 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";
    1314    protected const string MeanParameterName = "Mean";
    14     protected const string VarianceParameterName = "Variance";
     15    protected const string StandardDeviationParameterName = "StandardDeviation";
    1516
    1617    #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    }
    1724    public IValueParameter<DoubleValue> MeanParameter {
    1825      get { return (IValueParameter<DoubleValue>)Parameters[MeanParameterName]; }
    1926    }
    20     public IValueParameter<DoubleValue> VarianceParameter {
    21       get { return (IValueParameter<DoubleValue>)Parameters[VarianceParameterName]; }
     27    public IValueParameter<DoubleValue> StandardDeviationParameter {
     28      get { return (IValueParameter<DoubleValue>)Parameters[StandardDeviationParameterName]; }
    2229    }
    2330    #endregion
    2431
    2532    #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    }
    2641    public double Mean {
    2742      get { return MeanParameter.Value.Value; }
    2843    }
    29     public double Variance {
    30       get { return VarianceParameter.Value.Value; }
     44    public double StandardDeviation {
     45      get { return StandardDeviationParameter.Value.Value; }
    3146    }
    3247    #endregion
    3348
    3449    [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)
    3752      : base(original, cloner) {
    3853    }
    39     public DeviationTransformation(IEnumerable<string> allowedColumns)
     54    public StandardDeviationTransformation(IEnumerable<string> allowedColumns)
    4055      : 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)));
    4562    }
    4663
    4764    public override IDeepCloneable Clone(Cloner cloner) {
    48       return new DeviationTransformation(this, cloner);
     65      return new StandardDeviationTransformation(this, cloner);
    4966    }
    5067
     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
    5171    public override IEnumerable<double> Apply(IEnumerable<double> data) {
    5272      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      }
    5484    }
    5585
    5686    public override bool Check(IEnumerable<double> data, out string errorMsg) {
    5787      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      }
    5995    }
    6096
    6197    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();
    69100    }
    70 
    71101  }
    72102}
Note: See TracChangeset for help on using the changeset viewer.