public override IOperation Apply() { ItemArray <ISymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue; ResultCollection results = ResultsParameter.ActualValue; DataTable symbolFrequencies = SymbolFrequenciesParameter.ActualValue; if (symbolFrequencies == null) { symbolFrequencies = new DataTable("Symbol frequencies", "Relative frequency of symbols aggregated over the whole population."); symbolFrequencies.VisualProperties.YAxisTitle = "Relative Symbol Frequency"; SymbolFrequenciesParameter.ActualValue = symbolFrequencies; results.Add(new Result("Symbol frequencies", symbolFrequencies)); } // all rows must have the same number of values so we can just take the first int numberOfValues = symbolFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First(); foreach (var pair in SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(expressions, AggregrateSymbolsWithDifferentSubtreeCount.Value)) { if (!symbolFrequencies.Rows.ContainsKey(pair.Key)) { // initialize a new row for the symbol and pad with zeros DataRow row = new DataRow(pair.Key, "", Enumerable.Repeat(0.0, numberOfValues)); row.VisualProperties.StartIndexZero = true; symbolFrequencies.Rows.Add(row); } symbolFrequencies.Rows[pair.Key].Values.Add(Math.Round(pair.Value, 3)); } // add a zero for each data row that was not modified in the previous loop foreach (var row in symbolFrequencies.Rows.Where(r => r.Values.Count != numberOfValues + 1)) { row.Values.Add(0.0); } return(base.Apply()); }
protected SymbolicExpressionSymbolFrequencyAnalyzer(SymbolicExpressionSymbolFrequencyAnalyzer original, Cloner cloner) : base(original, cloner) { }