- Timestamp:
- 06/30/10 15:14:31 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionSolutionLinearScaler.cs
r3801 r3986 73 73 DoubleValue beta = BetaParameter.ActualValue; 74 74 if (alpha != null && beta != null) { 75 var mainBranch = tree.Root.SubTrees[0].SubTrees[0]; 76 var scaledMainBranch = MakeSum(MakeProduct(beta.Value, mainBranch), alpha.Value); 77 78 // remove the main branch before cloning to prevent cloning of sub-trees 79 tree.Root.SubTrees[0].RemoveSubTree(0); 80 var scaledTree = (SymbolicExpressionTree)tree.Clone(); 81 // insert main branch into the original tree again 82 tree.Root.SubTrees[0].InsertSubTree(0, mainBranch); 83 // insert the scaled main branch into the cloned tree 84 scaledTree.Root.SubTrees[0].InsertSubTree(0, scaledMainBranch); 85 ScaledSymbolicExpressionTreeParameter.ActualValue = scaledTree; 75 ScaledSymbolicExpressionTreeParameter.ActualValue = Scale(tree, alpha.Value, beta.Value); 86 76 } else { 87 77 // alpha or beta parameter not available => do not scale tree 88 78 ScaledSymbolicExpressionTreeParameter.ActualValue = tree; 89 79 } 90 80 91 81 return base.Apply(); 92 82 } 93 83 94 private SymbolicExpressionTreeNode MakeSum(SymbolicExpressionTreeNode treeNode, double alpha) { 84 public static SymbolicExpressionTree Scale(SymbolicExpressionTree original, double alpha, double beta) { 85 var mainBranch = original.Root.SubTrees[0].SubTrees[0]; 86 var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha); 87 88 // remove the main branch before cloning to prevent cloning of sub-trees 89 original.Root.SubTrees[0].RemoveSubTree(0); 90 var scaledTree = (SymbolicExpressionTree)original.Clone(); 91 // insert main branch into the original tree again 92 original.Root.SubTrees[0].InsertSubTree(0, mainBranch); 93 // insert the scaled main branch into the cloned tree 94 scaledTree.Root.SubTrees[0].InsertSubTree(0, scaledMainBranch); 95 return scaledTree; 96 } 97 98 private static SymbolicExpressionTreeNode MakeSum(SymbolicExpressionTreeNode treeNode, double alpha) { 95 99 var node = (new Addition()).CreateTreeNode(); 96 100 var alphaConst = MakeConstant(alpha); … … 100 104 } 101 105 102 private SymbolicExpressionTreeNode MakeProduct(double beta, SymbolicExpressionTreeNode treeNode) {106 private static SymbolicExpressionTreeNode MakeProduct(double beta, SymbolicExpressionTreeNode treeNode) { 103 107 var node = (new Multiplication()).CreateTreeNode(); 104 108 var betaConst = MakeConstant(beta); … … 108 112 } 109 113 110 private SymbolicExpressionTreeNode MakeConstant(double c) {114 private static SymbolicExpressionTreeNode MakeConstant(double c) { 111 115 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 112 116 node.Value = c;
Note: See TracChangeset
for help on using the changeset viewer.