Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftToRangeTransformation.cs @ 16628

Last change on this file since 16628 was 16628, checked in by gkronber, 5 years ago

#2971: made branch compile with current version of trunk

File size: 2.3 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;
8using HEAL.Attic;
9
10namespace HeuristicLab.Problems.DataAnalysis {
11  [StorableType("763232A1-C3B4-4BB3-976A-A4D423511733")]
12  [Item("Shift to Range Transformation", "f(x) = k * x + d, start <= f(x) <= end | Represents a linear Transformation using Parameters defining a target range")]
13  public class ShiftToRangeTransformation : LinearTransformation {
14    protected const string RangeParameterName = "Range";
15
16    #region Parameters
17    public IValueParameter<DoubleRange> RangeParameter {
18      get { return (IValueParameter<DoubleRange>)Parameters[RangeParameterName]; }
19    }
20    #endregion
21
22    #region properties
23    public override string ShortName {
24      get { return "Sft"; }
25    }
26    public DoubleRange Range {
27      get { return RangeParameter.Value; }
28    }
29    #endregion
30
31    [StorableConstructor]
32    protected ShiftToRangeTransformation(StorableConstructorFlag _) : base(_) { }
33    protected ShiftToRangeTransformation(ShiftToRangeTransformation original, Cloner cloner)
34      : base(original, cloner) {
35    }
36    public ShiftToRangeTransformation(IEnumerable<string> allowedColumns)
37      : base(allowedColumns) {
38      MultiplierParameter.Hidden = true;
39      AddendParameter.Hidden = true;
40      Parameters.Add(new ValueParameter<DoubleRange>(RangeParameterName, "start, end | Range for the target window of the linear transformation", new DoubleRange(0.0, 1.0)));
41    }
42
43    public override IDeepCloneable Clone(Cloner cloner) {
44      return new ShiftToRangeTransformation(this, cloner);
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    public override 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
59      Multiplier = targetRangeWidth / originalRangeWidth;
60      Addend = Range.Start - originalRangeStart * Multiplier;
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.