Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/09/11 10:45:50 (13 years ago)
Author:
gkronber
Message:

#1557 implemented parallel evaluation in analyzers using ParallelEnumerable extension methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs

    r6709 r6728  
    131131
    132132    public static IEnumerable<KeyValuePair<string, double>> CalculateVariableFrequencies(IEnumerable<ISymbolicExpressionTree> trees, bool aggregateLaggedVariables = true) {
    133       Dictionary<string, double> variableFrequencies = new Dictionary<string, double>();
    134       int totalNumberOfSymbols = 0;
    135 
    136       foreach (var tree in trees) {
    137         var variableReferences = GetVariableReferences(tree, aggregateLaggedVariables);
    138         foreach (var pair in variableReferences) {
    139           totalNumberOfSymbols += pair.Value;
    140           if (variableFrequencies.ContainsKey(pair.Key)) {
    141             variableFrequencies[pair.Key] += pair.Value;
    142           } else {
    143             variableFrequencies.Add(pair.Key, pair.Value);
    144           }
    145         }
    146       }
     133
     134      var variableFrequencies = trees
     135        .AsParallel()
     136        .SelectMany(t => GetVariableReferences(t, aggregateLaggedVariables))
     137        .GroupBy(pair => pair.Key, pair => pair.Value)
     138        .ToDictionary(g => g.Key, g => (double)g.Sum());
     139
     140      double totalNumberOfSymbols = variableFrequencies.Values.Sum();
    147141
    148142      foreach (var pair in variableFrequencies)
Note: See TracChangeset for help on using the changeset viewer.