Changeset 15987 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration
- Timestamp:
- 07/05/18 17:52:31 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
r15979 r15987 374 374 } else if (!OpenPhrases.Contains(phraseHash) && !ArchivedPhrases.Contains(phraseHash)) { 375 375 376 double r2 = GetR2(newPhrase, fetchedSearchNode.R2); 376 bool isCompleteSentence = IsCompleteSentence(newPhrase); 377 double r2 = isCompleteSentence ? Grammar.EvaluatePhrase(newPhrase, Problem.ProblemData, OptimizeConstants) : fetchedSearchNode.R2; 377 378 double phrasePriority = GetPriority(newPhrase, r2, maxSentenceLength, errorWeight, variableImportanceWeight); 378 379 … … 396 397 double relLength = (double)phrase.Count() / maxSentenceLength; 397 398 double error = 1.0 - r2; 398 399 return relLength + errorWeight * error + variableImportanceWeight * phraseVariableImportance; 400 } 401 402 private double GetR2(SymbolString phrase, double parentR2) { 403 int length = phrase.Count(); 404 405 // If the only nonterminal symbol is Expr, we can need to evaluate the sentence. Otherwise 406 // the phrase has the same r2 as its parent, from which it was derived. 407 for (int i = 0; i < length; i++) { 408 if (phrase[i] is NonterminalSymbol && phrase[i] != Grammar.Expr) { 409 return parentR2; 410 } 411 } 412 413 return Grammar.EvaluatePhrase(phrase, Problem.ProblemData, OptimizeConstants); 399 return error * relLength; 400 } 401 402 private bool IsCompleteSentence(SymbolString phrase) { 403 return !phrase.Any(x => x is NonterminalSymbol && x != Grammar.Expr); 414 404 } 415 405 … … 461 451 protected override void OnStopped() { 462 452 previousExecutionState = this.ExecutionState; 463 464 if (BestTrainingSentence == null) {465 base.OnStopped();466 return;467 }468 469 453 // free memory at the end of the run (this saves a lot of memory) 470 454 ArchivedPhrases.Clear(); 471 455 OpenPhrases.Clear(); 472 456 DistinctSentencesComplexity.Clear(); 457 458 if (BestTrainingSentence == null) { 459 base.OnStopped(); 460 return; 461 } 473 462 474 463 var tree = Grammar.ParseSymbolicExpressionTree(BestTrainingSentence);
Note: See TracChangeset
for help on using the changeset viewer.