Changeset 14351 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Timestamp:
- 10/23/16 09:44:29 (8 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650
- Property svn:mergeinfo changed
/trunk/sources merged: 14332,14340-14350
- Property svn:mergeinfo changed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression merged: 14349
- Property svn:mergeinfo changed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 merged: 14349
- Property svn:mergeinfo changed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r14266 r14351 183 183 List<string> variableNames = new List<string>(); 184 184 List<string> categoricalVariableValues = new List<string>(); 185 List<int> lags = new List<int>(); 185 186 186 187 AutoDiff.Term func; 187 if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out func))188 if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out func)) 188 189 throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree."); 189 190 if (variableNames.Count == 0) return 0.0; // gkronber: constant expressions always have a R² of 0.0 … … 235 236 foreach (var r in rows) { 236 237 for (int col = 0; col < variableNames.Count; col++) { 238 int lag = lags[col]; 237 239 if (ds.VariableHasType<double>(variableNames[col])) { 238 x[row, col] = ds.GetDoubleValue(variableNames[col], r );240 x[row, col] = ds.GetDoubleValue(variableNames[col], r + lag); 239 241 } else if (ds.VariableHasType<string>(variableNames[col])) { 240 242 x[row, col] = ds.GetStringValue(variableNames[col], r) == categoricalVariableValues[col] ? 1 : 0; … … 257 259 alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, null, null); 258 260 alglib.lsfitresults(state, out info, out c, out rep); 259 } 260 catch (ArithmeticException) { 261 } catch (ArithmeticException) { 261 262 return originalQuality; 262 } 263 catch (alglib.alglibexception) { 263 } catch (alglib.alglibexception) { 264 264 return originalQuality; 265 265 } … … 312 312 313 313 private static bool TryTransformToAutoDiff(ISymbolicExpressionTreeNode node, List<AutoDiff.Variable> variables, List<AutoDiff.Variable> parameters, 314 List<string> variableNames, List< string> categoricalVariableValues, bool updateVariableWeights, out AutoDiff.Term term) {314 List<string> variableNames, List<int> lags, List<string> categoricalVariableValues, bool updateVariableWeights, out AutoDiff.Term term) { 315 315 if (node.Symbol is Constant) { 316 316 var var = new AutoDiff.Variable(); … … 325 325 var varValue = factorVarNode != null ? factorVarNode.VariableValue : string.Empty; 326 326 var par = FindOrCreateParameter(varNode.VariableName, varValue, parameters, variableNames, categoricalVariableValues); 327 lags.Add(0); 327 328 328 329 if (updateVariableWeights) { … … 349 350 return true; 350 351 } 352 if (node.Symbol is LaggedVariable) { 353 var varNode = node as LaggedVariableTreeNode; 354 var par = new AutoDiff.Variable(); 355 parameters.Add(par); 356 variableNames.Add(varNode.VariableName); 357 lags.Add(varNode.Lag); 358 359 if (updateVariableWeights) { 360 var w = new AutoDiff.Variable(); 361 variables.Add(w); 362 term = AutoDiff.TermBuilder.Product(w, par); 363 } else { 364 term = par; 365 } 366 return true; 367 } 351 368 if (node.Symbol is Addition) { 352 369 List<AutoDiff.Term> terms = new List<Term>(); 353 370 foreach (var subTree in node.Subtrees) { 354 371 AutoDiff.Term t; 355 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {372 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 356 373 term = null; 357 374 return false; … … 366 383 for (int i = 0; i < node.SubtreeCount; i++) { 367 384 AutoDiff.Term t; 368 if (!TryTransformToAutoDiff(node.GetSubtree(i), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {385 if (!TryTransformToAutoDiff(node.GetSubtree(i), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 369 386 term = null; 370 387 return false; … … 381 398 foreach (var subTree in node.Subtrees) { 382 399 AutoDiff.Term t; 383 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {400 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 384 401 term = null; 385 402 return false; … … 396 413 foreach (var subTree in node.Subtrees) { 397 414 AutoDiff.Term t; 398 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {415 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 399 416 term = null; 400 417 return false; … … 408 425 if (node.Symbol is Logarithm) { 409 426 AutoDiff.Term t; 410 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {427 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 411 428 term = null; 412 429 return false; … … 418 435 if (node.Symbol is Exponential) { 419 436 AutoDiff.Term t; 420 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {437 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 421 438 term = null; 422 439 return false; … … 428 445 if (node.Symbol is Square) { 429 446 AutoDiff.Term t; 430 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {447 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 431 448 term = null; 432 449 return false; … … 438 455 if (node.Symbol is SquareRoot) { 439 456 AutoDiff.Term t; 440 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {457 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 441 458 term = null; 442 459 return false; … … 448 465 if (node.Symbol is Sine) { 449 466 AutoDiff.Term t; 450 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {467 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 451 468 term = null; 452 469 return false; … … 458 475 if (node.Symbol is Cosine) { 459 476 AutoDiff.Term t; 460 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {477 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 461 478 term = null; 462 479 return false; … … 468 485 if (node.Symbol is Tangent) { 469 486 AutoDiff.Term t; 470 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {487 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 471 488 term = null; 472 489 return false; … … 478 495 if (node.Symbol is Erf) { 479 496 AutoDiff.Term t; 480 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {497 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 481 498 term = null; 482 499 return false; … … 488 505 if (node.Symbol is Norm) { 489 506 AutoDiff.Term t; 490 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out t)) {507 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out t)) { 491 508 term = null; 492 509 return false; … … 502 519 variables.Add(alpha); 503 520 AutoDiff.Term branchTerm; 504 if (TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, categoricalVariableValues, updateVariableWeights, out branchTerm)) {521 if (TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, categoricalVariableValues, updateVariableWeights, out branchTerm)) { 505 522 term = branchTerm * alpha + beta; 506 523 return true; … … 547 564 !(n.Symbol is BinaryFactorVariable) && 548 565 !(n.Symbol is FactorVariable) && 566 !(n.Symbol is LaggedVariable) && 549 567 !(n.Symbol is Constant) && 550 568 !(n.Symbol is Addition) &&
Note: See TracChangeset
for help on using the changeset viewer.