Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/12/17 16:16:12 (7 years ago)
Author:
mkommend
Message:

#2852: Merged r15447, r15448, r15480, r15481, r15483 into stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs

    r15145 r15515  
    8787    #endregion
    8888
    89     public static bool TryConvertToAutoDiff(ISymbolicExpressionTree tree, bool makeVariableWeightsVariable,
     89    public static bool TryConvertToAutoDiff(ISymbolicExpressionTree tree, bool makeVariableWeightsVariable, bool addLinearScalingTerms,
    9090      out List<DataForVariable> parameters, out double[] initialConstants,
    9191      out ParametricFunction func,
     
    9393
    9494      // use a transformator object which holds the state (variable list, parameter list, ...) for recursive transformation of the tree
    95       var transformator = new TreeToAutoDiffTermConverter(makeVariableWeightsVariable);
     95      var transformator = new TreeToAutoDiffTermConverter(makeVariableWeightsVariable, addLinearScalingTerms);
    9696      AutoDiff.Term term;
    9797      try {
     
    120120    private readonly List<AutoDiff.Variable> variables;
    121121    private readonly bool makeVariableWeightsVariable;
    122 
    123     private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable) {
     122    private readonly bool addLinearScalingTerms;
     123
     124    private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable, bool addLinearScalingTerms) {
    124125      this.makeVariableWeightsVariable = makeVariableWeightsVariable;
     126      this.addLinearScalingTerms = addLinearScalingTerms;
    125127      this.initialConstants = new List<double>();
    126128      this.parameters = new Dictionary<DataForVariable, AutoDiff.Variable>();
     
    248250      }
    249251      if (node.Symbol is StartSymbol) {
    250         var alpha = new AutoDiff.Variable();
    251         var beta = new AutoDiff.Variable();
    252         variables.Add(beta);
    253         variables.Add(alpha);
    254         return ConvertToAutoDiff(node.GetSubtree(0)) * alpha + beta;
     252        if (addLinearScalingTerms) {
     253          // scaling variables α, β are given at the beginning of the parameter vector
     254          var alpha = new AutoDiff.Variable();
     255          var beta = new AutoDiff.Variable();
     256          variables.Add(beta);
     257          variables.Add(alpha);
     258          var t = ConvertToAutoDiff(node.GetSubtree(0));
     259          return t * alpha + beta;
     260        } else return ConvertToAutoDiff(node.GetSubtree(0));
    255261      }
    256262      throw new ConversionException();
Note: See TracChangeset for help on using the changeset viewer.