Changeset 10853


Ignore:
Timestamp:
05/14/14 15:33:09 (5 years ago)
Author:
tsteinre
Message:
  • TransformationToSymbolicTreeMapper: added further Generate[Inverse]Model methods.
File:
1 edited

Legend:

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

    r10848 r10853  
    4040        return GenerateModelForExponentialTransformation();
    4141      } else if (transformation is LogarithmicTransformation) {
    42 
     42        return GenerateModelForLogarithmicTransformation();
    4343      } else if (transformation is PowerTransformation) {
    44 
     44        return GenerateModelForPowerTransformation();
    4545      } else if (transformation is ReciprocalTransformation) {
    46 
     46        return GenerateModelForReciprocalTransformation();
    4747      } else if (transformation is ShiftStandardDistributionTransformation) {
    48 
     48        return GenerateModelForShiftStandardDistributionTransformation();
    4949      }
    5050      throw new NotImplementedException();
     
    5959        return GenerateInverseModelForExponentialTransformation();
    6060      } else if (transformation is LogarithmicTransformation) {
    61 
     61        return GenerateInverseModelForLogarithmicTransformation();
    6262      } else if (transformation is PowerTransformation) {
    63 
     63        return GenerateInverseModelForPowerTransformation();
    6464      } else if (transformation is ReciprocalTransformation) {
    65 
     65        return GenerateInverseModelForReciprocalTransformation();
    6666      } else if (transformation is ShiftStandardDistributionTransformation) {
    6767
     
    7272
    7373    #endregion
     74
     75    // helper
    7476
    7577    private ISymbolicExpressionTree GenerateModelForLinearTransformation() {
     
    8082      // k * x
    8183      var multiplicationNode = new Multiplication().CreateTreeNode();
    82       var kNode = new ConstantTreeNode(new Constant() { Name = "K" }) { Value = kValue };
     84      var kNode = new ConstantTreeNode(new Constant() { Description = "K" }) { Value = kValue };
    8385      var xNode = new Variable(column, "x").CreateTreeNode();
    8486      multiplicationNode.AddSubtree(kNode);
     
    8789      // ( k * x ) + d
    8890      var additionNode = new Addition().CreateTreeNode();
    89       var dNode = new ConstantTreeNode(new Constant() { Name = "d" }) { Value = dValue };
     91      var dNode = new ConstantTreeNode(new Constant() { Description = "d" }) { Value = dValue };
    9092      additionNode.AddSubtree(multiplicationNode);
    9193      additionNode.AddSubtree(dNode);
     
    102104      // x - d
    103105      var substractionNode = new Subtraction().CreateTreeNode();
    104       var dNode = new ConstantTreeNode(new Constant() { Name = "d" }) { Value = dValue };
     106      var dNode = new ConstantTreeNode(new Constant() { Description = "d" }) { Value = dValue };
    105107      var xNode = new Variable(column, "x").CreateTreeNode();
    106108      substractionNode.AddSubtree(xNode);
     
    109111      // ( x - d ) / k
    110112      var divisionNode = new Division().CreateTreeNode();
    111       var kNode = new ConstantTreeNode(new Constant() { Name = "K" }) { Value = kValue };
     113      var kNode = new ConstantTreeNode(new Constant() { Description = "K" }) { Value = kValue };
    112114      divisionNode.AddSubtree(substractionNode);
    113115      divisionNode.AddSubtree(kNode);
     
    122124      var bValue = exponentialTransformation.Base;
    123125
    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;
     126      return GenTreePow_b_x(bValue);
    133127    }
    134128
     
    137131      var bValue = exponentialTransformation.Base;
    138132
     133      return GenTreeLog_x_b(bValue);
     134    }
     135
     136
     137    private ISymbolicExpressionTree GenerateModelForLogarithmicTransformation() {
     138      var logarithmicTransformation = (LogarithmicTransformation)transformation;
     139      var bValue = logarithmicTransformation.Base;
     140
     141      return GenTreeLog_x_b(bValue);
     142    }
     143
     144    private ISymbolicExpressionTree GenerateInverseModelForLogarithmicTransformation() {
     145      var logarithmicTransformation = (LogarithmicTransformation)transformation;
     146      var bValue = logarithmicTransformation.Base;
     147
     148      return GenTreePow_b_x(bValue);
     149    }
     150
     151
     152    private ISymbolicExpressionTree GenerateModelForPowerTransformation() {
     153      var powerTransformation = (PowerTransformation)transformation;
     154      var expValue = powerTransformation.Exponent;
     155
     156      // x ^ exp
     157      var powerNode = new Power().CreateTreeNode();
     158      var xNode = new Variable(column, "x").CreateTreeNode();
     159      var expNode = new ConstantTreeNode(new Constant() { Description = "exp" }) { Value = expValue };
     160      powerNode.AddSubtree(xNode);
     161      powerNode.AddSubtree(expNode);
     162
     163      tree.Root.AddSubtree(powerNode);
     164      return tree;
     165    }
     166
     167    private ISymbolicExpressionTree GenerateInverseModelForPowerTransformation() {
     168      var powerTransformation = (PowerTransformation)transformation;
     169      var expValue = powerTransformation.Exponent;
     170
     171      // rt(x, b)
     172      var rootNode = new Root().CreateTreeNode();
     173      var xNode = new Variable(column, "x").CreateTreeNode();
     174      var bNode = new ConstantTreeNode(new Constant() { Description = "b" }) { Value = expValue };
     175      rootNode.AddSubtree(xNode);
     176      rootNode.AddSubtree(bNode);
     177
     178      tree.Root.AddSubtree(rootNode);
     179      return tree;
     180    }
     181
     182
     183    private ISymbolicExpressionTree GenerateModelForReciprocalTransformation() {
     184      return GenTreeDiv_1_x();
     185    }
     186
     187    private ISymbolicExpressionTree GenerateInverseModelForReciprocalTransformation() {
     188      return GenTreeDiv_1_x();
     189    }
     190
     191    private ISymbolicExpressionTree GenerateModelForShiftStandardDistributionTransformation() {
     192      var shiftStandardDistributionTransformation = (ShiftStandardDistributionTransformation)transformation;
     193      var m_orgValue = shiftStandardDistributionTransformation.OriginalMean;
     194      var s_orgValue = shiftStandardDistributionTransformation.OriginalStandardDeviation;
     195      var m_tarValue = shiftStandardDistributionTransformation.Mean;
     196      var s_tarValue = shiftStandardDistributionTransformation.StandardDeviation;
     197
     198      // x - m_org
     199      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 };
     202      substractionNode.AddSubtree(xNode);
     203      substractionNode.AddSubtree(m_orgNode);
     204
     205      // (x - m_org) / s_org
     206      var divisionNode = new Division().CreateTreeNode();
     207      var s_orgNode = new ConstantTreeNode(new Constant() { Description = "s_org" }) { Value = s_orgValue };
     208      divisionNode.AddSubtree(substractionNode);
     209      divisionNode.AddSubtree(s_orgNode);
     210
     211      // ((x - m_org) / s_org ) * s_tar
     212      var multiplicationNode = new Multiplication().CreateTreeNode();
     213      var s_tarNode = new ConstantTreeNode(new Constant() { Description = "s_tar" }) { Value = s_tarValue };
     214      multiplicationNode.AddSubtree(divisionNode);
     215      multiplicationNode.AddSubtree(s_tarNode);
     216
     217      // ((x - m_org) / s_org ) * s_tar + m_tar
     218      var additionNode = new Addition().CreateTreeNode();
     219      var m_tarNode = new ConstantTreeNode(new Constant() { Description = "m_tar" }) { Value = m_tarValue };
     220      additionNode.AddSubtree(multiplicationNode);
     221      additionNode.AddSubtree(m_tarNode);
     222
     223      tree.Root.AddSubtree(additionNode);
     224      return tree;
     225    }
     226
     227    // helper's helper:
     228
     229    private ISymbolicExpressionTree GenTreeLog_x_b(double b) {
     230      var tree = CreateNewTree();
     231
    139232      // log(x, b)
    140233      var logNode = new Logarithm().CreateTreeNode();
    141       var bNode = new ConstantTreeNode(new Constant() { Name = "b" }) { Value = bValue };
     234      var bNode = new ConstantTreeNode(new Constant() { Description = "b" }) { Value = b };
    142235      var xNode = new Variable(column, "x").CreateTreeNode();
    143236      logNode.AddSubtree(xNode);
     
    145238
    146239      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);
    147268      return tree;
    148269    }
Note: See TracChangeset for help on using the changeset viewer.