- Timestamp:
- 11/02/18 16:20:33 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisBuildingBlockAnalyzer.cs
r16271 r16272 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 38 39 public sealed class SymbolicDataAnalysisBuildingBlockAnalyzer : SymbolicDataAnalysisAnalyzer { 39 40 private const string BuildingBlocksResultName = "BuildingBlocks"; 41 private const string SolutionUniquenessResultName = "SolutionUniqueness"; 40 42 private const string MinimumSubtreeLengthParameterName = "MinimumSubtreeLength"; 41 43 private const string SimplifyTreesParameterName = "SimplifyTrees"; … … 90 92 [StorableConstructor] 91 93 private SymbolicDataAnalysisBuildingBlockAnalyzer(bool deserializing) : base(deserializing) { } 94 95 private readonly Func<byte[], ulong> hashFunction = HashUtil.JSHash; 92 96 93 97 public override IOperation Apply() { … … 109 113 int totalCount = 0; // total number of examined subtrees 110 114 115 var hashes = new List<ulong>(); 111 116 // count hashes 112 117 foreach (var tree in SymbolicExpressionTree) { 113 118 var hashNodes = tree.Root.GetSubtree(0).GetSubtree(0).MakeNodes(); 114 var simplified = simplify ? hashNodes.Simplify() : hashNodes.Sort(); 119 var simplified = simplify ? hashNodes.Simplify(hashFunction) : hashNodes.Sort(hashFunction); 120 hashes.Add(simplified.Last().CalculatedHashValue); // maybe calculate aggregate hash instead 115 121 116 122 for (int i = 0; i < simplified.Length; i++) { … … 165 171 } 166 172 173 // compute solution uniqueness 174 DataTableHistory dth; 175 var counts = hashes.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()); 176 if (!ResultCollection.ContainsKey(SolutionUniquenessResultName)) { 177 dth = new DataTableHistory(); 178 ResultCollection.Add(new Result(SolutionUniquenessResultName, dth)); 179 } else { 180 dth = (DataTableHistory)ResultCollection[SolutionUniquenessResultName].Value; 181 } 182 183 var ct = new DataTable("Unique Solutions"); 184 var ctr = new DataRow { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Columns } }; 185 ctr.Values.AddRange(hashes.Select(x => (double)counts[x]).OrderByDescending(x => x)); 186 ct.Rows.Add(ctr); 187 dth.Add(ct); 188 189 var max = dth.Max(x => x.Rows.First().Values.Max()); 190 foreach (var table in dth) { 191 table.VisualProperties.YAxisMinimumAuto = false; 192 table.VisualProperties.YAxisMaximumAuto = false; 193 table.VisualProperties.YAxisMinimumFixedValue = 0; 194 table.VisualProperties.YAxisMaximumFixedValue = max; 195 } 196 167 197 return base.Apply(); 168 198 }
Note: See TracChangeset
for help on using the changeset viewer.