[10775]  1  using System.Collections.Generic;


 2  using System.Linq;


 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 {


[10808]  10  [Item("ShiftDataToRangeTransformation", "f(x) = k * x + d, start <= f(x) <= end  Represents a linear Transformation using Parameters defining a target range")]


[10775]  11  public class ShiftDataToRangeTransformation : LinearTransformation {


 12  protected const string RangeParameterName = "Range";


 13 


 14  #region Parameters


 15  public IValueParameter<DoubleRange> RangeParameter {


 16  get { return (IValueParameter<DoubleRange>)Parameters[RangeParameterName]; }


 17  }


 18  #endregion


 19 


 20  #region properties


 21  public DoubleRange Range {


 22  get { return RangeParameter.Value; }


 23  }


 24  #endregion


 25 


 26  [StorableConstructor]


 27  protected ShiftDataToRangeTransformation(bool deserializing) : base(deserializing) { }


 28  protected ShiftDataToRangeTransformation(Transformation<double> original, Cloner cloner)


 29  : base(original, cloner) {


 30  }


 31  public ShiftDataToRangeTransformation(IEnumerable<string> allowedColumns)


 32  : base(allowedColumns) {


[10777]  33  MultiplierParameter.Hidden = true;


 34  AddendParameter.Hidden = true;


[10808]  35  Parameters.Add(new ValueParameter<DoubleRange>(RangeParameterName, "start, end  Range for the target window of the linear transformation", new DoubleRange(0.0, 1.0)));


[10775]  36  }


 37 


 38  public override IDeepCloneable Clone(Cloner cloner) {


 39  return new ShiftDataToRangeTransformation(this, cloner);


 40  }


 41 


 42  public override IEnumerable<double> Apply(IEnumerable<double> data) {


 43  ConfigureParameters(data);


 44  return base.Apply(data);


 45  }


 46 


 47  public override bool Check(IEnumerable<double> data, out string errorMsg) {


 48  ConfigureParameters(data);


 49  return base.Check(data, out errorMsg);


 50  }


 51 


 52  protected void ConfigureParameters(IEnumerable<double> data) {


 53  double originalRangeStart = data.Min();


 54  double originalRangeEnd = data.Max();


 55 


 56  double originalRangeWidth = originalRangeEnd  originalRangeStart;


 57  double targetRangeWidth = Range.End  Range.Start;


 58 


[10777]  59  Multiplier = targetRangeWidth / originalRangeWidth;


 60  Addend = Range.Start  originalRangeStart * Multiplier;


[10775]  61  }


 62  }


 63  }

