1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Problems.DataAnalysis.Transformations {
|
---|
10 | [Item("Power Transformation", "f(x) = x ^ exp | Represents a power transformation.")]
|
---|
11 | public class PowerTransformation : Transformation<double> {
|
---|
12 | protected const string ExponentParameterName = "Exponent";
|
---|
13 |
|
---|
14 | #region Parameters
|
---|
15 | public IValueParameter<DoubleValue> ExponentParameter {
|
---|
16 | get { return (IValueParameter<DoubleValue>)Parameters[ExponentParameterName]; }
|
---|
17 | }
|
---|
18 | #endregion
|
---|
19 |
|
---|
20 | #region properties
|
---|
21 | public double Exponent {
|
---|
22 | get { return ExponentParameter.Value.Value; }
|
---|
23 | }
|
---|
24 | #endregion
|
---|
25 |
|
---|
26 | [StorableConstructor]
|
---|
27 | protected PowerTransformation(bool deserializing) : base(deserializing) { }
|
---|
28 | protected PowerTransformation(Transformation<double> original, Cloner cloner)
|
---|
29 | : base(original, cloner) {
|
---|
30 | }
|
---|
31 | public PowerTransformation(IEnumerable<string> allowedColumns)
|
---|
32 | : base(allowedColumns) {
|
---|
33 | Parameters.Add(new ValueParameter<DoubleValue>(ExponentParameterName, "exp | Exponent for Exponentation", new DoubleValue(2.0)));
|
---|
34 | }
|
---|
35 |
|
---|
36 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
37 | return new PowerTransformation(this, cloner);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public override IEnumerable<double> Apply(IEnumerable<double> data) {
|
---|
41 | foreach (double i in data) {
|
---|
42 | yield return Math.Pow(i, Exponent);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public override bool Check(IEnumerable<double> data, out string errorMsg) {
|
---|
47 | errorMsg = "";
|
---|
48 | return true;
|
---|
49 | }
|
---|
50 |
|
---|
51 | }
|
---|
52 | }
|
---|