Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10846 was 10846, checked in by tsteinre, 10 years ago
  • TransformationToSymbolicTreeMapper implemented GenerateModel for
    • LinearTransformation
File size: 3.9 KB
RevLine 
[10845]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
[10846]22using System;
[10845]23using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
24using HeuristicLab.Problems.DataAnalysis.Transformations;
25
26namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
27  public class TransformationToSymbolicTreeMapper : ITransformationMapper<ISymbolicExpressionTree> {
[10846]28    private ITransformation transformation;
29    private string column;
30    private ISymbolicExpressionTree tree;
31
[10845]32    #region ITransformationMapper<ISymbolicExpressionTree> Members
33
34    public ISymbolicExpressionTree GenerateModel(ITransformation transformation) {
[10846]35      InitComponents(transformation);
[10845]36
37      if (transformation is LinearTransformation) {
[10846]38        return GenerateModelForLinearTransformation();
[10845]39      } else if (transformation is ExponentialTransformation) {
40
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      }
[10846]50      throw new NotImplementedException();
[10845]51    }
52
53    public ISymbolicExpressionTree GenerateInverseModel(ITransformation transformation) {
[10846]54      InitComponents(transformation);
[10845]55
56      if (transformation is LinearTransformation) {
57
58      } else if (transformation is ExponentialTransformation) {
59
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
[10846]70      throw new NotImplementedException();
[10845]71    }
72
73    #endregion
74
[10846]75    private ISymbolicExpressionTree GenerateModelForLinearTransformation() {
76      var linearTransformation = (LinearTransformation)transformation;
77      var tree = CreateNewTree();
78      string column = linearTransformation.Column;
79      var kValue = linearTransformation.Multiplier;
80      var dValue = linearTransformation.Addend;
81
82      // k * x
83      var multiplicationNode = new Multiplication().CreateTreeNode();
84      var kNode = new ConstantTreeNode(new Constant() { Name = "K" }) { Value = kValue };
85      var xNode = new Variable(column, "x").CreateTreeNode();
86      multiplicationNode.AddSubtree(kNode);
87      multiplicationNode.AddSubtree(xNode);
88
89      // ( k * x ) + d
90      var additionNode = new Addition().CreateTreeNode();
91      var dNode = new ConstantTreeNode(new Constant() { Name = "d" }) { Value = dValue };
92      additionNode.AddSubtree(multiplicationNode);
93      additionNode.AddSubtree(dNode);
94
95      tree.Root.AddSubtree(additionNode);
96      return tree;
97    }
98
[10845]99    private ISymbolicExpressionTree CreateNewTree() {
100      return new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
101    }
[10846]102
103    private void InitComponents(ITransformation transformation) {
104      this.transformation = transformation;
105      column = transformation.Column;
106      tree = CreateNewTree();
107    }
[10845]108  }
109}
Note: See TracBrowser for help on using the repository browser.