[10782] | 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 {
|
---|
[10909] | 10 | [Item("Power Transformation", "f(x) = x ^ exp | Represents a power transformation.")]
|
---|
[10805] | 11 | public class PowerTransformation : Transformation<double> {
|
---|
| 12 | protected const string ExponentParameterName = "Exponent";
|
---|
[10782] | 13 |
|
---|
| 14 | #region Parameters
|
---|
[10805] | 15 | public IValueParameter<DoubleValue> ExponentParameter {
|
---|
| 16 | get { return (IValueParameter<DoubleValue>)Parameters[ExponentParameterName]; }
|
---|
[10782] | 17 | }
|
---|
| 18 | #endregion
|
---|
| 19 |
|
---|
| 20 | #region properties
|
---|
[10932] | 21 | public override string ShortName {
|
---|
| 22 | get { return "Pow"; }
|
---|
| 23 | }
|
---|
[10805] | 24 | public double Exponent {
|
---|
| 25 | get { return ExponentParameter.Value.Value; }
|
---|
[10782] | 26 | }
|
---|
| 27 | #endregion
|
---|
| 28 |
|
---|
| 29 | [StorableConstructor]
|
---|
[10805] | 30 | protected PowerTransformation(bool deserializing) : base(deserializing) { }
|
---|
| 31 | protected PowerTransformation(Transformation<double> original, Cloner cloner)
|
---|
[10782] | 32 | : base(original, cloner) {
|
---|
| 33 | }
|
---|
[10805] | 34 | public PowerTransformation(IEnumerable<string> allowedColumns)
|
---|
[10782] | 35 | : base(allowedColumns) {
|
---|
[10909] | 36 | Parameters.Add(new ValueParameter<DoubleValue>(ExponentParameterName, "exp | Exponent for Exponentation", new DoubleValue(2.0)));
|
---|
[10782] | 37 | }
|
---|
| 38 |
|
---|
| 39 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[10805] | 40 | return new PowerTransformation(this, cloner);
|
---|
[10782] | 41 | }
|
---|
| 42 |
|
---|
| 43 | public override IEnumerable<double> Apply(IEnumerable<double> data) {
|
---|
| 44 | foreach (double i in data) {
|
---|
[10805] | 45 | yield return Math.Pow(i, Exponent);
|
---|
[10782] | 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public override bool Check(IEnumerable<double> data, out string errorMsg) {
|
---|
| 50 | errorMsg = "";
|
---|
| 51 | return true;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | }
|
---|
| 55 | }
|
---|