Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10866


Ignore:
Timestamp:
05/21/14 10:58:35 (11 years ago)
Author:
tsteinre
Message:
  • refactored TransformationToSymbolicTreeMapper
  • full support of ShiftStandardDistributionTransformation
File:
1 edited

Legend:

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

    r10853 r10866  
    6565        return GenerateInverseModelForReciprocalTransformation();
    6666      } else if (transformation is ShiftStandardDistributionTransformation) {
    67 
     67        GenerateInverseModelForShiftStandardDistributionTransformation();
    6868      }
    6969
     
    8282      // k * x
    8383      var multiplicationNode = new Multiplication().CreateTreeNode();
    84       var kNode = new ConstantTreeNode(new Constant() { Description = "K" }) { Value = kValue };
    85       var xNode = new Variable(column, "x").CreateTreeNode();
     84      var kNode = CreateConstantTreeNode("k", kValue);
     85      var xNode = CreateVariableTreeNode(column, "x");
    8686      multiplicationNode.AddSubtree(kNode);
    8787      multiplicationNode.AddSubtree(xNode);
     
    8989      // ( k * x ) + d
    9090      var additionNode = new Addition().CreateTreeNode();
    91       var dNode = new ConstantTreeNode(new Constant() { Description = "d" }) { Value = dValue };
     91      var dNode = CreateConstantTreeNode("d", dValue);
    9292      additionNode.AddSubtree(multiplicationNode);
    9393      additionNode.AddSubtree(dNode);
     
    104104      // x - d
    105105      var substractionNode = new Subtraction().CreateTreeNode();
    106       var dNode = new ConstantTreeNode(new Constant() { Description = "d" }) { Value = dValue };
    107       var xNode = new Variable(column, "x").CreateTreeNode();
     106      var dNode = CreateConstantTreeNode("d", dValue);
     107      var xNode = CreateVariableTreeNode(column, "x");
    108108      substractionNode.AddSubtree(xNode);
    109109      substractionNode.AddSubtree(dNode);
     
    111111      // ( x - d ) / k
    112112      var divisionNode = new Division().CreateTreeNode();
    113       var kNode = new ConstantTreeNode(new Constant() { Description = "K" }) { Value = kValue };
     113      var kNode = CreateConstantTreeNode("k", kValue);
    114114      divisionNode.AddSubtree(substractionNode);
    115115      divisionNode.AddSubtree(kNode);
     
    156156      // x ^ exp
    157157      var powerNode = new Power().CreateTreeNode();
    158       var xNode = new Variable(column, "x").CreateTreeNode();
    159       var expNode = new ConstantTreeNode(new Constant() { Description = "exp" }) { Value = expValue };
     158      var xNode = CreateVariableTreeNode(column, "x");
     159      var expNode = CreateConstantTreeNode("exp", expValue);
    160160      powerNode.AddSubtree(xNode);
    161161      powerNode.AddSubtree(expNode);
     
    171171      // rt(x, b)
    172172      var rootNode = new Root().CreateTreeNode();
    173       var xNode = new Variable(column, "x").CreateTreeNode();
    174       var bNode = new ConstantTreeNode(new Constant() { Description = "b" }) { Value = expValue };
     173      var xNode = CreateVariableTreeNode(column, "x");
     174      var bNode = CreateConstantTreeNode("b", expValue);
    175175      rootNode.AddSubtree(xNode);
    176176      rootNode.AddSubtree(bNode);
     
    196196      var s_tarValue = shiftStandardDistributionTransformation.StandardDeviation;
    197197
     198      return GenTreeShiftStdDist(column, m_orgValue, s_orgValue, m_tarValue, s_tarValue);
     199    }
     200
     201    private ISymbolicExpressionTree GenerateInverseModelForShiftStandardDistributionTransformation() {
     202      var shiftStandardDistributionTransformation = (ShiftStandardDistributionTransformation)transformation;
     203      var m_orgValue = shiftStandardDistributionTransformation.OriginalMean;
     204      var s_orgValue = shiftStandardDistributionTransformation.OriginalStandardDeviation;
     205      var m_tarValue = shiftStandardDistributionTransformation.Mean;
     206      var s_tarValue = shiftStandardDistributionTransformation.StandardDeviation;
     207
     208      return GenTreeShiftStdDist(column, m_tarValue, s_tarValue, m_orgValue, s_orgValue);
     209    }
     210
     211    // helper's helper:
     212
     213    private ISymbolicExpressionTree GenTreeLog_x_b(double b) {
     214      var tree = CreateNewTree();
     215
     216      // log(x, b)
     217      var logNode = new Logarithm().CreateTreeNode();
     218      var bNode = CreateConstantTreeNode("b", b);
     219      var xNode = CreateVariableTreeNode(column, "x");
     220      logNode.AddSubtree(xNode);
     221      logNode.AddSubtree(bNode);
     222
     223      tree.Root.AddSubtree(logNode);
     224      return tree;
     225    }
     226
     227    private ISymbolicExpressionTree GenTreePow_b_x(double b) {
     228      var tree = CreateNewTree();
     229
     230      // b ^ x
     231      var powerNode = new Power().CreateTreeNode();
     232      var bNode = CreateConstantTreeNode("b", b);
     233      var xNode = CreateVariableTreeNode(column, "x");
     234      powerNode.AddSubtree(bNode);
     235      powerNode.AddSubtree(xNode);
     236
     237      tree.Root.AddSubtree(powerNode);
     238      return tree;
     239    }
     240
     241    private ISymbolicExpressionTree GenTreeDiv_1_x() {
     242      var tree = CreateNewTree();
     243
     244      // 1 / x
     245      var divNode = new Division().CreateTreeNode();
     246      var oneNode = CreateConstantTreeNode("1", 1.0);
     247      var xNode = CreateVariableTreeNode(column, "x");
     248      divNode.AddSubtree(oneNode);
     249      divNode.AddSubtree(xNode);
     250
     251      tree.Root.AddSubtree(divNode);
     252      return tree;
     253    }
     254    private ISymbolicExpressionTree GenTreeShiftStdDist(string variable, double m_org, double s_org, double m_tar, double s_tar) {
     255      var tree = CreateNewTree();
    198256      // x - m_org
    199257      var substractionNode = new Subtraction().CreateTreeNode();
    200       var xNode = new Variable(column, "x").CreateTreeNode();
    201       var m_orgNode = new ConstantTreeNode(new Constant() { Description = "m_org" }) { Value = m_orgValue };
     258      var xNode = CreateVariableTreeNode(variable, "x");
     259      var m_orgNode = CreateConstantTreeNode("m_org", m_org);
    202260      substractionNode.AddSubtree(xNode);
    203261      substractionNode.AddSubtree(m_orgNode);
     
    205263      // (x - m_org) / s_org
    206264      var divisionNode = new Division().CreateTreeNode();
    207       var s_orgNode = new ConstantTreeNode(new Constant() { Description = "s_org" }) { Value = s_orgValue };
     265      var s_orgNode = CreateConstantTreeNode("s_org", s_org);
    208266      divisionNode.AddSubtree(substractionNode);
    209267      divisionNode.AddSubtree(s_orgNode);
     
    211269      // ((x - m_org) / s_org ) * s_tar
    212270      var multiplicationNode = new Multiplication().CreateTreeNode();
    213       var s_tarNode = new ConstantTreeNode(new Constant() { Description = "s_tar" }) { Value = s_tarValue };
     271      var s_tarNode = CreateConstantTreeNode("s_tar", s_tar);
    214272      multiplicationNode.AddSubtree(divisionNode);
    215273      multiplicationNode.AddSubtree(s_tarNode);
     
    217275      // ((x - m_org) / s_org ) * s_tar + m_tar
    218276      var additionNode = new Addition().CreateTreeNode();
    219       var m_tarNode = new ConstantTreeNode(new Constant() { Description = "m_tar" }) { Value = m_tarValue };
     277      var m_tarNode = CreateConstantTreeNode("m_tar", m_tar);
    220278      additionNode.AddSubtree(multiplicationNode);
    221279      additionNode.AddSubtree(m_tarNode);
     
    225283    }
    226284
    227     // helper's helper:
    228 
    229     private ISymbolicExpressionTree GenTreeLog_x_b(double b) {
    230       var tree = CreateNewTree();
    231 
    232       // log(x, b)
    233       var logNode = new Logarithm().CreateTreeNode();
    234       var bNode = new ConstantTreeNode(new Constant() { Description = "b" }) { Value = b };
    235       var xNode = new Variable(column, "x").CreateTreeNode();
    236       logNode.AddSubtree(xNode);
    237       logNode.AddSubtree(bNode);
    238 
    239       tree.Root.AddSubtree(logNode);
    240       return tree;
    241     }
    242 
    243     private ISymbolicExpressionTree GenTreePow_b_x(double b) {
    244       var tree = CreateNewTree();
    245 
    246       // b ^ x
    247       var powerNode = new Power().CreateTreeNode();
    248       var bNode = new ConstantTreeNode(new Constant() { Description = "b" }) { Value = b };
    249       var xNode = new Variable(column, "x").CreateTreeNode();
    250       powerNode.AddSubtree(bNode);
    251       powerNode.AddSubtree(xNode);
    252 
    253       tree.Root.AddSubtree(powerNode);
    254       return tree;
    255     }
    256 
    257     private ISymbolicExpressionTree GenTreeDiv_1_x() {
    258       var tree = CreateNewTree();
    259 
    260       // 1 / x
    261       var divNode = new Division().CreateTreeNode();
    262       var oneNode = new ConstantTreeNode(new Constant() { Description = "1" }) { Value = 1.0 };
    263       var xNode = new Variable(column, "x").CreateTreeNode();
    264       divNode.AddSubtree(oneNode);
    265       divNode.AddSubtree(xNode);
    266 
    267       tree.Root.AddSubtree(divNode);
    268       return tree;
     285    private ConstantTreeNode CreateConstantTreeNode(string description, double value) {
     286      return new ConstantTreeNode(new Constant() { Description = description }) { Value = value };
     287    }
     288    private ISymbolicExpressionTreeNode CreateVariableTreeNode(string name, string description) {
     289      return new Variable(name, description).CreateTreeNode();
    269290    }
    270291
Note: See TracChangeset for help on using the changeset viewer.