- Timestamp:
- 01/28/11 13:10:29 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs
r5387 r5392 83 83 } 84 84 85 // all rows must have the same number of values so we can just take the first 86 int numberOfValues = SymbolFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First(); 87 85 88 foreach (var pair in SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(expressions)) { 86 if (SymbolFrequencies.Rows.ContainsKey(pair.Key)) 87 SymbolFrequencies.Rows[pair.Key].Values.Add(pair.Value); 88 else { 89 int missingValues = SymbolFrequencies.Rows.Select(r => r.Values.Count()-1).DefaultIfEmpty().Max(); 90 List<double> values = new List<double>(Enumerable.Repeat(0.0, missingValues)); 91 values.Add(pair.Value); 92 DataRow row = new DataRow(pair.Key, "", values); 89 if (!SymbolFrequencies.Rows.ContainsKey(pair.Key)) { 90 // initialize a new row for the symbol and pad with zeros 91 DataRow row = new DataRow(pair.Key, "", Enumerable.Repeat(0.0, numberOfValues)); 93 92 row.VisualProperties.StartIndexZero = true; 94 93 SymbolFrequencies.Rows.Add(row); 95 94 } 95 SymbolFrequencies.Rows[pair.Key].Values.Add(pair.Value); 96 96 } 97 97 98 int maxValues = SymbolFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().Max();99 foreach (var row in SymbolFrequencies.Rows.Where(r => r.Values.Count != maxValues))98 // add a zero for each data row that was not modified in the previous loop 99 foreach (var row in SymbolFrequencies.Rows.Where(r => r.Values.Count != numberOfValues + 1)) 100 100 row.Values.Add(0.0); 101 101 … … 115 115 } 116 116 117 foreach (string symbolName in symbolFrequencies.Keys.ToList()) 118 symbolFrequencies[symbolName] /= totalNumberOfSymbols; 119 return symbolFrequencies; 117 foreach (var pair in symbolFrequencies) 118 yield return new KeyValuePair<string, double>(pair.Key, pair.Value / totalNumberOfSymbols); 120 119 } 121 120 }
Note: See TracChangeset
for help on using the changeset viewer.