- Timestamp:
- 02/24/22 20:33:45 (3 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs
r18174 r18220 199 199 var tanh = (ISymbolicExpressionTreeNode)branch.Clone(); 200 200 return Product(fxp, Subtract(CreateNumber(1.0), Square(tanh))); 201 } 202 if (branch.Symbol is SubFunctionSymbol) { 203 return Derive(branch.GetSubtree(0), variableName); 201 204 } 202 205 throw new NotSupportedException(string.Format("Symbol {0} is not supported.", branch.Symbol)); … … 285 288 !(n.Symbol is Cosine) && 286 289 !(n.Symbol is Tangent) && 287 !(n.Symbol is StartSymbol) 290 !(n.Symbol is StartSymbol) && 291 !(n.Symbol is SubFunctionSymbol) 288 292 select n).Any(); 289 293 return !containsUnknownSymbol; -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
r18132 r18220 106 106 out ParametricFunctionGradient func_grad) { 107 107 108 return TryConvertToAutoDiff(tree, makeVariableWeightsVariable, addLinearScalingTerms, Enumerable.Empty<ISymbolicExpressionTreeNode>(), 109 out parameters, out initialParamValues, out func, out func_grad); 110 } 111 112 public static bool TryConvertToAutoDiff(ISymbolicExpressionTree tree, bool makeVariableWeightsVariable, bool addLinearScalingTerms, IEnumerable<ISymbolicExpressionTreeNode> excludedNodes, 113 out List<DataForVariable> parameters, out double[] initialParamValues, 114 out ParametricFunction func, 115 out ParametricFunctionGradient func_grad) { 116 108 117 // use a transformator object which holds the state (variable list, parameter list, ...) for recursive transformation of the tree 109 var transformator = new TreeToAutoDiffTermConverter(makeVariableWeightsVariable, addLinearScalingTerms );118 var transformator = new TreeToAutoDiffTermConverter(makeVariableWeightsVariable, addLinearScalingTerms, excludedNodes); 110 119 AutoDiff.Term term; 111 120 try { … … 134 143 private readonly bool makeVariableWeightsVariable; 135 144 private readonly bool addLinearScalingTerms; 136 137 private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable, bool addLinearScalingTerms) { 145 private readonly HashSet<ISymbolicExpressionTreeNode> excludedNodes; 146 147 private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable, bool addLinearScalingTerms, IEnumerable<ISymbolicExpressionTreeNode> excludedNodes) { 138 148 this.makeVariableWeightsVariable = makeVariableWeightsVariable; 139 149 this.addLinearScalingTerms = addLinearScalingTerms; 150 this.excludedNodes = new HashSet<ISymbolicExpressionTreeNode>(excludedNodes); 151 140 152 this.initialParamValues = new List<double>(); 141 153 this.parameters = new Dictionary<DataForVariable, AutoDiff.Variable>(); … … 161 173 var par = FindOrCreateParameter(parameters, varNode.VariableName, varValue); 162 174 163 if (makeVariableWeightsVariable ) {175 if (makeVariableWeightsVariable && !excludedNodes.Contains(node)) { 164 176 initialParamValues.Add(varNode.Weight); 165 177 var w = new AutoDiff.Variable(); … … 176 188 var par = FindOrCreateParameter(parameters, factorVarNode.VariableName, variableValue); 177 189 178 initialParamValues.Add(factorVarNode.GetValue(variableValue)); 179 var wVar = new AutoDiff.Variable(); 180 variables.Add(wVar); 181 182 products.Add(AutoDiff.TermBuilder.Product(wVar, par)); 190 if (makeVariableWeightsVariable && !excludedNodes.Contains(node)) { 191 initialParamValues.Add(factorVarNode.GetValue(variableValue)); 192 var wVar = new AutoDiff.Variable(); 193 variables.Add(wVar); 194 195 products.Add(AutoDiff.TermBuilder.Product(wVar, par)); 196 } else { 197 var weight = factorVarNode.GetValue(variableValue); 198 products.Add(weight * par); 199 } 200 183 201 } 184 202 return AutoDiff.TermBuilder.Sum(products); … … 188 206 var par = FindOrCreateParameter(parameters, varNode.VariableName, string.Empty, varNode.Lag); 189 207 190 if (makeVariableWeightsVariable ) {208 if (makeVariableWeightsVariable && !excludedNodes.Contains(node)) { 191 209 initialParamValues.Add(varNode.Weight); 192 210 var w = new AutoDiff.Variable(); … … 305 323 return t * alpha + beta; 306 324 } else return ConvertToAutoDiff(node.GetSubtree(0)); 325 } 326 if (node.Symbol is SubFunctionSymbol) { 327 return ConvertToAutoDiff(node.GetSubtree(0)); 307 328 } 308 329 throw new ConversionException(); … … 353 374 !(n.Symbol is Cube) && 354 375 !(n.Symbol is CubeRoot) && 355 !(n.Symbol is Power) 376 !(n.Symbol is Power) && 377 !(n.Symbol is SubFunctionSymbol) 356 378 select n).Any(); 357 379 return !containsUnknownSymbol;
Note: See TracChangeset
for help on using the changeset viewer.