Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/07/19 13:32:09 (5 years ago)
Author:
mkommend
Message:

#2974: Merged trunk changes into branch.

Location:
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    8383        if (branch.SubtreeCount >= 2) {
    8484          var f = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone();
    85           var g = (ISymbolicExpressionTreeNode)branch.GetSubtree(1).Clone();
    8685          var fprime = Derive(f, variableName);
    87           var gprime = Derive(g, variableName);
    88           var fgPrime = Sum(Product(f, gprime), Product(fprime, g));
    89           for (int i = 2; i < branch.SubtreeCount; i++) {
     86          for (int i = 1; i < branch.SubtreeCount; i++) {
     87            var g = (ISymbolicExpressionTreeNode)branch.GetSubtree(i).Clone();
    9088            var fg = Product((ISymbolicExpressionTreeNode)f.Clone(), (ISymbolicExpressionTreeNode)g.Clone());
    91             var h = (ISymbolicExpressionTreeNode)branch.GetSubtree(i).Clone();
    92             var hPrime = Derive(h, variableName);
    93             fgPrime = Sum(Product(fgPrime, h), Product(fg, hPrime));
     89            var gPrime = Derive(g, variableName);
     90            var fgPrime = Sum(Product(fprime, g), Product(gPrime, f));
     91            // prepare for next iteration
     92            f = fg;
     93            fprime = fgPrime;
    9494          }
    95           return fgPrime;
     95          return fprime;
    9696        } else
    9797          // multiplication with only one argument has no effect -> derive the argument
     
    143143        var f = (ISymbolicExpressionTreeNode)branch.Clone();
    144144        var u = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone();
    145         return Product(Div(CreateConstant(1.0), Product(CreateConstant(3.0), Square(f))), Derive(u, variableName));
     145        return Product(Div(CreateConstant(1.0), Product(CreateConstant(3.0), Square(f))), Derive(u, variableName));  // 1/3 1/cbrt(f(x))^2 d/dx f(x)
    146146      }
    147147      if (branch.Symbol is Cube) {
     
    179179        var u = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone();
    180180        return Div(fxp, Square(Cosine(u)));
     181      }
     182      if (branch.Symbol is HyperbolicTangent) {
     183        // tanh(f(x))' = f(x)'sech²(f(x)) = f(x)'(1 - tanh²(f(x)))
     184        var fxp = Derive(branch.GetSubtree(0), variableName);
     185        var tanh = (ISymbolicExpressionTreeNode)branch.Clone();
     186        return Product(fxp, Subtract(CreateConstant(1.0), Square(tanh)));
    181187      }
    182188      throw new NotSupportedException(string.Format("Symbol {0} is not supported.", branch.Symbol));
Note: See TracChangeset for help on using the changeset viewer.