Changeset 5331 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/TrainingBestScaledSymbolicRegressionSolutionAnalyzer.cs
- Timestamp:
- 01/19/11 15:07:45 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.