source: branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ExponentialTransformation.cs @ 15865

Last change on this file since 15865 was 15865, checked in by pfleck, 15 months ago

#2906 Added PreprocessingTransformation as a custom view-model for transformations in preprocessing.

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.DataAnalysis {
32  [Item("Exponential", "Exponential transformation x' = Base ^ x")]
33  [StorableClass]
34  public class ExponentialTransformation : Transformation<double> {
35    #region Parameters
36    private FixedValueParameter<DoubleValue> BaseParameter {
37      get { return (FixedValueParameter<DoubleValue>)Parameters["Base"]; }
38    }
39    #endregion
40
41    #region Properties
42    public double Base {
43      get { return BaseParameter.Value.Value; }
44      set { BaseParameter.Value.Value = value; }
45    }
46    #endregion
47
48    #region Constructor, Cloning & Persistence
49    public ExponentialTransformation()
50      : base() {
51      Parameters.Add(new FixedValueParameter<DoubleValue>("Base", "", new DoubleValue(Math.E)));
52    }
53
54    protected ExponentialTransformation(ExponentialTransformation original, Cloner cloner)
55      : base(original, cloner) {
56    }
57    public override IDeepCloneable Clone(Cloner cloner) {
58      return new ExponentialTransformation(this, cloner);
59    }
60
61    [StorableConstructor]
62    protected ExponentialTransformation(bool deserializing)
63      : base(deserializing) {
64    }
65    #endregion
66
67    public override IEnumerable<double> Apply(IEnumerable<double> data) {
68      return Apply(data, Base);
69    }
70
71    public override IEnumerable<double> InverseApply(IEnumerable<double> data) {
72      return InverseApply(data, Base);
73    }
74
75
76    public static IEnumerable<double> Apply(IEnumerable<double> data, double @base = Math.E) {
77      return data.Select(x => Math.Pow(@base, x));
78    }
79
80    public static IEnumerable<double> InverseApply(IEnumerable<double> data, double @base = Math.E) {
81      return LogarithmTransformation.Apply(data, @base);
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.