Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5392


Ignore:
Timestamp:
01/28/11 13:10:29 (14 years ago)
Author:
gkronber
Message:

#1398 fixed a bug in SymbolicExpressionSymbolFrequencyAnalyzer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs

    r5387 r5392  
    8383      }
    8484
     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
    8588      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));
    9392          row.VisualProperties.StartIndexZero = true;
    9493          SymbolFrequencies.Rows.Add(row);
    9594        }
     95        SymbolFrequencies.Rows[pair.Key].Values.Add(pair.Value);
    9696      }
    9797
    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))
    100100        row.Values.Add(0.0);
    101101
     
    115115      }
    116116
    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);
    120119    }
    121120  }
Note: See TracChangeset for help on using the changeset viewer.