using System; using System.Collections.Generic; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.DataAnalysis.Transformations { [Item("PowerTransformation", "f(x) = x ^ exp | Represents a power transformation.")] public class PowerTransformation : Transformation { protected const string ExponentParameterName = "Exponent"; #region Parameters public IValueParameter ExponentParameter { get { return (IValueParameter)Parameters[ExponentParameterName]; } } #endregion #region properties public double Exponent { get { return ExponentParameter.Value.Value; } } #endregion [StorableConstructor] protected PowerTransformation(bool deserializing) : base(deserializing) { } protected PowerTransformation(Transformation original, Cloner cloner) : base(original, cloner) { } public PowerTransformation(IEnumerable allowedColumns) : base(allowedColumns) { Parameters.Add(new ValueParameter(ExponentParameterName, "exp | Exponent for Exponentation", new DoubleValue(Math.E))); } public override IDeepCloneable Clone(Cloner cloner) { return new PowerTransformation(this, cloner); } public override IEnumerable Apply(IEnumerable data) { foreach (double i in data) { yield return Math.Pow(i, Exponent); } } public override bool Check(IEnumerable data, out string errorMsg) { errorMsg = ""; return true; } } }