- Timestamp:
- 06/08/10 17:47:15 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Analyzers/RegressionSolutionAnalyzer.cs
r3892 r3905 44 44 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; 45 45 private const string BestSolutionQualityParameterName = "BestSolutionQuality"; 46 private const string GenerationsParameterName = "Generations"; 46 47 private const string ResultsParameterName = "Results"; 47 48 private const string BestSolutionResultName = "Best solution (on validiation set)"; … … 52 53 private const string BestSolutionTrainingRelativeError = "Best solution average relative error (training)"; 53 54 private const string BestSolutionTestRelativeError = "Best solution average relative error (test)"; 55 private const string BestSolutionGeneration = "Best solution generation"; 54 56 55 57 #region parameter properties … … 71 73 public ILookupParameter<ResultCollection> ResultsParameter { 72 74 get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; } 75 } 76 public ILookupParameter<IntValue> GenerationsParameter { 77 get { 78 return (ILookupParameter<IntValue>)Parameters[GenerationsParameterName]; 79 } 73 80 } 74 81 #endregion … … 98 105 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the symbolic regression trees which should be analyzed.")); 99 106 Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameterName, "The quality of the best regression solution.")); 107 Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations calculated so far.")); 100 108 Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic regression solution should be stored.")); 109 } 110 111 [StorableHook(HookType.AfterDeserialization)] 112 public void Initialize() { 113 // backwards compatibility 114 if (!Parameters.ContainsKey(GenerationsParameterName)) { 115 Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations calculated so far.")); 116 } 101 117 } 102 118 … … 135 151 Results[BestSolutionTrainingRelativeError].Value = new DoubleValue(trainingRelError); 136 152 Results[BestSolutionTestRelativeError].Value = new DoubleValue(testRelError); 153 Results[BestSolutionGeneration].Value = new IntValue(GenerationsParameter.ActualValue.Value); 137 154 } else { 138 155 Results.Add(new Result(BestSolutionResultName, solution)); … … 143 160 Results.Add(new Result(BestSolutionTrainingRelativeError, new DoubleValue(trainingRelError))); 144 161 Results.Add(new Result(BestSolutionTestRelativeError, new DoubleValue(testRelError))); 162 Results.Add(new Result(BestSolutionGeneration, new IntValue(GenerationsParameter.ActualValue.Value))); 145 163 } 146 164 #endregion -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/BestSymbolicRegressionSolutionAnalyzer.cs
r3892 r3905 35 35 using HeuristicLab.Problems.DataAnalysis; 36 36 using HeuristicLab.Problems.DataAnalysis.Evaluators; 37 using HeuristicLab.Analysis; 37 38 38 39 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers { … … 43 44 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 44 45 private const string BestSolutionInputvariableCountResultName = "Variables used by best solution"; 46 private const string VariableFrequenciesParameterName = "VariableFrequencies"; 47 private const string VariableImpactsResultName = "Integrated variable frequencies"; 45 48 private const string BestSolutionParameterName = "BestSolution"; 46 49 … … 55 58 get { return (ILookupParameter<SymbolicRegressionSolution>)Parameters[BestSolutionParameterName]; } 56 59 } 60 public ILookupParameter<DataTable> VariableFrequenciesParameter { 61 get { return (ILookupParameter<DataTable>)Parameters[VariableFrequenciesParameterName]; } 62 } 57 63 #endregion 58 64 #region properties … … 63 69 get { return SymbolicExpressionTreeParameter.ActualValue; } 64 70 } 71 public DataTable VariableFrequencies { 72 get { return VariableFrequenciesParameter.ActualValue; } 73 } 65 74 #endregion 66 75 … … 69 78 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze.")); 70 79 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")); 71 81 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 } 72 89 } 73 90 … … 89 106 if (Results.ContainsKey(BestSolutionInputvariableCountResultName)) { 90 107 Results[BestSolutionInputvariableCountResultName].Value = new IntValue(model.InputVariables.Count()); 108 Results[VariableImpactsResultName].Value = CalculateVariableImpacts(); 91 109 } else { 92 110 Results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(model.InputVariables.Count()))); 111 Results.Add(new Result(VariableImpactsResultName, CalculateVariableImpacts())); 93 112 } 94 113 } 95 114 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); 96 134 } 97 135 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionVariableFrequencyAnalyzer.cs
r3774 r3905 60 60 #endregion 61 61 #region properties 62 public DataTable Variable Impacts {62 public DataTable VariableFrequencies { 63 63 get { return VariableFrequenciesParameter.ActualValue; } 64 64 set { VariableFrequenciesParameter.ActualValue = value; } … … 80 80 ResultCollection results = ResultsParameter.ActualValue; 81 81 82 if (Variable Impacts == null) {83 Variable Impacts = 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."); 84 84 // add a data row for each input variable 85 85 foreach (var inputVariable in inputVariables) 86 Variable Impacts.Rows.Add(new DataRow(inputVariable));87 results.Add(new Result("Variable frequencies", Variable Impacts));86 VariableFrequencies.Rows.Add(new DataRow(inputVariable)); 87 results.Add(new Result("Variable frequencies", VariableFrequencies)); 88 88 } 89 89 foreach (var pair in VariableFrequencyAnalyser.CalculateVariableFrequencies(expressions, inputVariables)) { 90 Variable Impacts.Rows[pair.Key].Values.Add(pair.Value);91 results["Variable frequencies"].Value = Variable Impacts;90 VariableFrequencies.Rows[pair.Key].Values.Add(pair.Value); 91 results["Variable frequencies"].Value = VariableFrequencies; 92 92 } 93 93
Note: See TracChangeset
for help on using the changeset viewer.