Changeset 14962 for stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators
- Timestamp:
- 05/11/17 13:42:10 (8 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14349,14358
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression merged: 14349,14358
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 merged: 14349,14358
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r14186 r14962 181 181 List<AutoDiff.Variable> parameters = new List<AutoDiff.Variable>(); 182 182 List<string> variableNames = new List<string>(); 183 List<int> lags = new List<int>(); 183 184 184 185 AutoDiff.Term func; 185 if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out func))186 if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out func)) 186 187 throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree."); 187 188 if (variableNames.Count == 0) return 0.0; … … 222 223 foreach (var r in rows) { 223 224 for (int col = 0; col < variableNames.Count; col++) { 224 x[row, col] = ds.GetDoubleValue(variableNames[col], r); 225 int lag = lags[col]; 226 x[row, col] = ds.GetDoubleValue(variableNames[col], r + lag); 225 227 } 226 228 row++; … … 240 242 alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, null, null); 241 243 alglib.lsfitresults(state, out info, out c, out rep); 242 } 243 catch (ArithmeticException) { 244 } catch (ArithmeticException) { 244 245 return originalQuality; 245 } 246 catch (alglib.alglibexception) { 246 } catch (alglib.alglibexception) { 247 247 return originalQuality; 248 248 } … … 286 286 } 287 287 288 private static bool TryTransformToAutoDiff(ISymbolicExpressionTreeNode node, List<AutoDiff.Variable> variables, List<AutoDiff.Variable> parameters, List<string> variableNames, bool updateVariableWeights, out AutoDiff.Term term) {288 private static bool TryTransformToAutoDiff(ISymbolicExpressionTreeNode node, List<AutoDiff.Variable> variables, List<AutoDiff.Variable> parameters, List<string> variableNames, List<int> lags, bool updateVariableWeights, out AutoDiff.Term term) { 289 289 if (node.Symbol is Constant) { 290 290 var var = new AutoDiff.Variable(); … … 298 298 parameters.Add(par); 299 299 variableNames.Add(varNode.VariableName); 300 lags.Add(0); 300 301 301 302 if (updateVariableWeights) { … … 304 305 term = AutoDiff.TermBuilder.Product(w, par); 305 306 } else { 306 term = par; 307 term = varNode.Weight * par; 308 } 309 return true; 310 } 311 if (node.Symbol is LaggedVariable) { 312 var varNode = node as LaggedVariableTreeNode; 313 var par = new AutoDiff.Variable(); 314 parameters.Add(par); 315 variableNames.Add(varNode.VariableName); 316 lags.Add(varNode.Lag); 317 318 if (updateVariableWeights) { 319 var w = new AutoDiff.Variable(); 320 variables.Add(w); 321 term = AutoDiff.TermBuilder.Product(w, par); 322 } else { 323 term = varNode.Weight * par; 307 324 } 308 325 return true; … … 312 329 foreach (var subTree in node.Subtrees) { 313 330 AutoDiff.Term t; 314 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out t)) {331 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 315 332 term = null; 316 333 return false; … … 325 342 for (int i = 0; i < node.SubtreeCount; i++) { 326 343 AutoDiff.Term t; 327 if (!TryTransformToAutoDiff(node.GetSubtree(i), variables, parameters, variableNames, updateVariableWeights, out t)) {344 if (!TryTransformToAutoDiff(node.GetSubtree(i), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 328 345 term = null; 329 346 return false; … … 340 357 foreach (var subTree in node.Subtrees) { 341 358 AutoDiff.Term t; 342 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out t)) {359 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 343 360 term = null; 344 361 return false; … … 355 372 foreach (var subTree in node.Subtrees) { 356 373 AutoDiff.Term t; 357 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out t)) {374 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 358 375 term = null; 359 376 return false; … … 367 384 if (node.Symbol is Logarithm) { 368 385 AutoDiff.Term t; 369 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {386 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 370 387 term = null; 371 388 return false; … … 377 394 if (node.Symbol is Exponential) { 378 395 AutoDiff.Term t; 379 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {396 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 380 397 term = null; 381 398 return false; … … 387 404 if (node.Symbol is Square) { 388 405 AutoDiff.Term t; 389 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {406 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 390 407 term = null; 391 408 return false; … … 397 414 if (node.Symbol is SquareRoot) { 398 415 AutoDiff.Term t; 399 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {416 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 400 417 term = null; 401 418 return false; … … 407 424 if (node.Symbol is Sine) { 408 425 AutoDiff.Term t; 409 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {426 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 410 427 term = null; 411 428 return false; … … 417 434 if (node.Symbol is Cosine) { 418 435 AutoDiff.Term t; 419 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {436 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 420 437 term = null; 421 438 return false; … … 427 444 if (node.Symbol is Tangent) { 428 445 AutoDiff.Term t; 429 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {446 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 430 447 term = null; 431 448 return false; … … 437 454 if (node.Symbol is Erf) { 438 455 AutoDiff.Term t; 439 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {456 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 440 457 term = null; 441 458 return false; … … 447 464 if (node.Symbol is Norm) { 448 465 AutoDiff.Term t; 449 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) {466 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out t)) { 450 467 term = null; 451 468 return false; … … 461 478 variables.Add(alpha); 462 479 AutoDiff.Term branchTerm; 463 if (TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out branchTerm)) {480 if (TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, lags, updateVariableWeights, out branchTerm)) { 464 481 term = branchTerm * alpha + beta; 465 482 return true; … … 478 495 where 479 496 !(n.Symbol is Variable) && 497 !(n.Symbol is LaggedVariable) && 480 498 !(n.Symbol is Constant) && 481 499 !(n.Symbol is Addition) &&
Note: See TracChangeset
for help on using the changeset viewer.