Changeset 13267 for trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression
- Timestamp:
- 11/18/15 22:29:17 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs
r12937 r13267 102 102 return InterpretRec(tree.Root.GetSubtree(0).GetSubtree(0), dataset, rows); 103 103 } 104 105 104 106 105 private IEnumerable<double> InterpretRec(ISymbolicExpressionTreeNode node, IDataset dataset, IEnumerable<int> rows) { 107 var eval = CreateEvalClosure(dataset, rows); 106 Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<double, double, double>, IEnumerable<double>> binaryEval = 107 (left, right, f) => InterpretRec(left, dataset,rows).Zip(InterpretRec(right, dataset, rows), f); 108 108 109 109 switch (node.Symbol.Name) { 110 case "+": return eval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x + y);111 case "*": return eval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x * y);112 case "-": return eval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x - y);113 case "%": return eval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => y.IsAlmost(0.0) ? 0.0 : x / y); // protected division110 case "+": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x + y); 111 case "*": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x * y); 112 case "-": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x - y); 113 case "%": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => y.IsAlmost(0.0) ? 0.0 : x / y); // protected division 114 114 default: { 115 115 double erc; … … 124 124 } 125 125 126 private Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<double, double, double>, IEnumerable<double>> CreateEvalClosure(IDataset dataset, IEnumerable<int> rows) {127 // capture dataset and rows in scope128 return (a, b, f) => {129 var leftResult = InterpretRec(a, dataset, rows);130 var rightResult = InterpretRec(b, dataset, rows);131 return leftResult.Zip(rightResult, f);132 };133 }134 135 126 #region item cloning and persistence 136 127 // persistence
Note: See TracChangeset
for help on using the changeset viewer.