Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/PowerTransformation.cs @ 17709

Last change on this file since 17709 was 17097, checked in by mkommend, 5 years ago

#2520: Merged 16565 - 16579 into stable.

File size: 1.8 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;
9
10namespace HeuristicLab.Problems.DataAnalysis {
11  [StorableType("D5A6860A-AEE5-47BE-A4D2-0107AB0A90E3")]
12  [Item("Power Transformation", "f(x) = x ^ exp | Represents a power transformation.")]
13  public class PowerTransformation : Transformation<double> {
14    protected const string ExponentParameterName = "Exponent";
15
16    #region Parameters
17    public IValueParameter<DoubleValue> ExponentParameter {
18      get { return (IValueParameter<DoubleValue>)Parameters[ExponentParameterName]; }
19    }
20    #endregion
21
22    #region properties
23    public override string ShortName {
24      get { return "Pow"; }
25    }
26    public double Exponent {
27      get { return ExponentParameter.Value.Value; }
28    }
29    #endregion
30
31    [StorableConstructor]
32    protected PowerTransformation(StorableConstructorFlag _) : base(_) { }
33    protected PowerTransformation(PowerTransformation original, Cloner cloner)
34      : base(original, cloner) {
35    }
36    public PowerTransformation(IEnumerable<string> allowedColumns)
37      : base(allowedColumns) {
38      Parameters.Add(new ValueParameter<DoubleValue>(ExponentParameterName, "exp | Exponent for Exponentation", new DoubleValue(2.0)));
39    }
40
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new PowerTransformation(this, cloner);
43    }
44
45    public override IEnumerable<double> Apply(IEnumerable<double> data) {
46      return data.Select(i => Math.Pow(i, Exponent));
47    }
48
49    public override bool Check(IEnumerable<double> data, out string errorMsg) {
50      errorMsg = "";
51      return true;
52    }
53
54  }
55}
Note: See TracBrowser for help on using the repository browser.