Changeset 3532
- Timestamp:
- 04/26/10 14:21:03 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj
r3531 r3532 87 87 <Compile Include="Properties\AssemblyInfo.cs" /> 88 88 <Compile Include="Symbolic\BestValidationSymbolicRegressionSolutionVisualizer.cs" /> 89 <Compile Include="Symbolic\SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs" /> 89 90 <Compile Include="Symbolic\SymbolicRegressionSolution.cs" /> 90 91 <Compile Include="Symbolic\SymbolicRegressionModel.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/BestValidationSymbolicRegressionSolutionVisualizer.cs
r3531 r3532 34 34 using HeuristicLab.Analysis; 35 35 36 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 37 36 38 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 37 39 /// <summary> … … 44 46 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; 45 47 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; 48 private const string AlphaParameterName = "Alpha"; 49 private const string BetaParameterName = "Beta"; 46 50 private const string SymbolicRegressionModelParameterName = "SymbolicRegressionModel"; 47 51 private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData"; … … 73 77 get { return (ILookupParameter<ItemArray<SymbolicExpressionTree>>)Parameters[SymbolicRegressionModelParameterName]; } 74 78 } 79 public ILookupParameter<ItemArray<DoubleValue>> AlphaParameter { 80 get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters[AlphaParameterName]; } 81 } 82 public ILookupParameter<ItemArray<DoubleValue>> BetaParameter { 83 get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters[BetaParameterName]; } 84 } 75 85 public ILookupParameter<DataAnalysisProblemData> DataAnalysisProblemDataParameter { 76 86 get { return (ILookupParameter<DataAnalysisProblemData>)Parameters[DataAnalysisProblemDataParameterName]; } … … 124 134 Parameters.Add(new LookupParameter<DataAnalysisProblemData>(DataAnalysisProblemDataParameterName, "The symbolic regression problme data on which the best solution should be evaluated.")); 125 135 Parameters.Add(new LookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of symbolic expression trees.")); 136 Parameters.Add(new SubScopesLookupParameter<DoubleValue>(AlphaParameterName, "Alpha parameter for linear scaling of the estimated values.")); 137 Parameters.Add(new SubScopesLookupParameter<DoubleValue>(BetaParameterName, "Beta parameter for linear scaling ot the estimated values.")); 126 138 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.")); 127 139 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.")); … … 135 147 public override IOperation Apply() { 136 148 ItemArray<SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue; 149 ItemArray<DoubleValue> alphas = AlphaParameter.ActualValue; 150 ItemArray<DoubleValue> betas = BetaParameter.ActualValue; 151 var scaledExpressions = from i in Enumerable.Range(0, expressions.Count()) 152 let expr = expressions[i] 153 let alpha = alphas[i].Value 154 let beta = betas[i].Value 155 select new { Expression = expr, Alpha = alpha, Beta = beta }; 137 156 DataAnalysisProblemData problemData = DataAnalysisProblemDataParameter.ActualValue; 138 157 #region update variable frequencies … … 156 175 double upperEstimationLimit = UpperEstimationLimit.Value; 157 176 double lowerEstimationLimit = LowerEstimationLimit.Value; 158 var currentBestExpression = (from expression in expressions177 var currentBestExpression = (from expression in scaledExpressions 159 178 let validationQuality = 160 SymbolicRegression MeanSquaredErrorEvaluator.Calculate(161 SymbolicExpressionTreeInterpreter, expression ,179 SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateWithScaling( 180 SymbolicExpressionTreeInterpreter, expression.Expression, 162 181 lowerEstimationLimit, upperEstimationLimit, 163 182 problemData.Dataset, problemData.TargetVariable.Value, 164 validationSamplesStart, validationSamplesEnd) 183 validationSamplesStart, validationSamplesEnd, 184 expression.Beta, expression.Alpha) 165 185 select new { Expression = expression, ValidationQuality = validationQuality }) 166 186 .OrderBy(x => x.ValidationQuality) … … 172 192 if (bestOfRunSolution == null) { 173 193 // no best of run solution yet -> make a solution from the currentBestExpression 174 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression , SymbolicExpressionTreeInterpreter, lowerEstimationLimit, upperEstimationLimit);194 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression.Expression, SymbolicExpressionTreeInterpreter, lowerEstimationLimit, upperEstimationLimit, currentBestExpression.Expression.Alpha, currentBestExpression.Expression.Beta); 175 195 } else { 176 196 // compare quality of current best with best of run solution … … 178 198 var bestOfRunValidationQuality = SimpleMSEEvaluator.Calculate(validationValues, estimatedValidationValues); 179 199 if (bestOfRunValidationQuality > currentBestExpression.ValidationQuality) { 180 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression , SymbolicExpressionTreeInterpreter, lowerEstimationLimit, upperEstimationLimit);200 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression.Expression, SymbolicExpressionTreeInterpreter, lowerEstimationLimit, upperEstimationLimit, currentBestExpression.Expression.Alpha, currentBestExpression.Expression.Beta); 181 201 } 182 202 } … … 186 206 187 207 private void UpdateBestOfRunSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, 188 double lowerEstimationLimit, double upperEstimationLimit) { 189 var newBestSolution = CreateDataAnalysisSolution(problemData, tree, interpreter, lowerEstimationLimit, upperEstimationLimit); 208 double lowerEstimationLimit, double upperEstimationLimit, 209 double alpha, double beta) { 210 var newBestSolution = CreateDataAnalysisSolution(problemData, tree, interpreter, lowerEstimationLimit, upperEstimationLimit, alpha, beta); 190 211 if (BestValidationSolutionParameter.ActualValue == null) 191 212 BestValidationSolutionParameter.ActualValue = newBestSolution; … … 215 236 } 216 237 217 private SymbolicRegressionSolution CreateDataAnalysisSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree expression, ISymbolicExpressionTreeInterpreter interpreter, 218 double lowerEstimationLimit, double upperEstimationLimit) { 219 var model = new SymbolicRegressionModel(interpreter, expression, problemData.InputVariables.Select(s => s.Value)); 238 private SymbolicRegressionSolution CreateDataAnalysisSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, 239 double lowerEstimationLimit, double upperEstimationLimit, 240 double alpha, double beta) { 241 var mainBranch = tree.Root.SubTrees[0].SubTrees[0]; 242 var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha); 243 244 // remove the main branch before cloning to prevent cloning of sub-trees 245 tree.Root.SubTrees[0].RemoveSubTree(0); 246 var scaledTree = (SymbolicExpressionTree)tree.Clone(); 247 // insert main branch into the original tree again 248 tree.Root.SubTrees[0].InsertSubTree(0, mainBranch); 249 // insert the scaled main branch into the cloned tree 250 scaledTree.Root.SubTrees[0].InsertSubTree(0, scaledMainBranch); 251 // create a new solution using the scaled tree 252 var model = new SymbolicRegressionModel(interpreter, scaledTree, problemData.InputVariables.Select(s => s.Value)); 220 253 return new SymbolicRegressionSolution(problemData, model, lowerEstimationLimit, upperEstimationLimit); 254 } 255 256 private SymbolicExpressionTreeNode MakeSum(SymbolicExpressionTreeNode treeNode, double alpha) { 257 var node = (new Addition()).CreateTreeNode(); 258 var alphaConst = MakeConstant(alpha); 259 node.AddSubTree(treeNode); 260 node.AddSubTree(alphaConst); 261 return node; 262 } 263 264 private SymbolicExpressionTreeNode MakeProduct(double beta, SymbolicExpressionTreeNode treeNode) { 265 var node = (new Multiplication()).CreateTreeNode(); 266 var betaConst = MakeConstant(beta); 267 node.AddSubTree(treeNode); 268 node.AddSubTree(betaConst); 269 return node; 270 } 271 272 private SymbolicExpressionTreeNode MakeConstant(double c) { 273 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 274 node.Value = c; 275 return node; 221 276 } 222 277 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r3528 r3532 111 111 set { MaxExpressionDepthParameter.Value = value; } 112 112 } 113 public IntValue MaxFunctionDefiningBranches { 114 get { return MaxFunctionDefiningBranchesParameter.Value; } 115 set { MaxFunctionDefiningBranchesParameter.Value = value; } 116 } 117 public IntValue MaxFunctionArguments { 118 get { return MaxFunctionArgumentsParameter.Value; } 119 set { MaxFunctionArgumentsParameter.Value = value; } 120 } 113 121 public SymbolicExpressionTreeCreator SolutionCreator { 114 122 get { return SolutionCreatorParameter.Value; } … … 166 174 : base() { 167 175 SymbolicExpressionTreeCreator creator = new ProbabilisticTreeCreator(); 168 var evaluator = new SymbolicRegression MeanSquaredErrorEvaluator();176 var evaluator = new SymbolicRegressionScaledMeanSquaredErrorEvaluator(); 169 177 var grammar = new ArithmeticExpressionGrammar(); 170 178 var globalGrammar = new GlobalSymbolicExpressionGrammar(grammar); … … 190 198 DataAnalysisProblemDataParameter.ValueChanged += new EventHandler(DataAnalysisProblemDataParameter_ValueChanged); 191 199 DataAnalysisProblemData.ProblemDataChanged += new EventHandler(DataAnalysisProblemData_Changed); 200 MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(ArchitectureParameter_Changed); 201 MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameter_Changed); 202 MaxFunctionDefiningBranchesParameter.ValueChanged += new EventHandler(ArchitectureParameter_Changed); 203 MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameter_Changed); 192 204 ParameterizeSolutionCreator(); 193 205 ParameterizeEvaluator(); … … 196 208 Initialize(); 197 209 } 210 198 211 199 212 [StorableConstructor] … … 214 227 UpdateGrammar(); 215 228 UpdatePartitioningParameters(); 229 } 230 231 void ArchitectureParameter_Changed(object sender, EventArgs e) { 232 var globalGrammar = FunctionTreeGrammar as GlobalSymbolicExpressionGrammar; 233 globalGrammar.MaxFunctionArguments = MaxFunctionArguments.Value; 234 globalGrammar.MaxFunctionDefinitions = MaxFunctionDefiningBranches.Value; 216 235 } 217 236
Note: See TracChangeset
for help on using the changeset viewer.