[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;
|
---|
[16565] | 7 | using HEAL.Attic;
|
---|
[10775] | 8 |
|
---|
[11068] | 9 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
[16565] | 10 | [StorableType("4A91E704-927C-4278-AA11-79C16BD8E4F2")]
|
---|
[10909] | 11 | [Item("Shift to Range Transformation", "f(x) = k * x + d, start <= f(x) <= end | Represents a linear Transformation using Parameters defining a target range")]
|
---|
[10841] | 12 | public class ShiftToRangeTransformation : LinearTransformation {
|
---|
[10775] | 13 | protected const string RangeParameterName = "Range";
|
---|
| 14 |
|
---|
| 15 | #region Parameters
|
---|
| 16 | public IValueParameter<DoubleRange> RangeParameter {
|
---|
| 17 | get { return (IValueParameter<DoubleRange>)Parameters[RangeParameterName]; }
|
---|
| 18 | }
|
---|
| 19 | #endregion
|
---|
| 20 |
|
---|
| 21 | #region properties
|
---|
[10932] | 22 | public override string ShortName {
|
---|
| 23 | get { return "Sft"; }
|
---|
| 24 | }
|
---|
[10775] | 25 | public DoubleRange Range {
|
---|
| 26 | get { return RangeParameter.Value; }
|
---|
| 27 | }
|
---|
| 28 | #endregion
|
---|
| 29 |
|
---|
| 30 | [StorableConstructor]
|
---|
[16565] | 31 | protected ShiftToRangeTransformation(StorableConstructorFlag _) : base(_) { }
|
---|
[11114] | 32 | protected ShiftToRangeTransformation(ShiftToRangeTransformation original, Cloner cloner)
|
---|
[10775] | 33 | : base(original, cloner) {
|
---|
| 34 | }
|
---|
[10841] | 35 | public ShiftToRangeTransformation(IEnumerable<string> allowedColumns)
|
---|
[10775] | 36 | : base(allowedColumns) {
|
---|
[10777] | 37 | MultiplierParameter.Hidden = true;
|
---|
| 38 | AddendParameter.Hidden = true;
|
---|
[10808] | 39 | Parameters.Add(new ValueParameter<DoubleRange>(RangeParameterName, "start, end | Range for the target window of the linear transformation", new DoubleRange(0.0, 1.0)));
|
---|
[10775] | 40 | }
|
---|
| 41 |
|
---|
| 42 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[10841] | 43 | return new ShiftToRangeTransformation(this, cloner);
|
---|
[10775] | 44 | }
|
---|
| 45 |
|
---|
| 46 | public override bool Check(IEnumerable<double> data, out string errorMsg) {
|
---|
| 47 | ConfigureParameters(data);
|
---|
| 48 | return base.Check(data, out errorMsg);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[14843] | 51 | public override void ConfigureParameters(IEnumerable<double> data) {
|
---|
[10775] | 52 | double originalRangeStart = data.Min();
|
---|
| 53 | double originalRangeEnd = data.Max();
|
---|
| 54 |
|
---|
| 55 | double originalRangeWidth = originalRangeEnd - originalRangeStart;
|
---|
| 56 | double targetRangeWidth = Range.End - Range.Start;
|
---|
| 57 |
|
---|
[10777] | 58 | Multiplier = targetRangeWidth / originalRangeWidth;
|
---|
| 59 | Addend = Range.Start - originalRangeStart * Multiplier;
|
---|
[10775] | 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|