Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/08/10 17:47:15 (15 years ago)
Author:
gkronber
Message:

Implemented calculation of variable impacts as integral over relative variable frequencies. #1036

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/BestSymbolicRegressionSolutionAnalyzer.cs

    r3892 r3905  
    3535using HeuristicLab.Problems.DataAnalysis;
    3636using HeuristicLab.Problems.DataAnalysis.Evaluators;
     37using HeuristicLab.Analysis;
    3738
    3839namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
     
    4344    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    4445    private const string BestSolutionInputvariableCountResultName = "Variables used by best solution";
     46    private const string VariableFrequenciesParameterName = "VariableFrequencies";
     47    private const string VariableImpactsResultName = "Integrated variable frequencies";
    4548    private const string BestSolutionParameterName = "BestSolution";
    4649
     
    5558      get { return (ILookupParameter<SymbolicRegressionSolution>)Parameters[BestSolutionParameterName]; }
    5659    }
     60    public ILookupParameter<DataTable> VariableFrequenciesParameter {
     61      get { return (ILookupParameter<DataTable>)Parameters[VariableFrequenciesParameterName]; }
     62    }
    5763    #endregion
    5864    #region properties
     
    6369      get { return SymbolicExpressionTreeParameter.ActualValue; }
    6470    }
     71    public DataTable VariableFrequencies {
     72      get { return VariableFrequenciesParameter.ActualValue; }
     73    }
    6574    #endregion
    6675
     
    6978      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
    7079      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used for the analysis of symbolic expression trees."));
     80      Parameters.Add(new LookupParameter<DataTable>(VariableFrequenciesParameterName, "The variable frequencies table to use for the calculation of variable impacts"));
    7181      Parameters.Add(new LookupParameter<SymbolicRegressionSolution>(BestSolutionParameterName, "The best symbolic regression solution."));
     82    }
     83
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void Initialize() {
     86      if (!Parameters.ContainsKey(VariableFrequenciesParameterName)) {
     87        Parameters.Add(new LookupParameter<DataTable>(VariableFrequenciesParameterName, "The variable frequencies table to use for the calculation of variable impacts"));
     88      }
    7289    }
    7390
     
    89106        if (Results.ContainsKey(BestSolutionInputvariableCountResultName)) {
    90107          Results[BestSolutionInputvariableCountResultName].Value = new IntValue(model.InputVariables.Count());
     108          Results[VariableImpactsResultName].Value = CalculateVariableImpacts();
    91109        } else {
    92110          Results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(model.InputVariables.Count())));
     111          Results.Add(new Result(VariableImpactsResultName, CalculateVariableImpacts()));
    93112        }
    94113      }
    95114      return BestSolutionParameter.ActualValue;
     115    }
     116
     117    private DoubleMatrix CalculateVariableImpacts() {
     118      if (VariableFrequencies != null) {
     119        var impacts = new DoubleMatrix(VariableFrequencies.Rows.Count, 1, new string[] { "Impact" }, VariableFrequencies.Rows.Select(x => x.Name));
     120        int rowIndex = 0;
     121        foreach (var dataRow in VariableFrequencies.Rows) {
     122          string variableName = dataRow.Name;
     123          double integral = 0;
     124          if (dataRow.Values.Count > 1) {
     125            double baseline = dataRow.Values.First();
     126            integral = (from value in dataRow.Values
     127                        select value - baseline)
     128                              .Sum();
     129          }
     130          impacts[rowIndex++, 0] = integral;
     131        }
     132        return impacts;
     133      } else return new DoubleMatrix(1, 1);
    96134    }
    97135
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionVariableFrequencyAnalyzer.cs

    r3774 r3905  
    6060    #endregion
    6161    #region properties
    62     public DataTable VariableImpacts {
     62    public DataTable VariableFrequencies {
    6363      get { return VariableFrequenciesParameter.ActualValue; }
    6464      set { VariableFrequenciesParameter.ActualValue = value; }
     
    8080      ResultCollection results = ResultsParameter.ActualValue;
    8181
    82       if (VariableImpacts == null) {
    83         VariableImpacts = new DataTable("Variable frequencies", "Relative frequency of variable references aggregated over the whole population.");
     82      if (VariableFrequencies == null) {
     83        VariableFrequencies = new DataTable("Variable frequencies", "Relative frequency of variable references aggregated over the whole population.");
    8484        // add a data row for each input variable
    8585        foreach (var inputVariable in inputVariables)
    86           VariableImpacts.Rows.Add(new DataRow(inputVariable));
    87         results.Add(new Result("Variable frequencies", VariableImpacts));
     86          VariableFrequencies.Rows.Add(new DataRow(inputVariable));
     87        results.Add(new Result("Variable frequencies", VariableFrequencies));
    8888      }
    8989      foreach (var pair in VariableFrequencyAnalyser.CalculateVariableFrequencies(expressions, inputVariables)) {
    90         VariableImpacts.Rows[pair.Key].Values.Add(pair.Value);
    91         results["Variable frequencies"].Value = VariableImpacts;
     90        VariableFrequencies.Rows[pair.Key].Values.Add(pair.Value);
     91        results["Variable frequencies"].Value = VariableFrequencies;
    9292      }
    9393
Note: See TracChangeset for help on using the changeset viewer.