Changeset 10846
- Timestamp:
- 05/14/14 13:19:12 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TransformationToSymbolicTreeMapper.cs
r10845 r10846 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 23 24 using HeuristicLab.Problems.DataAnalysis.Transformations; … … 25 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 26 27 public class TransformationToSymbolicTreeMapper : ITransformationMapper<ISymbolicExpressionTree> { 28 private ITransformation transformation; 29 private string column; 30 private ISymbolicExpressionTree tree; 31 27 32 #region ITransformationMapper<ISymbolicExpressionTree> Members 28 33 29 34 public ISymbolicExpressionTree GenerateModel(ITransformation transformation) { 30 var tree = CreateNewTree(); 31 var column = transformation.Column; 35 InitComponents(transformation); 32 36 33 37 if (transformation is LinearTransformation) { 34 var kValue = ((LinearTransformation)transformation).Multiplier; 35 var multiplicationNode = new Multiplication().CreateTreeNode(); 36 var kNode = new Constant(); 38 return GenerateModelForLinearTransformation(); 37 39 } else if (transformation is ExponentialTransformation) { 38 40 … … 46 48 47 49 } 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(); 54 51 } 55 52 56 53 public ISymbolicExpressionTree GenerateInverseModel(ITransformation transformation) { 57 var tree = CreateNewTree(); 58 var column = transformation.Column; 54 InitComponents(transformation); 59 55 60 56 if (transformation is LinearTransformation) { … … 72 68 } 73 69 74 return tree;70 throw new NotImplementedException(); 75 71 } 76 72 77 73 #endregion 78 74 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 79 99 private ISymbolicExpressionTree CreateNewTree() { 80 100 return new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 81 101 } 102 103 private void InitComponents(ITransformation transformation) { 104 this.transformation = transformation; 105 column = transformation.Column; 106 tree = CreateNewTree(); 107 } 82 108 } 83 109 }
Note: See TracChangeset
for help on using the changeset viewer.