Changeset 15824 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration
- Timestamp:
- 02/28/18 19:09:34 (7 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration
-
Property
svn:ignore
set to
Plugin.cs
-
Property
svn:ignore
set to
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/GrammarEnumerationAlgorithm.cs
r15821 r15824 8 8 using HeuristicLab.Core; 9 9 using HeuristicLab.Data; 10 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;11 10 using HeuristicLab.Optimization; 12 11 using HeuristicLab.Parameters; 13 12 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 14 13 using HeuristicLab.Problems.DataAnalysis; 15 using HeuristicLab.Problems.DataAnalysis.Symbolic;16 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;17 14 18 15 namespace HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration { … … 22 19 public class GrammarEnumerationAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 23 20 #region properties and result names 24 private readonly string BestTrainingQualityName = "Best R² (Training)";25 private readonly string BestTrainingSolutionName = "Best solution (Training)";26 21 private readonly string SearchStructureSizeName = "Search Structure Size"; 27 22 private readonly string GeneratedPhrasesName = "Generated/Archived Phrases"; … … 32 27 private readonly string OverwrittenSentencesName = "Sentences overwritten"; 33 28 private readonly string AnalyzersParameterName = "Analyzers"; 29 private readonly string ExpansionsPerSecondName = "Expansions per second"; 34 30 35 31 … … 72 68 } 73 69 74 public SymbolString BestTrainingSentence; 75 70 public SymbolString BestTrainingSentence { get; set; } // Currently set in RSquaredEvaluator: quite hacky, but makes testing much easier for now... 76 71 #endregion 77 72 … … 91 86 public Grammar Grammar { get; private set; } 92 87 93 private readonly ISymbolicDataAnalysisExpressionTreeInterpreter expressionTreeLinearInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();94 88 95 89 #region ctors … … 109 103 var availableAnalyzers = new IGrammarEnumerationAnalyzer[] { 110 104 new SearchGraphVisualizer(), 111 new SentenceLogger() 105 new SentenceLogger(), 106 new RSquaredEvaluator() 112 107 }; 113 108 Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemCollection<IGrammarEnumerationAnalyzer>>( … … 119 114 } 120 115 Analyzers.CheckedItemsChanged += AnalyzersOnCheckedItemsChanged; 116 Analyzers.SetItemCheckedState(Analyzers.First(analyzer => analyzer is RSquaredEvaluator), true); 121 117 } 122 118 … … 179 175 180 176 DistinctSentencesLength[phraseHash] = newPhrase.Count; 181 EvaluateSentence(newPhrase);182 183 177 OnDistinctSentenceGenerated(fetchedPhrase.Hash, fetchedPhrase.SymbolString, phraseHash, newPhrase, expandedSymbol, productionAlternative); 184 178 } … … 191 185 } 192 186 } 193 194 187 UpdateView(force: true); 195 UpdateFinalResults(); 196 } 197 198 #region Evaluation of generated models. 199 200 // Evaluate sentence within an algorithm run. 201 private void EvaluateSentence(SymbolString symbolString) { 202 SymbolicExpressionTree tree = Grammar.ParseSymbolicExpressionTree(symbolString); 203 SymbolicRegressionModel model = new SymbolicRegressionModel( 204 Problem.ProblemData.TargetVariable, 205 tree, 206 expressionTreeLinearInterpreter); 207 208 var probData = Problem.ProblemData; 209 var target = probData.TargetVariableTrainingValues; 210 var estVals = model.GetEstimatedValues(probData.Dataset, probData.TrainingIndices); 211 OnlineCalculatorError error; 212 var r2 = OnlinePearsonsRSquaredCalculator.Calculate(target, estVals, out error); 213 if (error != OnlineCalculatorError.None) r2 = 0.0; 214 215 var bestR2 = ((DoubleValue)Results[BestTrainingQualityName].Value).Value; 216 if (r2 > bestR2) { 217 ((DoubleValue)Results[BestTrainingQualityName].Value).Value = r2; 218 BestTrainingSentence = symbolString; 219 } 220 } 221 222 #endregion 188 } 223 189 224 190 #region Visualization in HL 225 191 // Initialize entries in result set. 226 192 private void InitResults() { 227 BestTrainingSentence = null;228 229 Results.Add(new Result(BestTrainingQualityName, new DoubleValue(-1.0)));230 231 193 Results.Add(new Result(GeneratedPhrasesName, new IntValue(0))); 232 194 Results.Add(new Result(SearchStructureSizeName, new IntValue(0))); … … 236 198 Results.Add(new Result(OverwrittenSentencesName, new IntValue(0))); 237 199 Results.Add(new Result(AverageSentenceLengthName, new DoubleValue(1.0))); 200 Results.Add(new Result(ExpansionsPerSecondName, "In Thousand expansions per second", new IntValue(0))); 238 201 } 239 202 … … 251 214 ((DoubleValue)Results[AverageSentenceLengthName].Value).Value = DistinctSentencesLength.Select(pair => pair.Value).Average(); 252 215 ((IntValue)Results[OverwrittenSentencesName].Value).Value = OverwrittenSentencesCount; 253 } 254 } 255 256 // Generate all Results after an algorithm run. 257 private void UpdateFinalResults() { 258 SymbolicExpressionTree tree = Grammar.ParseSymbolicExpressionTree(BestTrainingSentence); 259 SymbolicRegressionModel model = new SymbolicRegressionModel( 260 Problem.ProblemData.TargetVariable, 261 tree, 262 new SymbolicDataAnalysisExpressionTreeLinearInterpreter()); 263 264 IRegressionSolution bestTrainingSolution = new RegressionSolution(model, Problem.ProblemData); 265 Results.AddOrUpdateResult(BestTrainingSolutionName, bestTrainingSolution); 216 ((IntValue)Results[ExpansionsPerSecondName].Value).Value = (int)((PhraseExpansionCount / 217 ExecutionTime.TotalSeconds) / 1000.0); 218 } 266 219 } 267 220 #endregion -
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.csproj
r15823 r15824 49 49 <Reference Include="HeuristicLab.Common-3.3"> 50 50 <HintPath>..\..\..\trunk\bin\HeuristicLab.Common-3.3.dll</HintPath> 51 51 <Private>False</Private> 52 52 </Reference> 53 53 <Reference Include="HeuristicLab.Core-3.3"> 54 54 <HintPath>..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath> 55 55 <Private>False</Private> 56 56 </Reference> 57 57 <Reference Include="HeuristicLab.Data-3.3"> 58 58 <HintPath>..\..\..\trunk\bin\HeuristicLab.Data-3.3.dll</HintPath> 59 59 <Private>False</Private> 60 60 </Reference> 61 61 <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4"> 62 62 <HintPath>..\..\..\trunk\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath> 63 63 <Private>False</Private> 64 64 </Reference> 65 65 <Reference Include="HeuristicLab.Operators-3.3"> 66 66 <HintPath>..\..\..\trunk\bin\HeuristicLab.Operators-3.3.dll</HintPath> 67 67 <Private>False</Private> 68 68 </Reference> 69 69 <Reference Include="HeuristicLab.Optimization-3.3"> 70 70 <HintPath>..\..\..\trunk\bin\HeuristicLab.Optimization-3.3.dll</HintPath> 71 71 <Private>False</Private> 72 72 </Reference> 73 73 <Reference Include="HeuristicLab.Parameters-3.3"> 74 74 <HintPath>..\..\..\trunk\bin\HeuristicLab.Parameters-3.3.dll</HintPath> 75 75 <Private>False</Private> 76 76 </Reference> 77 77 <Reference Include="HeuristicLab.Persistence-3.3"> 78 78 <HintPath>..\..\..\trunk\bin\HeuristicLab.Persistence-3.3.dll</HintPath> 79 79 <Private>False</Private> 80 80 </Reference> 81 81 <Reference Include="HeuristicLab.PluginInfrastructure-3.3"> 82 82 <HintPath>..\..\..\trunk\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 83 83 <Private>False</Private> 84 84 </Reference> 85 85 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4"> 86 86 <HintPath>..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath> 87 87 <Private>False</Private> 88 88 </Reference> 89 89 <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4"> 90 90 <HintPath>..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll</HintPath> 91 91 <Private>False</Private> 92 92 </Reference> 93 93 <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4"> 94 94 <HintPath>..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll</HintPath> 95 95 <Private>False</Private> 96 96 </Reference> 97 97 <Reference Include="HeuristicLab.Problems.Instances-3.3"> 98 98 <HintPath>..\..\..\trunk\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath> 99 99 <Private>False</Private> 100 100 </Reference> 101 101 <Reference Include="HeuristicLab.Random-3.3"> 102 102 <HintPath>..\..\..\trunk\bin\HeuristicLab.Random-3.3.dll</HintPath> 103 103 <Private>False</Private> 104 104 </Reference> 105 105 <Reference Include="HeuristicLab.Problems.Instances.DataAnalysis-3.3"> 106 106 <HintPath>..\..\..\trunk\bin\HeuristicLab.Problems.Instances.DataAnalysis-3.3.dll</HintPath> 107 107 <Private>False</Private> 108 108 </Reference> 109 109 <Reference Include="System" /> … … 111 111 <ItemGroup> 112 112 <Compile Include="Analysis\IGrammarEnumerationAnalyzer.cs" /> 113 <Compile Include="Analysis\RSquaredEvaluator.cs" /> 113 114 <Compile Include="Analysis\SentenceLogger.cs" /> 114 115 <Compile Include="Analysis\SearchGraphVisualizer.cs" /> … … 119 120 <Compile Include="Properties\AssemblyInfo.cs" /> 120 121 <Compile Include="GrammarEnumeration\Symbol.cs" /> 122 <Compile Include="Plugin.cs" /> 121 123 </ItemGroup> 122 124 <ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.