Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Transformations/3.3/ShiftDataToRangeTransformation.cs @ 10777

Last change on this file since 10777 was 10777, checked in by tsteinre, 10 years ago

LinearTransformation: Renamed Multiplier and Addend

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.Transformations {
10  [Item("ShiftDataToRangeTransformation", "Represents a linear Transformation using Parameters defining a target range")]
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    protected ShiftDataToRangeTransformation()
32      : base() {
33    }
34    public ShiftDataToRangeTransformation(IEnumerable<string> allowedColumns)
35      : base(allowedColumns) {
36      MultiplierParameter.Hidden = true;
37      AddendParameter.Hidden = true;
38      Parameters.Add(new ValueParameter<DoubleRange>(RangeParameterName, "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 ShiftDataToRangeTransformation(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.