- Timestamp:
- 07/13/19 10:04:28 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/ConstrainedConstantOptimizationEvaluator.cs
r17006 r17136 153 153 154 154 if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) { 155 var evaluationRows = GenerateRowsToEvaluate(); 156 quality = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, double.MinValue, double.MaxValue, ProblemDataParameter.ActualValue, evaluationRows, applyLinearScaling: false); 155 throw new NotSupportedException(); 157 156 } 158 157 … … 165 164 166 165 } else { 167 var evaluationRows = GenerateRowsToEvaluate(); 168 quality = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, double.MinValue, double.MaxValue, ProblemDataParameter.ActualValue, evaluationRows, applyLinearScaling: false); 166 throw new NotSupportedException(); 169 167 } 170 168 QualityParameter.ActualValue = new DoubleValue(quality); … … 292 290 // buffers for calculate_jacobian 293 291 var target = problemData.TargetVariableTrainingValues.ToArray(); 292 var targetVariance = target.VariancePop(); 294 293 var fi_eval = new double[target.Length]; 295 294 var jac_eval = new double[target.Length, thetaValues.Count]; … … 337 336 try { 338 337 alglib.minnscreate(thetaValues.Count, thetaValues.ToArray(), out state); 339 // alglib.minnssetalgoslp(state); // SLP is more robust but slower340 338 alglib.minnssetbc(state, thetaValues.Select(_ => -10000.0).ToArray(), thetaValues.Select(_ => +10000.0).ToArray()); 341 339 alglib.minnssetcond(state, 1E-7, maxIterations); … … 353 351 counter.GradientEvaluations += rep.nfev; 354 352 355 if (rep.terminationtype != -8) {353 if (rep.terminationtype > 0) { 356 354 // update parameters in tree 357 355 var pIdx = 0; … … 363 361 } 364 362 } 365 366 363 // note: we keep the optimized constants even when the tree is worse. 367 364 } 368 365 if (Math.Abs(rep.nlcerr) > 0.01) return targetVariance; // constraints are violated 369 366 } catch (ArithmeticException) { 370 // eval MSE of original tree 371 return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false); 372 367 return targetVariance; 373 368 } catch (alglib.alglibexception) { 374 369 // eval MSE of original tree 375 return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false);370 return targetVariance; 376 371 } 377 372 } else if (solver.Contains("minnlc")) { … … 413 408 // note: we keep the optimized constants even when the tree is worse. 414 409 } 410 if (Math.Abs(rep.nlcerr) > 0.01) return targetVariance; // constraints are violated 415 411 416 412 } catch (ArithmeticException) { 417 // eval MSE of original tree 418 return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false); 419 413 return targetVariance; 420 414 } catch (alglib.alglibexception) { 421 // eval MSE of original tree 422 return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false); 415 return targetVariance; 423 416 } 424 417 } else { … … 428 421 429 422 // evaluate tree with updated constants 430 return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false); 423 var residualVariance = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false); 424 return Math.Min(residualVariance, targetVariance); 431 425 } 432 426
Note: See TracChangeset
for help on using the changeset viewer.