- Timestamp:
- 04/01/15 15:52:38 (10 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12227,12262,12264
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 12227,12262,12264
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r12009 r12277 287 287 // make sum(x0..xn) / n 288 288 var sum = original.Subtrees 289 .Select( x => GetSimplifiedTree(x))290 .Aggregate( (a, b) => MakeSum(a, b));289 .Select(GetSimplifiedTree) 290 .Aggregate(MakeSum); 291 291 return MakeFraction(sum, MakeConstant(original.Subtrees.Count())); 292 292 } … … 299 299 // simplify expressions x0..xn 300 300 // make multiplication (x0 * 1/(x1 * x1 * .. * xn)) 301 var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x)); 301 var first = original.GetSubtree(0); 302 var second = original.GetSubtree(1); 303 var remaining = original.Subtrees.Skip(2); 302 304 return 303 MakeProduct( simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate((a, b) => MakeProduct(a, b))));305 MakeProduct(GetSimplifiedTree(first), Invert(remaining.Aggregate(GetSimplifiedTree(second), (a, b) => MakeProduct(a, GetSimplifiedTree(b))))); 304 306 } 305 307 } … … 310 312 } else { 311 313 return original.Subtrees 312 .Select( x => GetSimplifiedTree(x))313 .Aggregate( (a, b) => MakeProduct(a, b));314 .Select(GetSimplifiedTree) 315 .Aggregate(MakeProduct); 314 316 } 315 317 } … … 321 323 // simplify expressions x0..xn 322 324 // make addition (x0,-x1..-xn) 323 var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x)); 324 return simplifiedTrees.Take(1) 325 .Concat(simplifiedTrees.Skip(1).Select(x => Negate(x))) 326 .Aggregate((a, b) => MakeSum(a, b)); 325 var first = original.Subtrees.First(); 326 var remaining = original.Subtrees.Skip(1); 327 return remaining.Aggregate(GetSimplifiedTree(first), (a, b) => MakeSum(a, Negate(GetSimplifiedTree(b)))); 327 328 } 328 329 } … … 335 336 // make addition (x0..xn) 336 337 return original.Subtrees 337 .Select( x => GetSimplifiedTree(x))338 .Aggregate( (a, b) => MakeSum(a, b));338 .Select(GetSimplifiedTree) 339 .Aggregate(MakeSum); 339 340 } 340 341 } … … 345 346 private ISymbolicExpressionTreeNode SimplifyOr(ISymbolicExpressionTreeNode original) { 346 347 return original.Subtrees 347 .Select( x => GetSimplifiedTree(x))348 .Aggregate( (a, b) => MakeOr(a, b));348 .Select(GetSimplifiedTree) 349 .Aggregate(MakeOr); 349 350 } 350 351 private ISymbolicExpressionTreeNode SimplifyAnd(ISymbolicExpressionTreeNode original) { 351 352 return original.Subtrees 352 .Select( x => GetSimplifiedTree(x))353 .Aggregate( (a, b) => MakeAnd(a, b));353 .Select(GetSimplifiedTree) 354 .Aggregate(MakeAnd); 354 355 } 355 356 private ISymbolicExpressionTreeNode SimplifyLessThan(ISymbolicExpressionTreeNode original) { … … 831 832 private void MergeVariablesInSum(ISymbolicExpressionTreeNode sum) { 832 833 var subtrees = new List<ISymbolicExpressionTreeNode>(sum.Subtrees); 833 while (sum.Subtrees. Count() > 0) sum.RemoveSubtree(0);834 while (sum.Subtrees.Any()) sum.RemoveSubtree(0); 834 835 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>() 835 836 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 … … 949 950 private void MergeVariablesAndConstantsInProduct(ISymbolicExpressionTreeNode prod) { 950 951 var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees); 951 while (prod.Subtrees. Count() > 0) prod.RemoveSubtree(0);952 while (prod.Subtrees.Any()) prod.RemoveSubtree(0); 952 953 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>() 953 954 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 … … 1004 1005 } else if (IsAddition(x)) { 1005 1006 // (x0 + x1 + .. + xn) * -1 => (-x0 + -x1 + .. + -xn) 1006 List<ISymbolicExpressionTreeNode>subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees);1007 while (x.Subtrees. Count() > 0) x.RemoveSubtree(0);1007 var subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees); 1008 while (x.Subtrees.Any()) x.RemoveSubtree(0); 1008 1009 foreach (var subtree in subtrees) { 1009 1010 x.AddSubtree(Negate(subtree));
Note: See TracChangeset
for help on using the changeset viewer.