Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LogarithmicTransformation.cs @ 16640

Last change on this file since 16640 was 16640, checked in by gkronber, 5 years ago

#2971: merged r16565:16631 from trunk/HeuristicLab.Problems.DataAnalysis to branch/HeuristicLab.Problems.DataAnalysis (resolving all conflicts)

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Parameters;
8using HEAL.Attic;
9using HEAL.Attic;
10
11namespace HeuristicLab.Problems.DataAnalysis {
12  [StorableType("D3330C77-060A-4F75-A0C5-47AC81C5F2DF")]
13  [Item("Logarithmic Transformation", "f(x) = log(x, b) | Represents a logarithmic transformation.")]
14  public class LogarithmicTransformation : Transformation<double> {
15    protected const string BaseParameterName = "Base";
16
17    #region Parameters
18    public IValueParameter<DoubleValue> BaseParameter {
19      get { return (IValueParameter<DoubleValue>)Parameters[BaseParameterName]; }
20    }
21    #endregion
22
23    #region properties
24    public override string ShortName {
25      get { return "Log"; }
26    }
27    public double Base {
28      get { return BaseParameter.Value.Value; }
29    }
30    #endregion
31
32    [StorableConstructor]
33    protected LogarithmicTransformation(StorableConstructorFlag _) : base(_) { }
34    protected LogarithmicTransformation(LogarithmicTransformation original, Cloner cloner)
35      : base(original, cloner) {
36    }
37    public LogarithmicTransformation(IEnumerable<string> allowedColumns)
38      : base(allowedColumns) {
39      Parameters.Add(new ValueParameter<DoubleValue>(BaseParameterName, "b | Base of log-function", new DoubleValue(Math.E)));
40    }
41
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new LogarithmicTransformation(this, cloner);
44    }
45
46    public override IEnumerable<double> Apply(IEnumerable<double> data) {
47      var b = Base;
48      return data.Select(d => d > 0.0 ? Math.Log(d, b) : d);
49    }
50
51    public override bool Check(IEnumerable<double> data, out string errorMsg) {
52      errorMsg = null;
53      int errorCounter = data.Count(i => i <= 0.0);
54      if (errorCounter > 0) {
55        errorMsg = String.Format("{0} values are zero or below zero. Logarithm can not be applied onto these values", errorCounter);
56        return false;
57      }
58      return true;
59    }
60
61  }
62}
Note: See TracBrowser for help on using the repository browser.