Changeset 3802 for trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/VariableFrequencyAnalyser.cs
- Timestamp:
- 05/13/10 20:29:01 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/VariableFrequencyAnalyser.cs
r3659 r3802 87 87 int totalVariableReferences = 0; 88 88 Dictionary<string, double> variableReferencesSum = new Dictionary<string, double>(); 89 Dictionary<string, double> variableFrequencies = new Dictionary<string, double>(); 89 90 foreach (var inputVariable in inputVariables) 90 91 variableReferencesSum[inputVariable] = 0.0; … … 98 99 foreach (string inputVariable in inputVariables) { 99 100 double relFreq = variableReferencesSum[inputVariable] / (double)totalVariableReferences; 100 yield return new KeyValuePair<string, double>(inputVariable, relFreq);101 variableFrequencies.Add(inputVariable, relFreq); 101 102 } 103 return variableFrequencies; 102 104 } 103 105 … … 107 109 108 110 private static IEnumerable<KeyValuePair<string, int>> GetVariableReferenceCount(SymbolicExpressionTree tree, IEnumerable<string> inputVariables) { 111 Dictionary<string, int> references = new Dictionary<string, int>(); 109 112 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(); 111 117 112 118 foreach (var inputVariable in inputVariables) { 113 119 var matchingFuns = from g in groupedFuns 114 120 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); 117 124 else { 118 yield return new KeyValuePair<string, int>(inputVariable, matchingFuns.Single());125 references.Add(inputVariable, matchingFuns.Single()); 119 126 } 120 127 } 128 return references; 121 129 } 122 130 }
Note: See TracChangeset
for help on using the changeset viewer.