- Timestamp:
- 04/23/10 14:28:07 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/BestValidationSymbolicRegressionSolutionVisualizer.cs
r3462 r3513 40 40 public sealed class BestValidationSymbolicRegressionSolutionVisualizer : SingleSuccessorOperator, ISingleObjectiveSolutionsVisualizer, ISolutionsVisualizer { 41 41 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 42 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; 43 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; 42 44 private const string SymbolicRegressionModelParameterName = "SymbolicRegressionModel"; 43 45 private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData"; … … 51 53 public ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { 52 54 get { return (ILookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; } 55 } 56 public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter { 57 get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; } 58 } 59 public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter { 60 get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; } 53 61 } 54 62 public IValueLookupParameter<IntValue> ValidationSamplesStartParameter { … … 85 93 get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; } 86 94 } 95 public DoubleValue UpperEstimationLimit { 96 get { return UpperEstimationLimitParameter.ActualValue; } 97 } 98 public DoubleValue LowerEstimationLimit { 99 get { return LowerEstimationLimitParameter.ActualValue; } 100 } 87 101 public IntValue ValidationSamplesStart { 88 102 get { return ValidationSamplesStartParameter.ActualValue; } … … 99 113 Parameters.Add(new LookupParameter<DataAnalysisProblemData>(DataAnalysisProblemDataParameterName, "The symbolic regression problme data on which the best solution should be evaluated.")); 100 114 Parameters.Add(new LookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of symbolic expression trees.")); 115 Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper limit that should be used as cut off value for the output values of symbolic expression trees.")); 116 Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower limit that should be used as cut off value for the output values of symbolic expression trees.")); 101 117 Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesStartParameterName, "The start index of the validation partition (part of the training partition).")); 102 118 Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesEndParameterName, "The end index of the validation partition (part of the training partition).")); … … 112 128 int validationSamplesEnd = ValidationSamplesEnd.Value; 113 129 var validationValues = problemData.Dataset.GetVariableValues(problemData.TargetVariable.Value, validationSamplesStart, validationSamplesEnd); 114 130 double upperEstimationLimit = UpperEstimationLimit.Value; 131 double lowerEstimationLimit = LowerEstimationLimit.Value; 115 132 var currentBestExpression = (from expression in expressions 116 133 let validationQuality = 117 134 SymbolicRegressionMeanSquaredErrorEvaluator.Calculate( 118 135 SymbolicExpressionTreeInterpreter, expression, 136 lowerEstimationLimit, upperEstimationLimit, 119 137 problemData.Dataset, problemData.TargetVariable.Value, 120 138 validationSamplesStart, validationSamplesEnd) … … 126 144 if (bestOfRunSolution == null) { 127 145 // no best of run solution yet -> make a solution from the currentBestExpression 128 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression, SymbolicExpressionTreeInterpreter );146 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression, SymbolicExpressionTreeInterpreter, lowerEstimationLimit, upperEstimationLimit); 129 147 } else { 130 148 // compare quality of current best with best of run solution … … 132 150 var bestOfRunValidationQuality = SimpleMSEEvaluator.Calculate(validationValues, estimatedValidationValues); 133 151 if (bestOfRunValidationQuality > currentBestExpression.ValidationQuality) { 134 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression, SymbolicExpressionTreeInterpreter );152 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression, SymbolicExpressionTreeInterpreter, lowerEstimationLimit, upperEstimationLimit); 135 153 } 136 154 } … … 140 158 } 141 159 142 private void UpdateBestOfRunSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter) { 143 var newBestSolution = CreateDataAnalysisSolution(problemData, tree, interpreter); 160 private void UpdateBestOfRunSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, 161 double lowerEstimationLimit, double upperEstimationLimit) { 162 var newBestSolution = CreateDataAnalysisSolution(problemData, tree, interpreter, lowerEstimationLimit, upperEstimationLimit); 144 163 if (BestValidationSolutionParameter.ActualValue == null) 145 164 BestValidationSolutionParameter.ActualValue = newBestSolution; … … 169 188 } 170 189 171 private SymbolicRegressionSolution CreateDataAnalysisSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree expression, ISymbolicExpressionTreeInterpreter interpreter) { 190 private SymbolicRegressionSolution CreateDataAnalysisSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree expression, ISymbolicExpressionTreeInterpreter interpreter, 191 double lowerEstimationLimit, double upperEstimationLimit) { 172 192 var model = new SymbolicRegressionModel(interpreter, expression, problemData.InputVariables.Select(s => s.Value)); 173 return new SymbolicRegressionSolution(problemData, model );193 return new SymbolicRegressionSolution(problemData, model, lowerEstimationLimit, upperEstimationLimit); 174 194 } 175 195 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs
r3491 r3513 41 41 [StorableClass] 42 42 public class SymbolicRegressionMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator { 43 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; 44 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; 45 46 #region parameter properties 47 public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter { 48 get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; } 49 } 50 public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter { 51 get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; } 52 } 53 #endregion 54 #region properties 55 public DoubleValue UpperEstimationLimit { 56 get { return UpperEstimationLimitParameter.ActualValue; } 57 } 58 public DoubleValue LowerEstimationLimit { 59 get { return LowerEstimationLimitParameter.ActualValue; } 60 } 61 #endregion 62 public SymbolicRegressionMeanSquaredErrorEvaluator() 63 : base() { 64 Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper limit that should be used as cut off value for the output values of symbolic expression trees.")); 65 Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower limit that should be used as cut off value for the output values of symbolic expression trees.")); 66 } 67 43 68 protected override double Evaluate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd) { 44 double mse = Calculate(interpreter, solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);69 double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value); 45 70 return mse; 46 71 } 47 72 48 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, string targetVariable, int start, int end) {73 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, int start, int end) { 49 74 int targetVariableIndex = dataset.GetVariableIndex(targetVariable); 50 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start)); 75 var estimatedValues = from x in interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start)) 76 let boundedX = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, x)) 77 select double.IsNaN(boundedX) ? upperEstimationLimit : boundedX; 51 78 var originalValues = from row in Enumerable.Range(start, end - start) select dataset[row, targetVariableIndex]; 52 79 return SimpleMSEEvaluator.Calculate(originalValues, estimatedValues); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs
r3493 r3513 55 55 get { return inputVariables.AsEnumerable(); } 56 56 } 57 58 57 public SymbolicRegressionModel() : base() { } // for cloning 59 58 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r3491 r3513 58 58 get { return SolutionCreatorParameter; } 59 59 } 60 public ValueParameter<DoubleValue> LowerEstimationLimitParameter { 61 get { return (ValueParameter<DoubleValue>)Parameters["LowerEstimationLimit"]; } 62 } 63 public ValueParameter<DoubleValue> UpperEstimationLimitParameter { 64 get { return (ValueParameter<DoubleValue>)Parameters["UpperEstimationLimit"]; } 65 } 66 public ValueParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { 67 get { return (ValueParameter<ISymbolicExpressionTreeInterpreter>)Parameters["SymbolicExpressionTreeInterpreter"]; } 68 } 60 69 public ValueParameter<ISymbolicRegressionEvaluator> EvaluatorParameter { 61 70 get { return (ValueParameter<ISymbolicRegressionEvaluator>)Parameters["Evaluator"]; } … … 109 118 get { return SolutionCreatorParameter.Value; } 110 119 } 120 public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { 121 get { return SymbolicExpressionTreeInterpreterParameter.Value; } 122 set { SymbolicExpressionTreeInterpreterParameter.Value = value; } 123 } 124 public DoubleValue LowerEstimationLimit { 125 get { return LowerEstimationLimitParameter.Value; } 126 set { LowerEstimationLimitParameter.Value = value; } 127 } 128 public DoubleValue UpperEstimationLimit { 129 get { return UpperEstimationLimitParameter.Value; } 130 set { UpperEstimationLimitParameter.Value = value; } 131 } 132 111 133 public ISymbolicRegressionEvaluator Evaluator { 112 134 get { return EvaluatorParameter.Value; } … … 135 157 public IEnumerable<IOperator> Operators { 136 158 get { return operators.Cast<IOperator>(); } 159 } 160 public DoubleValue PunishmentFactor { 161 get { return new DoubleValue(10.0); } 137 162 } 138 163 #endregion … … 150 175 Parameters.Add(new ValueParameter<ISymbolicExpressionTreeInterpreter>("SymbolicExpressionTreeInterpreter", "The interpreter that should be used to evaluate the symbolic expression tree.", interpreter)); 151 176 Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator)); 177 Parameters.Add(new ValueParameter<DoubleValue>("LowerEstimationLimit", "The lower limit for the estimated value that can be returned by the symbolic regression model.", new DoubleValue(double.NegativeInfinity))); 178 Parameters.Add(new ValueParameter<DoubleValue>("UpperEstimationLimit", "The upper limit for the estimated value that can be returned by the symbolic regression model.", new DoubleValue(double.PositiveInfinity))); 152 179 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem.")); 153 180 Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("FunctionTreeGrammar", "The grammar that should be used for symbolic regression models.", globalGrammar)); … … 169 196 Initialize(); 170 197 } 171 172 198 173 199 [StorableConstructor] … … 208 234 Evaluator.SamplesStartParameter.Value = new IntValue(trainingStart); 209 235 Evaluator.SamplesEndParameter.Value = new IntValue(trainingEnd); 236 237 if (trainingEnd - trainingStart > 0 && DataAnalysisProblemData.TargetVariable.Value != string.Empty) { 238 var targetValues = DataAnalysisProblemData.Dataset.GetVariableValues(DataAnalysisProblemData.TargetVariable.Value, trainingStart, trainingEnd); 239 var mean = targetValues.Average(); 240 var range = targetValues.Max() - targetValues.Min(); 241 UpperEstimationLimit = new DoubleValue(mean + PunishmentFactor.Value * range); 242 LowerEstimationLimit = new DoubleValue(mean - PunishmentFactor.Value * range); 243 } 210 244 } 211 245 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs
r3493 r3513 50 50 51 51 public SymbolicRegressionSolution() : base() { } 52 public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model )53 : base(problemData ) {52 public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model, double lowerEstimationLimit, double upperEstimationLimit) 53 : base(problemData, lowerEstimationLimit, upperEstimationLimit) { 54 54 this.model = model; 55 55 } … … 68 68 69 69 private void RecalculateEstimatedValues() { 70 estimatedValues = model.GetEstimatedValues(ProblemData.Dataset, 0, ProblemData.Dataset.Rows).ToList(); 70 estimatedValues = (from x in model.GetEstimatedValues(ProblemData.Dataset, 0, ProblemData.Dataset.Rows) 71 let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x)) 72 select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX).ToList(); 71 73 OnEstimatedValuesChanged(EventArgs.Empty); 72 74 }
Note: See TracChangeset
for help on using the changeset viewer.