Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3802 for trunk/sources


Ignore:
Timestamp:
05/13/10 20:29:01 (15 years ago)
Author:
gkronber
Message:

Minor efficiency improvements for variable frequency analyzer. #938

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/VariableFrequencyAnalyser.cs

    r3659 r3802  
    8787      int totalVariableReferences = 0;
    8888      Dictionary<string, double> variableReferencesSum = new Dictionary<string, double>();
     89      Dictionary<string, double> variableFrequencies = new Dictionary<string, double>();
    8990      foreach (var inputVariable in inputVariables)
    9091        variableReferencesSum[inputVariable] = 0.0;
     
    9899      foreach (string inputVariable in inputVariables) {
    99100        double relFreq = variableReferencesSum[inputVariable] / (double)totalVariableReferences;
    100         yield return new KeyValuePair<string, double>(inputVariable, relFreq);
     101        variableFrequencies.Add(inputVariable, relFreq);
    101102      }
     103      return variableFrequencies;
    102104    }
    103105
     
    107109
    108110    private static IEnumerable<KeyValuePair<string, int>> GetVariableReferenceCount(SymbolicExpressionTree tree, IEnumerable<string> inputVariables) {
     111      Dictionary<string, int> references = new Dictionary<string, int>();
    109112      var groupedFuns = (from node in tree.IterateNodesPrefix().OfType<VariableTreeNode>()
    110                          select node.VariableName).GroupBy(x => x);
     113                         select node.VariableName)
     114                         .GroupBy(x => x)
     115                         .Select(g => new { Key = g.Key, Count = g.Count() })
     116                         .ToArray();
    111117
    112118      foreach (var inputVariable in inputVariables) {
    113119        var matchingFuns = from g in groupedFuns
    114120                           where g.Key == inputVariable
    115                            select g.Count();
    116         if (matchingFuns.Count() == 0) yield return new KeyValuePair<string, int>(inputVariable, 0);
     121                           select g.Count;
     122        if (matchingFuns.Count() == 0)
     123          references.Add(inputVariable, 0);
    117124        else {
    118           yield return new KeyValuePair<string, int>(inputVariable, matchingFuns.Single());
     125          references.Add(inputVariable, matchingFuns.Single());
    119126        }
    120127      }
     128      return references;
    121129    }
    122130  }
Note: See TracChangeset for help on using the changeset viewer.