Changeset 13869 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective
- Timestamp:
- 06/01/16 17:00:19 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r13670 r13869 337 337 if (node.Symbol is Multiplication) { 338 338 AutoDiff.Term a, b; 339 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out a) || 340 !TryTransformToAutoDiff(node.GetSubtree(1), variables, parameters, variableNames, updateVariableWeights, out b)) { 341 term = null; 342 return false; 343 } else { 344 List<AutoDiff.Term> factors = new List<Term>(); 345 foreach (var subTree in node.Subtrees.Skip(2)) { 346 AutoDiff.Term f; 347 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out f)) { 348 term = null; 349 return false; 350 } 351 factors.Add(f); 352 } 353 term = AutoDiff.TermBuilder.Product(a, b, factors.ToArray()); 354 return true; 355 } 339 if (node.SubtreeCount == 1) { 340 a = AutoDiff.TermBuilder.Constant(1); 341 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out b)) { 342 term = null; 343 return false; 344 } 345 } else { 346 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out a) || 347 !TryTransformToAutoDiff(node.GetSubtree(1), variables, parameters, variableNames, updateVariableWeights, out b)) { 348 term = null; 349 return false; 350 } 351 } 352 List<AutoDiff.Term> factors = new List<Term>(); 353 foreach (var subTree in node.Subtrees.Skip(2)) { 354 AutoDiff.Term f; 355 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out f)) { 356 term = null; 357 return false; 358 } 359 factors.Add(f); 360 } 361 term = AutoDiff.TermBuilder.Product(a, b, factors.ToArray()); 362 return true; 356 363 } 357 364 if (node.Symbol is Division) { 358 // only works for at least two subtrees359 365 AutoDiff.Term a, b; 360 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out a) || 361 !TryTransformToAutoDiff(node.GetSubtree(1), variables, parameters, variableNames, updateVariableWeights, out b)) { 362 term = null; 363 return false; 364 } else { 365 List<AutoDiff.Term> factors = new List<Term>(); 366 foreach (var subTree in node.Subtrees.Skip(2)) { 367 AutoDiff.Term f; 368 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out f)) { 369 term = null; 370 return false; 371 } 372 factors.Add(1.0 / f); 373 } 374 term = AutoDiff.TermBuilder.Product(a, 1.0 / b, factors.ToArray()); 375 return true; 376 } 366 if (node.SubtreeCount == 1) { 367 a = AutoDiff.TermBuilder.Constant(1); 368 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out b)) { 369 term = null; 370 return false; 371 } 372 } else { 373 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out a) || 374 !TryTransformToAutoDiff(node.GetSubtree(1), variables, parameters, variableNames, updateVariableWeights, out b)) { 375 term = null; 376 return false; 377 } 378 } 379 List<AutoDiff.Term> factors = new List<Term>(); 380 foreach (var subTree in node.Subtrees.Skip(2)) { 381 AutoDiff.Term f; 382 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out f)) { 383 term = null; 384 return false; 385 } 386 factors.Add(1.0 / f); 387 } 388 term = AutoDiff.TermBuilder.Product(a, 1.0 / b, factors.ToArray()); 389 return true; 377 390 } 378 391 if (node.Symbol is Logarithm) { … … 405 418 return true; 406 419 } 407 } if (node.Symbol is SquareRoot) { 420 } 421 if (node.Symbol is SquareRoot) { 408 422 AutoDiff.Term t; 409 423 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { … … 414 428 return true; 415 429 } 416 } if (node.Symbol is Sine) { 430 } 431 if (node.Symbol is Sine) { 417 432 AutoDiff.Term t; 418 433 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { … … 423 438 return true; 424 439 } 425 } if (node.Symbol is Cosine) { 440 } 441 if (node.Symbol is Cosine) { 426 442 AutoDiff.Term t; 427 443 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { … … 432 448 return true; 433 449 } 434 } if (node.Symbol is Tangent) { 450 } 451 if (node.Symbol is Tangent) { 435 452 AutoDiff.Term t; 436 453 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { … … 441 458 return true; 442 459 } 443 } if (node.Symbol is Erf) { 460 } 461 if (node.Symbol is Erf) { 444 462 AutoDiff.Term t; 445 463 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { … … 450 468 return true; 451 469 } 452 } if (node.Symbol is Norm) { 470 } 471 if (node.Symbol is Norm) { 453 472 AutoDiff.Term t; 454 473 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {
Note: See TracChangeset
for help on using the changeset viewer.