- Timestamp:
- 05/07/10 21:10:46 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj
r3702 r3710 87 87 <Compile Include="Properties\AssemblyInfo.cs" /> 88 88 <Compile Include="Symbolic\Analyzers\BestSymbolicRegressionSolutionAnalyzer.cs" /> 89 <Compile Include="Symbolic\Analyzers\SymbolicRegressionMeanSquaredErrorCalculator.cs" />90 89 <Compile Include="Symbolic\Analyzers\ISymbolicRegressionAnalyzer.cs" /> 91 90 <Compile Include="Symbolic\Analyzers\SymbolicRegressionModelQualityAnalyzer.cs" /> 92 <Compile Include="Symbolic\Analyzers\SymbolicRegressionModelQualityCalculator.cs" /> 91 <Compile Include="Symbolic\Analyzers\SymbolicRegressionModelQualityCalculator.cs"> 92 <SubType>Code</SubType> 93 </Compile> 93 94 <Compile Include="Symbolic\Analyzers\SymbolicRegressionSolutionLinearScaler.cs" /> 94 95 <Compile Include="Symbolic\Analyzers\SymbolicRegressionVariableFrequencyAnalyzer.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/BestSymbolicRegressionSolutionAnalyzer.cs
r3681 r3710 34 34 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 35 35 using HeuristicLab.Problems.DataAnalysis; 36 using HeuristicLab.Problems.DataAnalysis.Evaluators; 36 37 37 38 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers { … … 48 49 private const string BestSolutionQualityParameterName = "BestSolutionQuality"; 49 50 private const string ResultsParameterName = "Results"; 50 51 private const string BestSolutionResultName = "Best Solution (on validiation set)"; 52 private const string BestSolutionInputvariableCountResultName = "Variables Used by Best Solution"; 51 private const string BestSolutionResultName = "Best solution (on validiation set)"; 52 private const string BestSolutionInputvariableCountResultName = "Variables used by best solution"; 53 private const string BestSolutionTrainingRSquared = "Best solution R² (training)"; 54 private const string BestSolutionTestRSquared = "Best solution R² (test)"; 55 private const string BestSolutionTrainingMse = "Best solution mean squared error (training)"; 56 private const string BestSolutionTestMse = "Best solution mean squared error (test)"; 57 private const string BestSolutionTrainingRelativeError = "Best solution average relative error (training)"; 58 private const string BestSolutionTestRelativeError = "Best solution average relative error (test)"; 53 59 54 60 public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { … … 112 118 results.Add(new Result(BestSolutionResultName, solution)); 113 119 results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(model.InputVariables.Count()))); 120 #region calculate R2,MSE,Rel Error 121 double[] trainingValues = problemData.Dataset.GetVariableValues( 122 problemData.TargetVariable.Value, 123 problemData.TrainingSamplesStart.Value, 124 problemData.TrainingSamplesEnd.Value); 125 double[] testValues = problemData.Dataset.GetVariableValues( 126 problemData.TargetVariable.Value, 127 problemData.TestSamplesStart.Value, 128 problemData.TestSamplesEnd.Value); 129 double trainingR2 = SimpleRSquaredEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues); 130 double testR2 = SimpleRSquaredEvaluator.Calculate(testValues, solution.EstimatedTestValues); 131 double trainingMse = SimpleMSEEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues); 132 double testMse = SimpleMSEEvaluator.Calculate(testValues, solution.EstimatedTestValues); 133 double trainingRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues); 134 double testRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(testValues, solution.EstimatedTestValues); 135 results.Add(new Result(BestSolutionTrainingRSquared, new DoubleValue(trainingR2))); 136 results.Add(new Result(BestSolutionTestRSquared, new DoubleValue(testR2))); 137 results.Add(new Result(BestSolutionTrainingMse, new DoubleValue(trainingMse))); 138 results.Add(new Result(BestSolutionTestMse, new DoubleValue(testMse))); 139 results.Add(new Result(BestSolutionTrainingRelativeError, new DoubleValue(trainingRelError))); 140 results.Add(new Result(BestSolutionTestRelativeError, new DoubleValue(testRelError))); 141 #endregion 114 142 } else { 115 143 if (BestSolutionQualityParameter.ActualValue.Value > qualities[i].Value) { … … 120 148 results[BestSolutionResultName].Value = solution; 121 149 results[BestSolutionInputvariableCountResultName].Value = new IntValue(model.InputVariables.Count()); 150 #region update R2,MSE, Rel Error 151 double[] trainingValues = problemData.Dataset.GetVariableValues( 152 problemData.TargetVariable.Value, 153 problemData.TrainingSamplesStart.Value, 154 problemData.TrainingSamplesEnd.Value); 155 double[] testValues = problemData.Dataset.GetVariableValues( 156 problemData.TargetVariable.Value, 157 problemData.TestSamplesStart.Value, 158 problemData.TestSamplesEnd.Value); 159 double trainingR2 = SimpleRSquaredEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues); 160 double testR2 = SimpleRSquaredEvaluator.Calculate(testValues, solution.EstimatedTestValues); 161 double trainingMse = SimpleMSEEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues); 162 double testMse = SimpleMSEEvaluator.Calculate(testValues, solution.EstimatedTestValues); 163 double trainingRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues); 164 double testRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(testValues, solution.EstimatedTestValues); 165 results[BestSolutionTrainingRSquared].Value = new DoubleValue(trainingR2); 166 results[BestSolutionTestRSquared].Value = new DoubleValue(testR2); 167 results[BestSolutionTrainingMse].Value = new DoubleValue(trainingMse); 168 results[BestSolutionTestMse].Value = new DoubleValue(testMse); 169 results[BestSolutionTrainingRelativeError].Value = new DoubleValue(trainingRelError); 170 results[BestSolutionTestRelativeError].Value = new DoubleValue(testRelError); 171 #endregion 122 172 } 123 173 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionModelQualityAnalyzer.cs
r3683 r3710 51 51 private const string ResultsParameterName = "Results"; 52 52 53 private const string TrainingMeanSquaredErrorQualityParameterName = " TrainingMeanSquaredError";54 private const string MinTrainingMeanSquaredErrorQualityParameterName = "Min TrainingMeanSquaredError";55 private const string MaxTrainingMeanSquaredErrorQualityParameterName = "Max TrainingMeanSquaredError";56 private const string AverageTrainingMeanSquaredErrorQualityParameterName = "Average TrainingMeanSquaredError";57 private const string BestTrainingMeanSquaredErrorQualityParameterName = "Best TrainingMeanSquaredError";58 59 private const string TrainingAverageRelativeErrorQualityParameterName = " TrainingAverageRelativeError";60 private const string MinTrainingAverageRelativeErrorQualityParameterName = "Min TrainingAverageRelativeError";61 private const string MaxTrainingAverageRelativeErrorQualityParameterName = "Max TrainingAverageRelativeError";62 private const string AverageTrainingAverageRelativeErrorQualityParameterName = "Average TrainingAverageRelativeError";63 private const string BestTrainingAverageRelativeErrorQualityParameterName = "Best TrainingAverageRelativeError";64 65 private const string TrainingRSquaredQualityParameterName = " TrainingRSquared";66 private const string MinTrainingRSquaredQualityParameterName = "Min TrainingRSquared";67 private const string MaxTrainingRSquaredQualityParameterName = "Max TrainingRSquared";68 private const string AverageTrainingRSquaredQualityParameterName = "Average TrainingRSquared";69 private const string BestTrainingRSquaredQualityParameterName = "Best TrainingRSquared";70 71 private const string TestMeanSquaredErrorQualityParameterName = " TestMeanSquaredError";72 private const string MinTestMeanSquaredErrorQualityParameterName = "Min TestMeanSquaredError";73 private const string MaxTestMeanSquaredErrorQualityParameterName = "Max TestMeanSquaredError";74 private const string AverageTestMeanSquaredErrorQualityParameterName = "Average TestMeanSquaredError";75 private const string BestTestMeanSquaredErrorQualityParameterName = "Best TestMeanSquaredError";76 77 private const string TestAverageRelativeErrorQualityParameterName = " TestAverageRelativeError";78 private const string MinTestAverageRelativeErrorQualityParameterName = "Min TestAverageRelativeError";79 private const string MaxTestAverageRelativeErrorQualityParameterName = "Max TestAverageRelativeError";80 private const string AverageTestAverageRelativeErrorQualityParameterName = "Average TestAverageRelativeError";81 private const string BestTestAverageRelativeErrorQualityParameterName = "Best TestAverageRelativeError";82 83 private const string TestRSquaredQualityParameterName = " TestRSquared";84 private const string MinTestRSquaredQualityParameterName = "Min TestRSquared";85 private const string MaxTestRSquaredQualityParameterName = "Max TestRSquared";86 private const string AverageTestRSquaredQualityParameterName = "Average TestRSquared";87 private const string BestTestRSquaredQualityParameterName = "Best TestRSquared";88 89 private const string RSquaredValuesParameterName = "R -squared Values";90 private const string MeanSquaredErrorValuesParameterName = "Mean Squared Error Values";91 private const string RelativeErrorValuesParameterName = "Average Relative Error Values";53 private const string TrainingMeanSquaredErrorQualityParameterName = "Mean squared error (training)"; 54 private const string MinTrainingMeanSquaredErrorQualityParameterName = "Min mean squared error (training)"; 55 private const string MaxTrainingMeanSquaredErrorQualityParameterName = "Max mean squared error (training)"; 56 private const string AverageTrainingMeanSquaredErrorQualityParameterName = "Average mean squared error (training)"; 57 private const string BestTrainingMeanSquaredErrorQualityParameterName = "Best mean squared error (training)"; 58 59 private const string TrainingAverageRelativeErrorQualityParameterName = "Average relative error (training)"; 60 private const string MinTrainingAverageRelativeErrorQualityParameterName = "Min average relative error (training)"; 61 private const string MaxTrainingAverageRelativeErrorQualityParameterName = "Max average relative error (training)"; 62 private const string AverageTrainingAverageRelativeErrorQualityParameterName = "Average average relative error (training)"; 63 private const string BestTrainingAverageRelativeErrorQualityParameterName = "Best average relative error (training)"; 64 65 private const string TrainingRSquaredQualityParameterName = "R² (training)"; 66 private const string MinTrainingRSquaredQualityParameterName = "Min R² (training)"; 67 private const string MaxTrainingRSquaredQualityParameterName = "Max R² (training)"; 68 private const string AverageTrainingRSquaredQualityParameterName = "Average R² (training)"; 69 private const string BestTrainingRSquaredQualityParameterName = "Best R² (training)"; 70 71 private const string TestMeanSquaredErrorQualityParameterName = "Mean squared error (test)"; 72 private const string MinTestMeanSquaredErrorQualityParameterName = "Min mean squared error (test)"; 73 private const string MaxTestMeanSquaredErrorQualityParameterName = "Max mean squared error (test)"; 74 private const string AverageTestMeanSquaredErrorQualityParameterName = "Average mean squared error (test)"; 75 private const string BestTestMeanSquaredErrorQualityParameterName = "Best mean squared error (test)"; 76 77 private const string TestAverageRelativeErrorQualityParameterName = "Average relative error (test)"; 78 private const string MinTestAverageRelativeErrorQualityParameterName = "Min average relative error (test)"; 79 private const string MaxTestAverageRelativeErrorQualityParameterName = "Max average relative error (test)"; 80 private const string AverageTestAverageRelativeErrorQualityParameterName = "Average average relative error (test)"; 81 private const string BestTestAverageRelativeErrorQualityParameterName = "Best average relative error (test)"; 82 83 private const string TestRSquaredQualityParameterName = "R² (test)"; 84 private const string MinTestRSquaredQualityParameterName = "Min R² (test)"; 85 private const string MaxTestRSquaredQualityParameterName = "Max R² (test)"; 86 private const string AverageTestRSquaredQualityParameterName = "Average R² (test)"; 87 private const string BestTestRSquaredQualityParameterName = "Best R² (test)"; 88 89 private const string RSquaredValuesParameterName = "R²"; 90 private const string MeanSquaredErrorValuesParameterName = "Mean squared error"; 91 private const string RelativeErrorValuesParameterName = "Average relative error"; 92 92 93 93 private const string TrainingSamplesStartParameterName = "TrainingSamplesStart"; … … 132 132 133 133 [Storable] 134 private SymbolicRegressionModelQualityCalculator trainingQualityCalculator; 135 [Storable] 136 private SymbolicRegressionModelQualityCalculator testQualityCalculator; 134 private UniformSubScopesProcessor subScopesProcessor; 137 135 [Storable] 138 136 private MinAverageMaxValueAnalyzer minAvgMaxTrainingMseAnalyzer; … … 165 163 166 164 #region operator initialization 167 trainingQualityCalculator = new SymbolicRegressionModelQualityCalculator(); 168 testQualityCalculator = new SymbolicRegressionModelQualityCalculator(); 165 subScopesProcessor = new UniformSubScopesProcessor(); 166 SymbolicRegressionModelQualityCalculator trainingQualityCalculator = new SymbolicRegressionModelQualityCalculator(); 167 SymbolicRegressionModelQualityCalculator testQualityCalculator = new SymbolicRegressionModelQualityCalculator(); 169 168 minAvgMaxTrainingMseAnalyzer = new MinAverageMaxValueAnalyzer(); 170 169 minAvgMaxTestMseAnalyzer = new MinAverageMaxValueAnalyzer(); … … 178 177 179 178 #region parameter wiring 179 subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth; 180 180 trainingQualityCalculator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name; 181 181 trainingQualityCalculator.ProblemDataParameter.ActualName = ProblemDataParameter.Name; … … 184 184 trainingQualityCalculator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name; 185 185 trainingQualityCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name; 186 trainingQualityCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;187 186 trainingQualityCalculator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name; 188 187 trainingQualityCalculator.AverageRelativeErrorQualityParameter.ActualName = TrainingAverageRelativeErrorQualityParameterName; … … 196 195 testQualityCalculator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name; 197 196 testQualityCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name; 198 testQualityCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;199 197 testQualityCalculator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name; 200 198 testQualityCalculator.AverageRelativeErrorQualityParameter.ActualName = TestAverageRelativeErrorQualityParameterName; … … 209 207 minAvgMaxTrainingMseAnalyzer.ValuesParameter.ActualName = MeanSquaredErrorValuesParameterName; 210 208 minAvgMaxTrainingMseAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name; 209 minAvgMaxTrainingMseAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false); 210 minAvgMaxTrainingMseAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false); 211 minAvgMaxTrainingMseAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false); 211 212 212 213 minAvgMaxTestMseAnalyzer.ValueParameter.ActualName = TestMeanSquaredErrorQualityParameterName; … … 217 218 minAvgMaxTestMseAnalyzer.ValuesParameter.ActualName = MeanSquaredErrorValuesParameterName; 218 219 minAvgMaxTestMseAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name; 220 minAvgMaxTestMseAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false); 221 minAvgMaxTestMseAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false); 222 minAvgMaxTestMseAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false); 223 219 224 #endregion 220 225 #region training/test R² … … 226 231 minAvgMaxTrainingRSquaredAnalyzer.ValuesParameter.ActualName = RSquaredValuesParameterName; 227 232 minAvgMaxTrainingRSquaredAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name; 233 minAvgMaxTrainingRSquaredAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false); 234 minAvgMaxTrainingRSquaredAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false); 235 minAvgMaxTrainingRSquaredAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false); 236 228 237 229 238 minAvgMaxTestRSquaredAnalyzer.ValueParameter.ActualName = TestRSquaredQualityParameterName; … … 234 243 minAvgMaxTestRSquaredAnalyzer.ValuesParameter.ActualName = RSquaredValuesParameterName; 235 244 minAvgMaxTestRSquaredAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name; 245 minAvgMaxTestRSquaredAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false); 246 minAvgMaxTestRSquaredAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false); 247 minAvgMaxTestRSquaredAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false); 248 236 249 #endregion 237 250 #region training/test avg. rel. error … … 243 256 minAvgMaxTrainingRelErrorAnalyzer.ValuesParameter.ActualName = RelativeErrorValuesParameterName; 244 257 minAvgMaxTrainingRelErrorAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name; 258 minAvgMaxTrainingRelErrorAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false); 259 minAvgMaxTrainingRelErrorAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false); 260 minAvgMaxTrainingRelErrorAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false); 245 261 246 262 minAvgMaxTestRelErrorAnalyzer.ValueParameter.ActualName = TestAverageRelativeErrorQualityParameterName; … … 251 267 minAvgMaxTestRelErrorAnalyzer.ValuesParameter.ActualName = RelativeErrorValuesParameterName; 252 268 minAvgMaxTestRelErrorAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name; 269 minAvgMaxTestRelErrorAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false); 270 minAvgMaxTestRelErrorAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false); 271 minAvgMaxTestRelErrorAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false); 253 272 #endregion 254 273 #endregion 255 274 256 275 #region operator graph 257 OperatorGraph.InitialOperator = trainingQualityCalculator; 276 OperatorGraph.InitialOperator = subScopesProcessor; 277 subScopesProcessor.Operator = trainingQualityCalculator; 258 278 trainingQualityCalculator.Successor = testQualityCalculator; 259 testQualityCalculator.Successor = minAvgMaxTrainingMseAnalyzer; 279 testQualityCalculator.Successor = null; 280 subScopesProcessor.Successor = minAvgMaxTrainingMseAnalyzer; 260 281 minAvgMaxTrainingMseAnalyzer.Successor = minAvgMaxTestMseAnalyzer; 261 282 minAvgMaxTestMseAnalyzer.Successor = minAvgMaxTrainingRSquaredAnalyzer; … … 284 305 285 306 private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) { 286 trainingQualityCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth; 287 testQualityCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth; 307 subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth; 288 308 minAvgMaxTrainingMseAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth; 289 309 minAvgMaxTrainingRelErrorAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionModelQualityCalculator.cs
r3683 r3710 57 57 58 58 #region parameter properties 59 public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {60 get { return ( ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }59 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { 60 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 61 61 } 62 62 public IValueLookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { … … 91 91 public SymbolicRegressionModelQualityCalculator() 92 92 : base() { 93 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree to analyze.")); 93 94 Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic expression tree.")); 94 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree to analyze."));95 95 Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data containing the input varaibles for the symbolic regression problem.")); 96 96 Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The first index of the data set partition on which the model quality values should be calculated.")); … … 102 102 Parameters.Add(new ValueLookupParameter<DoubleValue>(RSQuaredQualityParameterName, "The R² correlation coefficient of the output of the model and the original target values.")); 103 103 Parameters.Add(new ValueLookupParameter<DoubleValue>(RelativeErrorQualityParameterName, "The average relative percentage error of the output of the model.")); 104 104 105 #region operator initialization 105 106 SimpleSymbolicRegressionEvaluator simpleEvaluator = new SimpleSymbolicRegressionEvaluator(); … … 143 144 144 145 } 145 146 // need to create custom operations for each solution scope (this has to be adapted on basis of the depth value of SymbolicExpressionTreeParameter)147 public override IOperation Apply() {148 var scopes = GetScopesOnLevel(ExecutionContext.Scope, SymbolicExpressionTreeParameter.Depth);149 OperationCollection operations = new OperationCollection();150 foreach (IScope treeScopes in scopes) {151 operations.Add(ExecutionContext.CreateChildOperation(OperatorGraph.InitialOperator, treeScopes));152 }153 if (Successor != null) operations.Add(ExecutionContext.CreateOperation(Successor));154 return operations;155 }156 157 private IEnumerable<IScope> GetScopesOnLevel(IScope scope, int d) {158 if (d == 0) yield return scope;159 else {160 foreach (IScope subScope in scope.SubScopes) {161 foreach (IScope scopesOfSubScope in GetScopesOnLevel(subScope, d - 1)) {162 yield return scopesOfSubScope;163 }164 }165 }166 }167 146 } 168 147 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionSolutionLinearScaler.cs
r3683 r3710 47 47 private const string BetaParameterName = "Beta"; 48 48 49 public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {50 get { return ( ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }49 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { 50 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 51 51 } 52 public ScopeTreeLookupParameter<SymbolicExpressionTree> ScaledSymbolicExpressionTreeParameter {53 get { return ( ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[ScaledSymbolicExpressionTreeParameterName]; }52 public ILookupParameter<SymbolicExpressionTree> ScaledSymbolicExpressionTreeParameter { 53 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[ScaledSymbolicExpressionTreeParameterName]; } 54 54 } 55 public ScopeTreeLookupParameter<DoubleValue> AlphaParameter {56 get { return ( ScopeTreeLookupParameter<DoubleValue>)Parameters[AlphaParameterName]; }55 public ILookupParameter<DoubleValue> AlphaParameter { 56 get { return (ILookupParameter<DoubleValue>)Parameters[AlphaParameterName]; } 57 57 } 58 public ScopeTreeLookupParameter<DoubleValue> BetaParameter {59 get { return ( ScopeTreeLookupParameter<DoubleValue>)Parameters[BetaParameterName]; }58 public ILookupParameter<DoubleValue> BetaParameter { 59 get { return (ILookupParameter<DoubleValue>)Parameters[BetaParameterName]; } 60 60 } 61 61 62 62 public SymbolicRegressionSolutionLinearScaler() 63 63 : base() { 64 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to transform."));65 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(ScaledSymbolicExpressionTreeParameterName, "The resulting symbolic expression trees after transformation."));66 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(AlphaParameterName, "Alpha parameter for linear transformation."));67 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(BetaParameterName, "Beta parameter for linear transformation."));64 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to transform.")); 65 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(ScaledSymbolicExpressionTreeParameterName, "The resulting symbolic expression trees after transformation.")); 66 Parameters.Add(new LookupParameter<DoubleValue>(AlphaParameterName, "Alpha parameter for linear transformation.")); 67 Parameters.Add(new LookupParameter<DoubleValue>(BetaParameterName, "Beta parameter for linear transformation.")); 68 68 } 69 69 70 70 public override IOperation Apply() { 71 ItemArray<SymbolicExpressionTree> trees = SymbolicExpressionTreeParameter.ActualValue; 72 ItemArray<DoubleValue> alphas = AlphaParameter.ActualValue; 73 ItemArray<DoubleValue> betas = BetaParameter.ActualValue; 74 ItemArray<SymbolicExpressionTree> scaledTrees = new ItemArray<SymbolicExpressionTree>(trees.Length); 75 for (int i = 0; i < trees.Length; i++) { 76 var mainBranch = trees[i].Root.SubTrees[0].SubTrees[0]; 77 var scaledMainBranch = MakeSum(MakeProduct(betas[i].Value, mainBranch), alphas[i].Value); 71 SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue; 72 DoubleValue alpha = AlphaParameter.ActualValue; 73 DoubleValue beta = BetaParameter.ActualValue; 74 var mainBranch = tree.Root.SubTrees[0].SubTrees[0]; 75 var scaledMainBranch = MakeSum(MakeProduct(beta.Value, mainBranch), alpha.Value); 78 76 79 // remove the main branch before cloning to prevent cloning of sub-trees 80 trees[i].Root.SubTrees[0].RemoveSubTree(0); 81 var scaledTree = (SymbolicExpressionTree)trees[i].Clone(); 82 // insert main branch into the original tree again 83 trees[i].Root.SubTrees[0].InsertSubTree(0, mainBranch); 84 // insert the scaled main branch into the cloned tree 85 scaledTree.Root.SubTrees[0].InsertSubTree(0, scaledMainBranch); 86 scaledTrees[i] = scaledTree; 87 } 88 ScaledSymbolicExpressionTreeParameter.ActualValue = scaledTrees; 77 // remove the main branch before cloning to prevent cloning of sub-trees 78 tree.Root.SubTrees[0].RemoveSubTree(0); 79 var scaledTree = (SymbolicExpressionTree)tree.Clone(); 80 // insert main branch into the original tree again 81 tree.Root.SubTrees[0].InsertSubTree(0, mainBranch); 82 // insert the scaled main branch into the cloned tree 83 scaledTree.Root.SubTrees[0].InsertSubTree(0, scaledMainBranch); 84 ScaledSymbolicExpressionTreeParameter.ActualValue = scaledTree; 89 85 return base.Apply(); 90 86 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs
r3683 r3710 56 56 private const string AlphaParameterName = "Alpha"; 57 57 private const string BetaParameterName = "Beta"; 58 private const string BestSolutionParameterName = "ValidationBestSolution"; 59 private const string BestSolutionQualityParameterName = "ValidationBestSolutionQuality"; 58 private const string BestSolutionParameterName = "Best solution (validation)"; 59 private const string BestSolutionQualityParameterName = "Best solution quality (validation)"; 60 private const string CurrentBestValidationQualityParameterName = "Current best validation quality"; 60 61 private const string ResultsParameterName = "Results"; 61 62 … … 91 92 } 92 93 93 [Storable]94 private BestQualityMemorizer validationQualityMemorizer;95 94 [Storable] 96 95 private BestSymbolicRegressionSolutionAnalyzer bestSolutionAnalyzer; 97 96 [Storable] 98 private SymbolicRegressionSolutionLinearScaler linearScaler;97 private UniformSubScopesProcessor subScopesProcessor; 99 98 [Storable] 100 private SymbolicRegressionMeanSquaredErrorCalculator validationMseCalculator;99 private BestAverageWorstQualityCalculator bestAvgWorstValidationQualityCalculator; 101 100 102 101 public ValidationBestScaledSymbolicRegressionSolutionAnalyzer() … … 114 113 115 114 #region operator initialization 116 linearScaler = new SymbolicRegressionSolutionLinearScaler(); 117 validationMseCalculator = new SymbolicRegressionMeanSquaredErrorCalculator(); 115 subScopesProcessor = new UniformSubScopesProcessor(); 116 SymbolicRegressionSolutionLinearScaler linearScaler = new SymbolicRegressionSolutionLinearScaler(); 117 SymbolicRegressionMeanSquaredErrorEvaluator validationMseEvaluator = new SymbolicRegressionMeanSquaredErrorEvaluator(); 118 118 bestSolutionAnalyzer = new BestSymbolicRegressionSolutionAnalyzer(); 119 validationQualityMemorizer = new BestQualityMemorizer(); 120 BestAverageWorstQualityCalculator bestAvgWorstValidationQualityCalculator = new BestAverageWorstQualityCalculator(); 119 bestAvgWorstValidationQualityCalculator = new BestAverageWorstQualityCalculator(); 121 120 DataTableValuesCollector validationValuesCollector = new DataTableValuesCollector(); 122 121 ResultsCollector resultsCollector = new ResultsCollector(); … … 124 123 125 124 #region parameter wiring 125 subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth; 126 126 127 linearScaler.AlphaParameter.ActualName = AlphaParameterName; 127 linearScaler.AlphaParameter.Depth = SymbolicExpressionTreeParameter.Depth;128 128 linearScaler.BetaParameter.ActualName = BetaParameterName; 129 linearScaler.BetaParameter.Depth = SymbolicExpressionTreeParameter.Depth;130 129 linearScaler.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name; 131 linearScaler.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;132 130 linearScaler.ScaledSymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName; 133 linearScaler.ScaledSymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth; 134 135 validationMseCalculator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name; 136 validationMseCalculator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name; 137 validationMseCalculator.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName; 138 validationMseCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth; 139 validationMseCalculator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name; 140 validationMseCalculator.QualityParameter.ActualName = QualityParameterName; 141 validationMseCalculator.ProblemDataParameter.ActualName = ProblemDataParameter.Name; 142 validationMseCalculator.SamplesStartParameter.ActualName = SamplesStartParameter.Name; 143 validationMseCalculator.SamplesEndParameter.ActualName = SamplesEndParameter.Name; 131 132 validationMseEvaluator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name; 133 validationMseEvaluator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name; 134 validationMseEvaluator.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName; 135 validationMseEvaluator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name; 136 validationMseEvaluator.QualityParameter.ActualName = QualityParameterName; 137 validationMseEvaluator.RegressionProblemDataParameter.ActualName = ProblemDataParameter.Name; 138 validationMseEvaluator.SamplesStartParameter.ActualName = SamplesStartParameter.Name; 139 validationMseEvaluator.SamplesEndParameter.ActualName = SamplesEndParameter.Name; 144 140 145 141 bestSolutionAnalyzer.BestSolutionParameter.ActualName = BestSolutionParameter.Name; … … 154 150 bestSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name; 155 151 156 bestAvgWorstValidationQualityCalculator.AverageQualityParameter.ActualName = "Current Average Validation Quality";157 bestAvgWorstValidationQualityCalculator.BestQualityParameter.ActualName = "Current Best Validation Quality";152 bestAvgWorstValidationQualityCalculator.AverageQualityParameter.ActualName = "Current average validation quality"; 153 bestAvgWorstValidationQualityCalculator.BestQualityParameter.ActualName = CurrentBestValidationQualityParameterName; 158 154 bestAvgWorstValidationQualityCalculator.MaximizationParameter.Value = new BoolValue(false); 159 155 bestAvgWorstValidationQualityCalculator.QualityParameter.ActualName = QualityParameterName; 160 bestAvgWorstValidationQualityCalculator.WorstQualityParameter.ActualName = "Current Worst Validation Quality"; 161 162 validationQualityMemorizer.BestQualityParameter.ActualName = "Best Validation Quality"; 163 validationQualityMemorizer.QualityParameter.ActualName = QualityParameterName; 164 validationQualityMemorizer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth; 165 166 validationValuesCollector.DataTableParameter.ActualName = "Validation Qualities"; 167 validationValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Validation Quality", null, "Current Best Validation Quality")); 168 validationValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Validation Quality", null, "Best Validation Quality")); 169 170 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Validation Quality", null, "Current Best Validation Quality")); 171 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Validation Quality", null, "Best Validation Quality")); 172 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Validation Qualities")); 156 bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth; 157 bestAvgWorstValidationQualityCalculator.WorstQualityParameter.ActualName = "Current worst validation quality"; 158 159 validationValuesCollector.DataTableParameter.ActualName = "Validation quality"; 160 validationValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(CurrentBestValidationQualityParameterName, null, CurrentBestValidationQualityParameterName)); 161 validationValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameter.Name, null, BestSolutionQualityParameter.Name)); 162 163 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(CurrentBestValidationQualityParameterName, null, CurrentBestValidationQualityParameterName)); 164 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameter.Name, null, BestSolutionQualityParameter.Name)); 165 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Validation quality")); 173 166 resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name; 174 167 #endregion 175 168 176 169 #region operator graph 177 OperatorGraph.InitialOperator = linearScaler; 178 linearScaler.Successor = validationMseCalculator; 179 validationMseCalculator.Successor = bestSolutionAnalyzer; 170 OperatorGraph.InitialOperator = subScopesProcessor; 171 subScopesProcessor.Operator = linearScaler; 172 linearScaler.Successor = validationMseEvaluator; 173 validationMseEvaluator.Successor = null; 174 subScopesProcessor.Successor = bestSolutionAnalyzer; 180 175 bestSolutionAnalyzer.Successor = bestAvgWorstValidationQualityCalculator; 181 bestAvgWorstValidationQualityCalculator.Successor = validationQualityMemorizer; 182 validationQualityMemorizer.Successor = validationValuesCollector; 176 bestAvgWorstValidationQualityCalculator.Successor = validationValuesCollector; 183 177 validationValuesCollector.Successor = resultsCollector; 184 178 resultsCollector.Successor = null; … … 203 197 204 198 private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) { 205 validationMseCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth; 206 validationQualityMemorizer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth; 199 subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth; 207 200 bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth; 208 201 bestSolutionAnalyzer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth; 209 linearScaler.AlphaParameter.Depth = SymbolicExpressionTreeParameter.Depth; 210 linearScaler.BetaParameter.Depth = SymbolicExpressionTreeParameter.Depth; 211 linearScaler.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth; 212 linearScaler.ScaledSymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth; 202 bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth; 213 203 } 214 204 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs
r3513 r3710 28 28 using System.Collections.Generic; 29 29 using System.Linq; 30 using System.Drawing; 30 31 31 32 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { … … 36 37 [StorableClass] 37 38 public sealed class SymbolicRegressionSolution : DataAnalysisSolution { 39 public override Image ItemImage { 40 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Function; } 41 } 38 42 [Storable] 39 43 private SymbolicRegressionModel model;
Note: See TracChangeset
for help on using the changeset viewer.