Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TransformationToSymbolicTreeMapper.cs @ 10848

Last change on this file since 10848 was 10848, checked in by tsteinre, 10 years ago
  • TransformationToSymbolicTreeMapper: added GenerateInverseModel[Inverse}Model for:
    • ExponentialTransformation
File size: 6.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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 HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
24using HeuristicLab.Problems.DataAnalysis.Transformations;
25
26namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
27  public class TransformationToSymbolicTreeMapper : ITransformationMapper<ISymbolicExpressionTree> {
28    private ITransformation transformation;
29    private string column;
30    private ISymbolicExpressionTree tree;
31
32    #region ITransformationMapper<ISymbolicExpressionTree> Members
33
34    public ISymbolicExpressionTree GenerateModel(ITransformation transformation) {
35      InitComponents(transformation);
36
37      if (transformation is LinearTransformation) {
38        return GenerateModelForLinearTransformation();
39      } else if (transformation is ExponentialTransformation) {
40        return GenerateModelForExponentialTransformation();
41      } else if (transformation is LogarithmicTransformation) {
42
43      } else if (transformation is PowerTransformation) {
44
45      } else if (transformation is ReciprocalTransformation) {
46
47      } else if (transformation is ShiftStandardDistributionTransformation) {
48
49      }
50      throw new NotImplementedException();
51    }
52
53    public ISymbolicExpressionTree GenerateInverseModel(ITransformation transformation) {
54      InitComponents(transformation);
55
56      if (transformation is LinearTransformation) {
57        return GenerateInverseModelForLinearTransformation();
58      } else if (transformation is ExponentialTransformation) {
59        return GenerateInverseModelForExponentialTransformation();
60      } else if (transformation is LogarithmicTransformation) {
61
62      } else if (transformation is PowerTransformation) {
63
64      } else if (transformation is ReciprocalTransformation) {
65
66      } else if (transformation is ShiftStandardDistributionTransformation) {
67
68      }
69
70      throw new NotImplementedException();
71    }
72
73    #endregion
74
75    private ISymbolicExpressionTree GenerateModelForLinearTransformation() {
76      var linearTransformation = (LinearTransformation)transformation;
77      var kValue = linearTransformation.Multiplier;
78      var dValue = linearTransformation.Addend;
79
80      // k * x
81      var multiplicationNode = new Multiplication().CreateTreeNode();
82      var kNode = new ConstantTreeNode(new Constant() { Name = "K" }) { Value = kValue };
83      var xNode = new Variable(column, "x").CreateTreeNode();
84      multiplicationNode.AddSubtree(kNode);
85      multiplicationNode.AddSubtree(xNode);
86
87      // ( k * x ) + d
88      var additionNode = new Addition().CreateTreeNode();
89      var dNode = new ConstantTreeNode(new Constant() { Name = "d" }) { Value = dValue };
90      additionNode.AddSubtree(multiplicationNode);
91      additionNode.AddSubtree(dNode);
92
93      tree.Root.AddSubtree(additionNode);
94      return tree;
95    }
96
97    private ISymbolicExpressionTree GenerateInverseModelForLinearTransformation() {
98      var linearTransformation = (LinearTransformation)transformation;
99      var kValue = linearTransformation.Multiplier;
100      var dValue = linearTransformation.Addend;
101
102      // x - d
103      var substractionNode = new Subtraction().CreateTreeNode();
104      var dNode = new ConstantTreeNode(new Constant() { Name = "d" }) { Value = dValue };
105      var xNode = new Variable(column, "x").CreateTreeNode();
106      substractionNode.AddSubtree(xNode);
107      substractionNode.AddSubtree(dNode);
108
109      // ( x - d ) / k
110      var divisionNode = new Division().CreateTreeNode();
111      var kNode = new ConstantTreeNode(new Constant() { Name = "K" }) { Value = kValue };
112      divisionNode.AddSubtree(substractionNode);
113      divisionNode.AddSubtree(kNode);
114
115      tree.Root.AddSubtree(divisionNode);
116      return tree;
117    }
118
119
120    private ISymbolicExpressionTree GenerateModelForExponentialTransformation() {
121      var exponentialTransformation = (ExponentialTransformation)transformation;
122      var bValue = exponentialTransformation.Base;
123
124      // b ^ x
125      var powerNode = new Power().CreateTreeNode();
126      var bNode = new ConstantTreeNode(new Constant() { Name = "b" }) { Value = bValue };
127      var xNode = new Variable(column, "x").CreateTreeNode();
128      powerNode.AddSubtree(bNode);
129      powerNode.AddSubtree(xNode);
130
131      tree.Root.AddSubtree(powerNode);
132      return tree;
133    }
134
135    private ISymbolicExpressionTree GenerateInverseModelForExponentialTransformation() {
136      var exponentialTransformation = (ExponentialTransformation)transformation;
137      var bValue = exponentialTransformation.Base;
138
139      // log(x, b)
140      var logNode = new Logarithm().CreateTreeNode();
141      var bNode = new ConstantTreeNode(new Constant() { Name = "b" }) { Value = bValue };
142      var xNode = new Variable(column, "x").CreateTreeNode();
143      logNode.AddSubtree(xNode);
144      logNode.AddSubtree(bNode);
145
146      tree.Root.AddSubtree(logNode);
147      return tree;
148    }
149
150
151    private ISymbolicExpressionTree CreateNewTree() {
152      return new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
153    }
154
155    private void InitComponents(ITransformation transformation) {
156      this.transformation = transformation;
157      column = transformation.Column;
158      tree = CreateNewTree();
159    }
160  }
161}
Note: See TracBrowser for help on using the repository browser.