Changeset 5748
- Timestamp:
- 03/18/11 10:28:08 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs
r5733 r5748 41 41 private const string VariableFrequenciesParameterName = "VariableFrequencies"; 42 42 private const string AggregateLaggedVariablesParameterName = "AggregateLaggedVariables"; 43 private const string VariableImpactsParameterName = "VariableImpacts"; 43 44 44 45 #region parameter properties … … 46 47 get { return (ILookupParameter<DataTable>)Parameters[VariableFrequenciesParameterName]; } 47 48 } 49 public ILookupParameter<DoubleMatrix> VariableImpactsParameter { 50 get { return (ILookupParameter<DoubleMatrix>)Parameters[VariableImpactsParameterName]; } 51 } 48 52 public IValueLookupParameter<BoolValue> AggregateLaggedVariablesParameter { 49 53 get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateLaggedVariablesParameterName]; } … … 51 55 #endregion 52 56 #region properties 53 public DataTable VariableFrequencies {54 get { return VariableFrequenciesParameter.ActualValue; }55 set { VariableFrequenciesParameter.ActualValue = value; }56 }57 57 public BoolValue AggregateLaggedVariables { 58 58 get { return AggregateLaggedVariablesParameter.ActualValue; } 59 set { AggregateLaggedVariablesParameter.Value = value; } 59 60 } 60 61 #endregion … … 67 68 : base() { 68 69 Parameters.Add(new LookupParameter<DataTable>(VariableFrequenciesParameterName, "The relative variable reference frequencies aggregated over all trees in the population.")); 70 Parameters.Add(new LookupParameter<DoubleMatrix>(VariableImpactsParameterName, "The relative variable relevance calculated as the average relative variable frequency over the whole run.")); 69 71 Parameters.Add(new ValueLookupParameter<BoolValue>(AggregateLaggedVariablesParameterName, "Switch that determines whether all references to a variable should be aggregated regardless of time-offsets. Turn off to analyze all variable references with different time offsets separately.", new BoolValue(true))); 70 72 } 73 71 74 public override IDeepCloneable Clone(Cloner cloner) { 72 75 return new SymbolicDataAnalysisVariableFrequencyAnalyzer(this, cloner); 73 76 } 74 75 77 76 78 public override IOperation Apply() { 77 79 ItemArray<ISymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue; 78 80 ResultCollection results = ResultCollection; 79 80 if (VariableFrequencies == null) { 81 VariableFrequencies = new DataTable("Variable frequencies", "Relative frequency of variable references aggregated over the whole population."); 82 VariableFrequencies.VisualProperties.XAxisTitle = "Generation"; 83 VariableFrequencies.VisualProperties.YAxisTitle = "Relative Variable Frequency"; 84 results.Add(new Result("Variable frequencies", VariableFrequencies)); 85 } 86 81 DoubleMatrix impacts; 82 DataTable datatable; 83 if (VariableFrequenciesParameter.ActualValue == null) { 84 datatable = new DataTable("Variable frequencies", "Relative frequency of variable references aggregated over the whole population."); 85 datatable.VisualProperties.XAxisTitle = "Generation"; 86 datatable.VisualProperties.YAxisTitle = "Relative Variable Frequency"; 87 impacts = new DoubleMatrix(); 88 VariableFrequenciesParameter.ActualValue = datatable; 89 VariableImpactsParameter.ActualValue = impacts; 90 results.Add(new Result("Variable frequencies", "Relative frequency of variable references aggregated over the whole population.", datatable)); 91 results.Add(new Result("Variable impacts", "The relative variable relevance calculated as the average relative variable frequency over the whole run.", impacts)); 92 } 93 94 impacts = VariableImpactsParameter.ActualValue; 95 datatable = VariableFrequenciesParameter.ActualValue; 87 96 // all rows must have the same number of values so we can just take the first 88 int numberOfValues = VariableFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();97 int numberOfValues = datatable.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First(); 89 98 90 99 foreach (var pair in SymbolicDataAnalysisVariableFrequencyAnalyzer.CalculateVariableFrequencies(expressions, AggregateLaggedVariables.Value)) { 91 if (! VariableFrequencies.Rows.ContainsKey(pair.Key)) {100 if (!datatable.Rows.ContainsKey(pair.Key)) { 92 101 // initialize a new row for the variable and pad with zeros 93 102 DataRow row = new DataRow(pair.Key, "", Enumerable.Repeat(0.0, numberOfValues)); 94 103 row.VisualProperties.StartIndexZero = true; 95 VariableFrequencies.Rows.Add(row);96 } 97 VariableFrequencies.Rows[pair.Key].Values.Add(pair.Value);104 datatable.Rows.Add(row); 105 } 106 datatable.Rows[pair.Key].Values.Add(pair.Value); 98 107 } 99 108 100 109 // add a zero for each data row that was not modified in the previous loop 101 foreach (var row in VariableFrequencies.Rows.Where(r => r.Values.Count != numberOfValues + 1))110 foreach (var row in datatable.Rows.Where(r => r.Values.Count != numberOfValues + 1)) 102 111 row.Values.Add(0.0); 112 113 // update variable impacts matrix 114 var orderedImpacts = (from row in datatable.Rows 115 select new { Name = row.Name, Impact = datatable.Rows[row.Name].Values.Average() }) 116 .OrderByDescending(p => p.Impact) 117 .ToList(); 118 var matrix = (IStringConvertibleMatrix)impacts; 119 matrix.Rows = orderedImpacts.Count; 120 matrix.RowNames = orderedImpacts.Select(x => x.Name); 121 matrix.Columns = 1; 122 matrix.ColumnNames = new string[] { "Relative variable relevance" }; 123 int i = 0; 124 foreach (var p in orderedImpacts) { 125 matrix.SetValue(p.Impact.ToString(), i++, 0); 126 } 103 127 104 128 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.