Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/30/10 15:14:31 (14 years ago)
Author:
gkronber
Message:

Moved code for the manipulation of SymbolicExpressionTrees to include the linear scaling calculation into a static method. #938

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionSolutionLinearScaler.cs

    r3801 r3986  
    7373      DoubleValue beta = BetaParameter.ActualValue;
    7474      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);
    8676      } else {
    8777        // alpha or beta parameter not available => do not scale tree
    8878        ScaledSymbolicExpressionTreeParameter.ActualValue = tree;
    8979      }
    90      
     80
    9181      return base.Apply();
    9282    }
    9383
    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) {
    9599      var node = (new Addition()).CreateTreeNode();
    96100      var alphaConst = MakeConstant(alpha);
     
    100104    }
    101105
    102     private SymbolicExpressionTreeNode MakeProduct(double beta, SymbolicExpressionTreeNode treeNode) {
     106    private static SymbolicExpressionTreeNode MakeProduct(double beta, SymbolicExpressionTreeNode treeNode) {
    103107      var node = (new Multiplication()).CreateTreeNode();
    104108      var betaConst = MakeConstant(beta);
     
    108112    }
    109113
    110     private SymbolicExpressionTreeNode MakeConstant(double c) {
     114    private static SymbolicExpressionTreeNode MakeConstant(double c) {
    111115      var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();
    112116      node.Value = c;
Note: See TracChangeset for help on using the changeset viewer.