Changeset 4125 for trunk/sources/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 08/01/10 18:08:04 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/VariableFrequencyAnalyser.cs
r4068 r4125 84 84 85 85 public static IEnumerable<KeyValuePair<string, double>> CalculateVariableFrequencies(IEnumerable<SymbolicExpressionTree> trees, IEnumerable<string> inputVariables) { 86 int totalVariableReferences = 0;87 86 Dictionary<string, double> variableReferencesSum = new Dictionary<string, double>(); 88 87 Dictionary<string, double> variableFrequencies = new Dictionary<string, double>(); … … 94 93 variableReferencesSum[pair.Key] += pair.Value; 95 94 } 96 totalVariableReferences += GetTotalVariableReferencesCount(tree);97 95 } 96 double totalVariableReferences = variableReferencesSum.Values.Sum(); 98 97 foreach (string inputVariable in inputVariables) { 99 double relFreq = variableReferencesSum[inputVariable] / (double)totalVariableReferences;98 double relFreq = variableReferencesSum[inputVariable] / totalVariableReferences; 100 99 variableFrequencies.Add(inputVariable, relFreq); 101 100 } … … 103 102 } 104 103 105 private static int GetTotalVariableReferencesCount(SymbolicExpressionTree tree) {106 return tree.IterateNodesPrefix().OfType<VariableTreeNode>().Count();107 }108 109 104 private static IEnumerable<KeyValuePair<string, int>> GetVariableReferenceCount(SymbolicExpressionTree tree, IEnumerable<string> inputVariables) { 110 105 Dictionary<string, int> references = new Dictionary<string, int>(); 111 var groupedFuns = (from node in tree.IterateNodesPrefix().OfType<VariableTreeNode>() 112 select node.VariableName) 113 .GroupBy(x => x) 114 .Select(g => new { Key = g.Key, Count = g.Count() }) 115 .ToArray(); 106 var variableNames = from node in tree.IterateNodesPrefix().OfType<VariableTreeNode>() 107 select node.VariableName; 116 108 117 foreach (var inputVariable in inputVariables) { 118 var matchingFuns = from g in groupedFuns 119 where g.Key == inputVariable 120 select g.Count; 121 if (matchingFuns.Count() == 0) 122 references.Add(inputVariable, 0); 123 else { 124 references.Add(inputVariable, matchingFuns.Single()); 109 foreach (var variableName in variableNames) { 110 if (!references.ContainsKey(variableName)) { 111 references[variableName] = 1; 112 } else { 113 references[variableName] += 1; 125 114 } 126 115 }
Note: See TracChangeset
for help on using the changeset viewer.