Ignore:
Timestamp:
05/14/14 13:19:12 (5 years ago)
Author:
tsteinre
Message:
  • TransformationToSymbolicTreeMapper implemented GenerateModel for
    • LinearTransformation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TransformationToSymbolicTreeMapper.cs

    r10845 r10846  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2324using HeuristicLab.Problems.DataAnalysis.Transformations;
     
    2526namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2627  public class TransformationToSymbolicTreeMapper : ITransformationMapper<ISymbolicExpressionTree> {
     28    private ITransformation transformation;
     29    private string column;
     30    private ISymbolicExpressionTree tree;
     31
    2732    #region ITransformationMapper<ISymbolicExpressionTree> Members
    2833
    2934    public ISymbolicExpressionTree GenerateModel(ITransformation transformation) {
    30       var tree = CreateNewTree();
    31       var column = transformation.Column;
     35      InitComponents(transformation);
    3236
    3337      if (transformation is LinearTransformation) {
    34         var kValue = ((LinearTransformation)transformation).Multiplier;
    35         var multiplicationNode = new Multiplication().CreateTreeNode();
    36         var kNode = new Constant();
     38        return GenerateModelForLinearTransformation();
    3739      } else if (transformation is ExponentialTransformation) {
    3840
     
    4648
    4749      }
    48 
    49       //var variableNode = (VariableTreeNode)new Variable("dummy", "dummy description").CreateTreeNode();
    50       //variableNode.VariableName = "dummy";
    51       //tree.Root.AddSubtree(variableNode);
    52 
    53       return tree;
     50      throw new NotImplementedException();
    5451    }
    5552
    5653    public ISymbolicExpressionTree GenerateInverseModel(ITransformation transformation) {
    57       var tree = CreateNewTree();
    58       var column = transformation.Column;
     54      InitComponents(transformation);
    5955
    6056      if (transformation is LinearTransformation) {
     
    7268      }
    7369
    74       return tree;
     70      throw new NotImplementedException();
    7571    }
    7672
    7773    #endregion
    7874
     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
    7999    private ISymbolicExpressionTree CreateNewTree() {
    80100      return new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
    81101    }
     102
     103    private void InitComponents(ITransformation transformation) {
     104      this.transformation = transformation;
     105      column = transformation.Column;
     106      tree = CreateNewTree();
     107    }
    82108  }
    83109}
Note: See TracChangeset for help on using the changeset viewer.