Changeset 16899 for branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters
- Timestamp:
- 05/06/19 14:20:06 (6 years ago)
- Location:
- branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 16737,16740,16758,16762,16764,16768,16802,16822,16839,16858,16868
- Property svn:mergeinfo changed
-
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs
r16565 r16899 83 83 if (branch.SubtreeCount >= 2) { 84 84 var f = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone(); 85 var g = (ISymbolicExpressionTreeNode)branch.GetSubtree(1).Clone();86 85 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(); 90 88 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; 94 94 } 95 return f gPrime;95 return fprime; 96 96 } else 97 97 // multiplication with only one argument has no effect -> derive the argument -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs
r16565 r16899 38 38 double @const = 0) { 39 39 40 if (factorCoefficients.Length == 0 && coefficients.Length == 0) throw new ArgumentException(); 40 if (factorCoefficients.Length == 0 && coefficients.Length == 0 && @const==0) throw new ArgumentException(); 41 42 // Combine both trees 43 ISymbolicExpressionTreeNode add = (new Addition()).CreateTreeNode(); 41 44 42 45 // Create tree for double variables 43 ISymbolicExpressionTree tree = null;44 46 if (coefficients.Length > 0) { 45 tree = CreateTree(variableNames, new int[variableNames.Length], coefficients, @const); 46 if (factorCoefficients.Length == 0) return tree; 47 var varTree = CreateTree(variableNames, new int[variableNames.Length], coefficients); 48 foreach (var varNode in varTree.IterateNodesPrefix().OfType<VariableTreeNode>()) 49 add.AddSubtree(varNode); 47 50 } 48 51 49 52 // Create tree for string variables 50 ISymbolicExpressionTree factorTree = null;51 53 if (factorCoefficients.Length > 0) { 52 factorTree = CreateTree(factors, factorCoefficients, @const); 53 if (tree == null) return factorTree; 54 var factorTree = CreateTree(factors, factorCoefficients); 55 foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>()) 56 add.AddSubtree(binFactorNode); 54 57 } 55 58 56 // Combine both trees 57 ISymbolicExpressionTreeNode add = tree.Root.GetSubtree(0).GetSubtree(0); 58 foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>()) 59 add.InsertSubtree(add.SubtreeCount - 1, binFactorNode); 59 if (@const!=0.0) { 60 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode(); 61 cNode.Value = @const; 62 add.AddSubtree(cNode); 63 } 64 65 ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 66 ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode(); 67 tree.Root.AddSubtree(startNode); 68 startNode.AddSubtree(add); 60 69 return tree; 61 62 throw new ArgumentException();63 70 } 64 71
Note: See TracChangeset
for help on using the changeset viewer.