Changeset 16140 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
- Timestamp:
- 09/14/18 11:36:59 (6 years ago)
- Location:
- branches/2817-BinPackingSpeedup
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
r14950 r16140 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 87 87 #endregion 88 88 89 public static bool TryConvertToAutoDiff(ISymbolicExpressionTree tree, bool makeVariableWeightsVariable, 89 public static bool TryConvertToAutoDiff(ISymbolicExpressionTree tree, bool makeVariableWeightsVariable, bool addLinearScalingTerms, 90 90 out List<DataForVariable> parameters, out double[] initialConstants, 91 91 out ParametricFunction func, … … 93 93 94 94 // 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); 96 96 AutoDiff.Term term; 97 97 try { … … 120 120 private readonly List<AutoDiff.Variable> variables; 121 121 private readonly bool makeVariableWeightsVariable; 122 123 private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable) { 122 private readonly bool addLinearScalingTerms; 123 124 private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable, bool addLinearScalingTerms) { 124 125 this.makeVariableWeightsVariable = makeVariableWeightsVariable; 126 this.addLinearScalingTerms = addLinearScalingTerms; 125 127 this.initialConstants = new List<double>(); 126 128 this.parameters = new Dictionary<DataForVariable, AutoDiff.Variable>(); … … 248 250 } 249 251 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)); 255 261 } 256 262 throw new ConversionException();
Note: See TracChangeset
for help on using the changeset viewer.