Changeset 15960 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
- Timestamp:
- 06/15/18 14:53:46 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
r15957 r15960 37 37 private readonly string GrammarSymbolsParameterName = "Grammar Symbols"; 38 38 39 public override bool SupportsPause { get { return false; } }39 public override bool SupportsPause { get { return true; } } 40 40 41 41 protected IValueParameter<DoubleValue> VariableImportanceWeightParameter { … … 107 107 #endregion 108 108 109 [Storable] 109 110 public Dictionary<int, int> DistinctSentencesComplexity { get; private set; } // Semantically distinct sentences and their length in a run. 111 112 [Storable] 110 113 public HashSet<int> ArchivedPhrases { get; private set; } 114 115 [Storable] 111 116 internal SearchDataStore OpenPhrases { get; private set; } // Stack/Queue/etc. for fetching the next node in the search tree. 112 117 … … 121 126 122 127 public Grammar Grammar { get; private set; } 123 124 128 125 129 #region ctors … … 174 178 analyzer.Register(this); 175 179 Analyzers.CheckedItemsChanged += Analyzers_CheckedItemsChanged; 180 181 DistinctSentencesComplexity = new Dictionary<int, int>(original.DistinctSentencesComplexity); 182 ArchivedPhrases = new HashSet<int>(original.ArchivedPhrases); 183 OpenPhrases = cloner.Clone(original.OpenPhrases); 184 185 AllGeneratedSentencesCount = original.AllGeneratedSentencesCount; 186 OverwrittenSentencesCount = original.OverwrittenSentencesCount; 187 PhraseExpansionCount = original.PhraseExpansionCount; 188 Grammar = cloner.Clone(original.Grammar); 189 190 if (original.variableImportance != null) 191 variableImportance = new Dictionary<VariableTerminalSymbol, double>(original.variableImportance); 176 192 } 177 193 #endregion … … 193 209 } 194 210 195 protected override void Run(CancellationToken cancellationToken) { 196 InitResults(); 197 var phrase0 = new SymbolString(new[] { Grammar.StartSymbol }); 198 var phrase0Hash = Grammar.Hasher.CalcHashCode(phrase0); 199 200 #region Variable Importance 211 private Dictionary<VariableTerminalSymbol, double> CalculateVariableImportances() { 201 212 variableImportance = new Dictionary<VariableTerminalSymbol, double>(); 202 213 … … 216 227 variableImportance[varSym] = rfImpact.Item2 / sum; 217 228 } 218 #endregion 229 return variableImportance; 230 } 231 232 protected override void Run(CancellationToken cancellationToken) { 233 // do not reinitialize the algorithm if we're resuming from pause 234 if (previousExecutionState != ExecutionState.Paused) { 235 CalculateVariableImportances(); 236 InitResults(); 237 var phrase0 = new SymbolString(new[] { Grammar.StartSymbol }); 238 var phrase0Hash = Grammar.Hasher.CalcHashCode(phrase0); 239 OpenPhrases.Store(new SearchNode(phrase0Hash, 0.0, 0.0, phrase0)); 240 } 219 241 220 242 int maxSentenceLength = GetMaxSentenceLength(); 221 222 OpenPhrases.Store(new SearchNode(phrase0Hash, 0.0, 0.0, phrase0));223 224 243 var errorWeight = ErrorWeight; 225 244 var variableImportanceWeight = VariableImportanceWeight; 226 245 // main search loop 227 246 while (OpenPhrases.Count > 0) { 228 if (cancellationToken.IsCancellationRequested) break; 247 if (cancellationToken.IsCancellationRequested) 248 break; 229 249 230 250 SearchNode fetchedSearchNode = OpenPhrases.GetNext(); … … 343 363 return p.Count(s => s is NonterminalSymbol); 344 364 } 365 366 #region pause support 367 private ExecutionState previousExecutionState; 368 protected override void OnPaused() { 369 previousExecutionState = this.ExecutionState; 370 base.OnPaused(); 371 } 372 protected override void OnPrepared() { 373 previousExecutionState = this.ExecutionState; 374 base.OnPrepared(); 375 } 376 protected override void OnStarted() { 377 previousExecutionState = this.ExecutionState; 378 base.OnStarted(); 379 } 380 protected override void OnStopped() { 381 previousExecutionState = this.ExecutionState; 382 base.OnStopped(); 383 } 384 #endregion 345 385 346 386 #region Visualization in HL
Note: See TracChangeset
for help on using the changeset viewer.