- Timestamp:
- 02/22/18 13:11:40 (7 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
r15800 r15803 11 11 public class Grammar { 12 12 13 public Symbol StartSymbol ;13 public Symbol StartSymbol { get; } 14 14 15 15 #region Symbols 16 17 16 public VariableSymbol Var; 18 17 … … 43 42 #endregion 44 43 45 46 44 #region HL Symbols for Parsing ExpressionTrees 47 48 45 private TypeCoherentExpressionGrammar symbolicExpressionGrammar; 49 46 … … 60 57 private ISymbol rootSy; 61 58 private ISymbol startSy; 62 63 59 #endregion 64 60 … … 90 86 ClosingBracket = new TerminalSymbol(")"); 91 87 #endregion 92 93 88 94 89 #region Production rules … … 179 174 } 180 175 181 var result = uniqueChildHashes.To List();182 result.Sort();183 return result .ToArray();176 var result = uniqueChildHashes.ToArray(); 177 Array.Sort(result); 178 return result; 184 179 } 185 180 … … 266 261 return hashesArray.Aggregate(start, (result, ti) => ((result << 5) + result) ^ ti.GetHashCode()); 267 262 } 268 269 /*270 private void CancelOutCompoundInverse(Stack<Symbol> parseStack) {271 // Resolve compound divisions272 int compoundFractionsCount = 0;273 274 while (ReferenceEquals(parseStack.Peek(), Inv)) {275 compoundFractionsCount++;276 parseStack.Pop();277 }278 279 if (compoundFractionsCount % 2 != 0) {280 // Compound division are reduced to a single division.281 parseStack.Push(Inv);282 } // else: compound divisions fully cancel out each other.283 } */284 263 #endregion 285 264 -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
r15800 r15803 25 25 private readonly string BestTrainingQualityName = "Best R² (Training)"; 26 26 private readonly string BestTrainingSolutionName = "Best solution (Training)"; 27 private readonly string SearchStructureSizeName = "Search Structure Size"; 28 private readonly string GeneratedPhrasesName = "Generated/Archived Phrases"; 27 29 private readonly string GeneratedSentencesName = "Generated Sentences"; 28 30 private readonly string DistinctSentencesName = "Distinct Sentences"; … … 115 117 116 118 using (TextWriterTraceListener dotFileTrace = new TextWriterTraceListener(new FileStream(dotFileName, FileMode.Create))) { 117 dotFileTrace.Write("digraph searchgraph {");119 LogSearchGraph(dotFileTrace, "digraph searchgraph {"); 118 120 119 121 OpenPhrases.Store(phrase0Hash, phrase0); … … 124 126 SymbolString currPhrase = fetchedPhrase.SymbolString; 125 127 126 dotFileTrace.Write( 127 $"{fetchedPhrase.Hash} [label=\"{Grammar.PostfixToInfixParser(fetchedPhrase.SymbolString)}\"];"); 128 LogSearchGraph(dotFileTrace, $"{fetchedPhrase.Hash} [label=\"{Grammar.PostfixToInfixParser(fetchedPhrase.SymbolString)}\"];"); 128 129 129 130 ArchivedPhrases.Add(fetchedPhrase.Hash, currPhrase); … … 142 143 var phraseHash = Grammar.CalcHashCode(newPhrase); 143 144 144 dotFileTrace.Write( 145 $"{fetchedPhrase.Hash} -> {phraseHash} [label=\"{expandedSymbol.StringRepresentation} + → {productionAlternative}\"];"); 145 LogSearchGraph(dotFileTrace, $"{fetchedPhrase.Hash} -> {phraseHash} [label=\"{expandedSymbol.StringRepresentation} + → {productionAlternative}\"];"); 146 146 147 147 if (newPhrase.IsSentence()) { … … 155 155 EvaluateSentence(newPhrase); 156 156 157 dotFileTrace.Write( 158 $"{phraseHash} [label=\"{Grammar.PostfixToInfixParser(newPhrase)}\", style=\"filled\"];"); 157 LogSearchGraph(dotFileTrace, $"{phraseHash} [label=\"{Grammar.PostfixToInfixParser(newPhrase)}\", style=\"filled\"];"); 159 158 } 160 159 UpdateView(AllSentences, DistinctSentences); … … 168 167 169 168 // Overwrite formatting of start search node and best found solution. 170 dotFileTrace.Write( 171 $"{Grammar.CalcHashCode(BestTrainingSentence)} [label=\"{Grammar.PostfixToInfixParser(BestTrainingSentence)}\", shape=Mcircle, style=\"filled,bold\"];"); 172 dotFileTrace.Write($"{phrase0Hash} [label=\"{Grammar.PostfixToInfixParser(phrase0)}\", shape=doublecircle];}}"); 169 LogSearchGraph(dotFileTrace, $"{Grammar.CalcHashCode(BestTrainingSentence)} [label=\"{Grammar.PostfixToInfixParser(BestTrainingSentence)}\", shape=Mcircle, style=\"filled,bold\"];"); 170 LogSearchGraph(dotFileTrace, $"{phrase0Hash} [label=\"{Grammar.PostfixToInfixParser(phrase0)}\", shape=doublecircle];}}"); 173 171 dotFileTrace.Flush(); 174 172 } … … 219 217 Results.Add(new Result(BestTrainingQualityName, new DoubleValue(-1.0))); 220 218 219 Results.Add(new Result(GeneratedPhrasesName, new IntValue(0))); 220 Results.Add(new Result(SearchStructureSizeName, new IntValue(0))); 221 221 Results.Add(new Result(GeneratedSentencesName, new IntValue(0))); 222 222 Results.Add(new Result(DistinctSentencesName, new IntValue(0))); … … 234 234 if (force || updates % GuiUpdateInterval == 0) { 235 235 var allGeneratedEnum = allGenerated.Values.SelectMany(x => x).ToArray(); 236 ((IntValue)Results[GeneratedPhrasesName].Value).Value = ArchivedPhrases.Count; 237 ((IntValue)Results[SearchStructureSizeName].Value).Value = OpenPhrases.Count; 236 238 ((IntValue)Results[GeneratedSentencesName].Value).Value = allGeneratedEnum.Length; 237 239 ((IntValue)Results[DistinctSentencesName].Value).Value = distinctGenerated.Count; … … 277 279 Results.Add(new Result("Distinct generated sentences", new StringMatrix(distinctSentencesMatrix))); 278 280 } 281 282 private void LogSearchGraph(TraceListener listener, String msg) { 283 #if false 284 listener.Write(msg); 285 #endif 286 } 279 287 #endregion 280 288
Note: See TracChangeset
for help on using the changeset viewer.