Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftToRangeTransformation.cs @ 15956

Last change on this file since 15956 was 11114, checked in by mkommend, 10 years ago

#2206: Merged data preprocessing into the trunk.

File size: 2.4 KB
Line 
1using System.Collections.Generic;
2using System.Linq;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Parameters;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.Problems.DataAnalysis {
10  [Item("Shift to Range Transformation", "f(x) = k * x + d, start <= f(x) <= end | Represents a linear Transformation using Parameters defining a target range")]
11  public class ShiftToRangeTransformation : 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 override string ShortName {
22      get { return "Sft"; }
23    }
24    public DoubleRange Range {
25      get { return RangeParameter.Value; }
26    }
27    #endregion
28
29    [StorableConstructor]
30    protected ShiftToRangeTransformation(bool deserializing) : base(deserializing) { }
31    protected ShiftToRangeTransformation(ShiftToRangeTransformation original, Cloner cloner)
32      : base(original, cloner) {
33    }
34    public ShiftToRangeTransformation(IEnumerable<string> allowedColumns)
35      : base(allowedColumns) {
36      MultiplierParameter.Hidden = true;
37      AddendParameter.Hidden = true;
38      Parameters.Add(new ValueParameter<DoubleRange>(RangeParameterName, "start, end | Range for the target window of the linear transformation", new DoubleRange(0.0, 1.0)));
39    }
40
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new ShiftToRangeTransformation(this, cloner);
43    }
44
45    public override IEnumerable<double> Apply(IEnumerable<double> data) {
46      ConfigureParameters(data);
47      return base.Apply(data);
48    }
49
50    public override bool Check(IEnumerable<double> data, out string errorMsg) {
51      ConfigureParameters(data);
52      return base.Check(data, out errorMsg);
53    }
54
55    protected void ConfigureParameters(IEnumerable<double> data) {
56      double originalRangeStart = data.Min();
57      double originalRangeEnd = data.Max();
58
59      double originalRangeWidth = originalRangeEnd - originalRangeStart;
60      double targetRangeWidth = Range.End - Range.Start;
61
62      Multiplier = targetRangeWidth / originalRangeWidth;
63      Addend = Range.Start - originalRangeStart * Multiplier;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.