Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5748


Ignore:
Timestamp:
03/18/11 10:28:08 (14 years ago)
Author:
gkronber
Message:

#1418 added calculation of variable impacts to variable frequency analyzer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs

    r5733 r5748  
    4141    private const string VariableFrequenciesParameterName = "VariableFrequencies";
    4242    private const string AggregateLaggedVariablesParameterName = "AggregateLaggedVariables";
     43    private const string VariableImpactsParameterName = "VariableImpacts";
    4344
    4445    #region parameter properties
     
    4647      get { return (ILookupParameter<DataTable>)Parameters[VariableFrequenciesParameterName]; }
    4748    }
     49    public ILookupParameter<DoubleMatrix> VariableImpactsParameter {
     50      get { return (ILookupParameter<DoubleMatrix>)Parameters[VariableImpactsParameterName]; }
     51    }
    4852    public IValueLookupParameter<BoolValue> AggregateLaggedVariablesParameter {
    4953      get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateLaggedVariablesParameterName]; }
     
    5155    #endregion
    5256    #region properties
    53     public DataTable VariableFrequencies {
    54       get { return VariableFrequenciesParameter.ActualValue; }
    55       set { VariableFrequenciesParameter.ActualValue = value; }
    56     }
    5757    public BoolValue AggregateLaggedVariables {
    5858      get { return AggregateLaggedVariablesParameter.ActualValue; }
     59      set { AggregateLaggedVariablesParameter.Value = value; }
    5960    }
    6061    #endregion
     
    6768      : base() {
    6869      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."));
    6971      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)));
    7072    }
     73
    7174    public override IDeepCloneable Clone(Cloner cloner) {
    7275      return new SymbolicDataAnalysisVariableFrequencyAnalyzer(this, cloner);
    7376    }
    74 
    7577
    7678    public override IOperation Apply() {
    7779      ItemArray<ISymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
    7880      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;
    8796      // 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();
    8998
    9099      foreach (var pair in SymbolicDataAnalysisVariableFrequencyAnalyzer.CalculateVariableFrequencies(expressions, AggregateLaggedVariables.Value)) {
    91         if (!VariableFrequencies.Rows.ContainsKey(pair.Key)) {
     100        if (!datatable.Rows.ContainsKey(pair.Key)) {
    92101          // initialize a new row for the variable and pad with zeros
    93102          DataRow row = new DataRow(pair.Key, "", Enumerable.Repeat(0.0, numberOfValues));
    94103          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);
    98107      }
    99108
    100109      // 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))
    102111        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      }
    103127
    104128      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.