Changeset 10853
- Timestamp:
- 05/14/14 15:33:09 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TransformationToSymbolicTreeMapper.cs
r10848 r10853 40 40 return GenerateModelForExponentialTransformation(); 41 41 } else if (transformation is LogarithmicTransformation) { 42 42 return GenerateModelForLogarithmicTransformation(); 43 43 } else if (transformation is PowerTransformation) { 44 44 return GenerateModelForPowerTransformation(); 45 45 } else if (transformation is ReciprocalTransformation) { 46 46 return GenerateModelForReciprocalTransformation(); 47 47 } else if (transformation is ShiftStandardDistributionTransformation) { 48 48 return GenerateModelForShiftStandardDistributionTransformation(); 49 49 } 50 50 throw new NotImplementedException(); … … 59 59 return GenerateInverseModelForExponentialTransformation(); 60 60 } else if (transformation is LogarithmicTransformation) { 61 61 return GenerateInverseModelForLogarithmicTransformation(); 62 62 } else if (transformation is PowerTransformation) { 63 63 return GenerateInverseModelForPowerTransformation(); 64 64 } else if (transformation is ReciprocalTransformation) { 65 65 return GenerateInverseModelForReciprocalTransformation(); 66 66 } else if (transformation is ShiftStandardDistributionTransformation) { 67 67 … … 72 72 73 73 #endregion 74 75 // helper 74 76 75 77 private ISymbolicExpressionTree GenerateModelForLinearTransformation() { … … 80 82 // k * x 81 83 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 }; 83 85 var xNode = new Variable(column, "x").CreateTreeNode(); 84 86 multiplicationNode.AddSubtree(kNode); … … 87 89 // ( k * x ) + d 88 90 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 }; 90 92 additionNode.AddSubtree(multiplicationNode); 91 93 additionNode.AddSubtree(dNode); … … 102 104 // x - d 103 105 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 }; 105 107 var xNode = new Variable(column, "x").CreateTreeNode(); 106 108 substractionNode.AddSubtree(xNode); … … 109 111 // ( x - d ) / k 110 112 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 }; 112 114 divisionNode.AddSubtree(substractionNode); 113 115 divisionNode.AddSubtree(kNode); … … 122 124 var bValue = exponentialTransformation.Base; 123 125 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); 133 127 } 134 128 … … 137 131 var bValue = exponentialTransformation.Base; 138 132 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 139 232 // log(x, b) 140 233 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 }; 142 235 var xNode = new Variable(column, "x").CreateTreeNode(); 143 236 logNode.AddSubtree(xNode); … … 145 238 146 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); 147 268 return tree; 148 269 }
Note: See TracChangeset
for help on using the changeset viewer.