Changeset 5331
- Timestamp:
- 01/19/11 15:07:45 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs
r5246 r5331 20 20 #endregion 21 21 22 using System.Collections.Generic;23 using System.Linq;24 22 using HeuristicLab.Analysis; 25 23 using HeuristicLab.Common; … … 27 25 using HeuristicLab.Data; 28 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Operators;30 27 using HeuristicLab.Optimization; 31 28 using HeuristicLab.Parameters; … … 40 37 [StorableClass] 41 38 public sealed class FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer : SymbolicRegressionValidationAnalyzer, ISymbolicRegressionAnalyzer { 39 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 42 40 private const string MaximizationParameterName = "Maximization"; 43 41 private const string CalculateSolutionComplexityParameterName = "CalculateSolutionComplexity"; … … 84 82 get { return (ILookupParameter<DataTable>)Parameters[VariableFrequenciesParameterName]; } 85 83 } 86 84 public IValueLookupParameter<BoolValue> ApplyLinearScalingParameter { 85 get { return (IValueLookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 86 } 87 87 #endregion 88 88 #region properties … … 114 114 set { BestSolutionHeightParameter.ActualValue = value; } 115 115 } 116 116 public BoolValue ApplyLinearScaling { 117 get { return ApplyLinearScalingParameter.ActualValue; } 118 set { ApplyLinearScalingParameter.ActualValue = value; } 119 } 117 120 #endregion 118 121 … … 122 125 public FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer() 123 126 : base() { 127 Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyLinearScalingParameterName, "The switch determines if the best solution should be linearly scaled on the whole training set.", new BoolValue(true))); 124 128 Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization.")); 125 Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the validation best solution should be calculated.", new BoolValue( false)));129 Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the validation best solution should be calculated.", new BoolValue(true))); 126 130 Parameters.Add(new LookupParameter<SymbolicRegressionSolution>(BestSolutionParameterName, "The best symbolic regression solution.")); 127 131 Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations calculated so far.")); … … 155 159 if (!Parameters.ContainsKey(BestSolutionHeightParameterName)) { 156 160 Parameters.Add(new LookupParameter<IntValue>(BestSolutionHeightParameterName, "The height of the best symbolic regression solution.")); 161 } 162 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) { 163 Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyLinearScalingParameterName, "The switch determines if the best solution should be linearly scaled on the whole training set.", new BoolValue(true))); 157 164 } 158 165 #endregion … … 182 189 string targetVariable = ProblemData.TargetVariable.Value; 183 190 184 // calculate scaling parameters and only for the best tree using the full training set 185 double alpha, beta; 186 SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree, 187 lowerEstimationLimit, upperEstimationLimit, 188 ProblemData.Dataset, targetVariable, 189 ProblemData.TrainingIndizes, out beta, out alpha); 190 191 // scale tree for solution 192 var scaledTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta); 191 if (ApplyLinearScaling.Value) { 192 // calculate scaling parameters and only for the best tree using the full training set 193 double alpha, beta; 194 SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree, 195 lowerEstimationLimit, upperEstimationLimit, 196 ProblemData.Dataset, targetVariable, 197 ProblemData.TrainingIndizes, out beta, out alpha); 198 199 // scale tree for solution 200 bestTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta); 201 } 193 202 var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)SymbolicExpressionTreeInterpreter.Clone(), 194 scaledTree);203 bestTree); 195 204 var solution = new SymbolicRegressionSolution((DataAnalysisProblemData)ProblemData.Clone(), model, lowerEstimationLimit, upperEstimationLimit); 196 205 solution.Name = BestSolutionParameterName; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/TrainingBestScaledSymbolicRegressionSolutionAnalyzer.cs
r5259 r5331 22 22 using System.Collections.Generic; 23 23 using System.Linq; 24 using HeuristicLab.Analysis;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 31 30 using HeuristicLab.Parameters; 32 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Problems.DataAnalysis.Evaluators; 33 33 using HeuristicLab.Problems.DataAnalysis.Symbolic; 34 using HeuristicLab.Problems.DataAnalysis.Evaluators;35 34 36 35 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers { … … 41 40 [StorableClass] 42 41 public sealed class TrainingBestScaledSymbolicRegressionSolutionAnalyzer : SingleSuccessorOperator, ISymbolicRegressionAnalyzer { 42 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 43 43 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 44 44 private const string QualityParameterName = "Quality"; … … 128 128 get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; } 129 129 } 130 public IValueLookupParameter<BoolValue> ApplyLinearScalingParameter { 131 get { return (IValueLookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 132 } 130 133 #endregion 131 134 #region properties … … 205 208 get { return BestSolutionTestRelativeErrorParameter.ActualValue; } 206 209 set { BestSolutionTestRelativeErrorParameter.ActualValue = value; } 210 } 211 public BoolValue ApplyLinearScaling { 212 get { return ApplyLinearScalingParameter.ActualValue; } 213 set { ApplyLinearScalingParameter.ActualValue = value; } 207 214 } 208 215 #endregion … … 213 220 public TrainingBestScaledSymbolicRegressionSolutionAnalyzer() 214 221 : base() { 222 Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyLinearScalingParameterName, "The switch determines if the best solution should be linearly scaled on the whole training set.", new BoolValue(true))); 215 223 Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization.")); 216 224 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze.")); 217 225 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the symbolic expression trees to analyze.")); 218 Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the training best solution should be calculated.", new BoolValue( false)));219 Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionAccuracyParameterName, "Determines if the accuracy of the training best solution on the training and test set should be calculated.", new BoolValue( false)));226 Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the training best solution should be calculated.", new BoolValue(true))); 227 Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionAccuracyParameterName, "Determines if the accuracy of the training best solution on the training and test set should be calculated.", new BoolValue(true))); 220 228 Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used for the analysis of symbolic expression trees.")); 221 229 Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data for which the symbolic expression tree is a solution.")); … … 241 249 242 250 [StorableHook(HookType.AfterDeserialization)] 243 private void AfterDeserialization() { } 251 private void AfterDeserialization() { 252 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) { 253 Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyLinearScalingParameterName, "The switch determines if the best solution should be linearly scaled on the whole training set.", new BoolValue(true))); 254 } 255 } 244 256 245 257 public override IOperation Apply() { … … 269 281 string targetVariable = ProblemData.TargetVariable.Value; 270 282 271 // calculate scaling parameters and only for the best tree using the full training set 272 double alpha, beta; 273 SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree, 274 lowerEstimationLimit, upperEstimationLimit, 275 ProblemData.Dataset, targetVariable, 276 ProblemData.TrainingIndizes, out beta, out alpha); 277 278 // scale tree for solution 279 var scaledTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta); 283 if (ApplyLinearScaling.Value) { 284 // calculate scaling parameters and only for the best tree using the full training set 285 double alpha, beta; 286 SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree, 287 lowerEstimationLimit, upperEstimationLimit, 288 ProblemData.Dataset, targetVariable, 289 ProblemData.TrainingIndizes, out beta, out alpha); 290 291 // scale tree for solution 292 bestTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta); 293 } 280 294 var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)SymbolicExpressionTreeInterpreter.Clone(), 281 scaledTree);295 bestTree); 282 296 var solution = new SymbolicRegressionSolution((DataAnalysisProblemData)ProblemData.Clone(), model, lowerEstimationLimit, upperEstimationLimit); 283 297 solution.Name = BestSolutionParameterName; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r5260 r5331 148 148 AddOperator(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer()); 149 149 AddOperator(new SymbolicRegressionOverfittingAnalyzer()); 150 AddOperator(new TrainingBestScaledSymbolicRegressionSolutionAnalyzer()); 150 151 ParameterizeAnalyzers(); 151 152 }
Note: See TracChangeset
for help on using the changeset viewer.