- Timestamp:
- 05/09/12 17:29:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Analyzers/SymbolicExpressionTreeFragmentsAnalyzer.cs
r7785 r7788 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; 25 using System.Text;26 24 using HeuristicLab.Analysis; 27 25 using HeuristicLab.Common; … … 33 31 using HeuristicLab.Parameters; 34 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 35 using HeuristicLab.Problems.DataAnalysis;36 using HeuristicLab.Problems.DataAnalysis.Symbolic;37 33 // type definitions for ease of use 38 34 using CloneMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItem>; … … 52 48 private const string GlobalTraceMapParameterName = "GlobalTraceMap"; 53 49 private const string GlobalCloneMapParameterName = "GlobalCloneMap"; 50 private const string GlobalFragmentMapParameterName = "GlobalFragmentMap"; 54 51 private const string GenerationsParameterName = "Generations"; 55 52 private const string FragmentStatisticsParameterName = "FragmentStatistics"; … … 71 68 get { return (LookupParameter<CloneMapType>)Parameters[GlobalCloneMapParameterName]; } 72 69 } 70 public LookupParameter<CloneMapType> GlobalFragmentMapParameter { 71 get { return (LookupParameter<CloneMapType>)Parameters[GlobalFragmentMapParameterName]; } 72 } 73 73 public LookupParameter<IntValue> GenerationsParameter { 74 74 get { return (LookupParameter<IntValue>)Parameters[GenerationsParameterName]; } … … 76 76 public LookupParameter<DataTable> FragmentStatisticsParameter { 77 77 get { return (LookupParameter<DataTable>)Parameters[FragmentStatisticsParameterName]; } 78 79 78 } 80 79 #endregion … … 98 97 public TraceMapType GlobalTraceMap { 99 98 get { return GlobalTraceMapParameter.ActualValue; } 99 } 100 public CloneMapType GlobalFragmentMap { 101 get { return GlobalFragmentMapParameter.ActualValue; } 100 102 } 101 103 public IntValue Generations { … … 123 125 Parameters.Add(new LookupParameter<TraceMapType>(GlobalTraceMapParameterName, "A global cache containing the whole genealogy.")); 124 126 Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName, "A global map keeping track of trees and their clones (made during selection).")); 127 Parameters.Add(new LookupParameter<CloneMapType>(GlobalFragmentMapParameterName, "A global map keeping track of tree fragments received via crossover.")); 125 128 Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored.")); 126 129 Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations so far.")); … … 159 162 ResultCollection results = ResultsParameter.ActualValue; 160 163 if (FragmentStatistics == null) { 161 FragmentStatisticsParameter.ActualValue = new DataTable("Fragment Statistics", "Statistical measurements of fragments aggregated over the whole population"); 164 FragmentStatisticsParameter.ActualValue = new DataTable("Fragment Statistics", 165 "Statistical measurements of fragments aggregated over the whole population"); 162 166 FragmentStatistics.VisualProperties.YAxisTitle = "Fragment length/Similarities"; 163 167 results.Add(new Result("Fragment Statistics", FragmentStatistics)); 164 168 } 165 166 int numberOfValues = FragmentStatistics.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();167 169 168 170 UpdateCounter.Value = 0; // reset counter … … 171 173 172 174 #region Fragment Statistics 173 // write these to file for now, later we will use a DataTable and display the results inside HeuristicLab174 var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);175 //using (var file = System.IO.File.AppendText(path + @"\tracking.csv")) {176 175 var fragments = new List<ISymbolicExpressionTreeNode>(); 177 176 var parents = new List<ISymbolicExpressionTree>(); 178 double best = gScope.SubScopes.Select(x => x.Variables["Quality"].Value as DoubleValue).Max(x => x.Value);179 177 var trees = (from s in gScope.SubScopes select s.Variables.First().Value as ISymbolicExpressionTree).ToList(); 180 178 foreach (var tree in trees.Where(x => GlobalTraceMap.ContainsKey(x))) { 181 var parent0 = (ISymbolicExpressionTree)GlobalTraceMap[tree][0]; 182 var fragment = SymbolicExpressionTreeMatching.GetFragmentDiff(parent0, tree); 183 if (fragment != null) { 184 parents.Add(parent0); 185 fragments.Add(fragment); 186 if (GlobalTraceMap.ContainsKey(parent0)) { 187 var p = (ISymbolicExpressionTree)GlobalTraceMap[parent0][0]; 188 fragment = SymbolicExpressionTreeMatching.GetFragmentDiff(p, parent0); 189 if (fragment != null) { 190 parents.Add(p); 191 fragments.Add(fragment); 179 if (GlobalTraceMap[tree].Count == 2) { 180 var fragment = tree.IterateNodes().ElementAt(((IntValue)GlobalFragmentMap[tree]).Value); 181 if (fragment != null) { 182 parents.AddRange(GlobalTraceMap[tree].Cast<ISymbolicExpressionTree>()); 183 fragments.Add(fragment); 184 } else { // "intermediate crossovers" (immediately followed by mutation) 185 var parent0 = (ISymbolicExpressionTree)GlobalTraceMap[tree][0]; 186 if (GlobalTraceMap.ContainsKey(parent0)) { 187 var p = (ISymbolicExpressionTree)GlobalTraceMap[parent0][0]; 188 fragment = parent0.IterateNodes().ElementAt(((IntValue)GlobalFragmentMap[parent0]).Value); 189 if (fragment != null) { 190 parents.AddRange(GlobalTraceMap[parent0].Cast<ISymbolicExpressionTree>()); 191 fragments.Add(fragment); 192 } 192 193 } 193 194 } … … 200 201 double a3 = parents.Average(x => x.Length); 201 202 double s1 = CalculateSimilarity(fragments, (int)SymbolicExpressionTreeMatching.SimilarityLevel.Exact); 202 double s2 = CalculateSimilarity(fragments, (int)SymbolicExpressionTreeMatching.SimilarityLevel.High);203 double s3 = CalculateSimilarity(fragments, (int)SymbolicExpressionTreeMatching.SimilarityLevel.Relaxed);203 //double s2 = CalculateSimilarity(fragments, (int)SymbolicExpressionTreeMatching.SimilarityLevel.High); 204 //double s3 = CalculateSimilarity(fragments, (int)SymbolicExpressionTreeMatching.SimilarityLevel.Relaxed); 204 205 205 206 #region Table data … … 232 233 } 233 234 FragmentStatistics.Rows["Similarity (exact)"].Values.Add(s1); 234 // exact similarity 235 if (!FragmentStatistics.Rows.ContainsKey("Similarity (high)")) { 236 DataRow row = new DataRow("Similarity (high)", ""); 237 row.VisualProperties.StartIndexZero = true; 238 FragmentStatistics.Rows.Add(row); 239 } 240 FragmentStatistics.Rows["Similarity (high)"].Values.Add(s2); 241 // exact similarity 242 if (!FragmentStatistics.Rows.ContainsKey("Similarity (relaxed)")) { 243 DataRow row = new DataRow("Similarity (relaxed)", ""); 244 row.VisualProperties.StartIndexZero = true; 245 FragmentStatistics.Rows.Add(row); 246 } 247 FragmentStatistics.Rows["Similarity (relaxed)"].Values.Add(s3); 248 249 //file.WriteLine(best * 10.0 + " " + a1 + " " + a2 + " " + a3 + " " + s1 + " " + s2 + " " + s3); 235 // high similarity 236 //if (!FragmentStatistics.Rows.ContainsKey("Similarity (high)")) { 237 // DataRow row = new DataRow("Similarity (high)", ""); 238 // row.VisualProperties.StartIndexZero = true; 239 // FragmentStatistics.Rows.Add(row); 250 240 //} 241 //FragmentStatistics.Rows["Similarity (high)"].Values.Add(s2); 242 //// relaxed similarity 243 //if (!FragmentStatistics.Rows.ContainsKey("Similarity (relaxed)")) { 244 // DataRow row = new DataRow("Similarity (relaxed)", ""); 245 // row.VisualProperties.StartIndexZero = true; 246 // FragmentStatistics.Rows.Add(row); 247 //} 248 //FragmentStatistics.Rows["Similarity (relaxed)"].Values.Add(s3); 251 249 #endregion 250 252 251 #endregion 252 253 253 // clear the global maps to save memory 254 254 GlobalCloneMap.Clear(); 255 255 GlobalTraceMap.Clear(); 256 GlobalFragmentMap.Clear(); 256 257 } 257 258 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.