Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/13/19 10:04:28 (5 years ago)
Author:
gkronber
Message:

#2994: return a bad quality if constraints are violated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/ConstrainedConstantOptimizationEvaluator.cs

    r17006 r17136  
    153153
    154154        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();
    157156        }
    158157
     
    165164
    166165      } 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();
    169167      }
    170168      QualityParameter.ActualValue = new DoubleValue(quality);
     
    292290      // buffers for calculate_jacobian
    293291      var target = problemData.TargetVariableTrainingValues.ToArray();
     292      var targetVariance = target.VariancePop();
    294293      var fi_eval = new double[target.Length];
    295294      var jac_eval = new double[target.Length, thetaValues.Count];
     
    337336        try {
    338337          alglib.minnscreate(thetaValues.Count, thetaValues.ToArray(), out state);
    339           // alglib.minnssetalgoslp(state);        // SLP is more robust but slower
    340338          alglib.minnssetbc(state, thetaValues.Select(_ => -10000.0).ToArray(), thetaValues.Select(_ => +10000.0).ToArray());
    341339          alglib.minnssetcond(state, 1E-7, maxIterations);
     
    353351          counter.GradientEvaluations += rep.nfev;
    354352
    355           if (rep.terminationtype != -8) {
     353          if (rep.terminationtype > 0) {
    356354            // update parameters in tree
    357355            var pIdx = 0;
     
    363361              }
    364362            }
    365 
    366363            // note: we keep the optimized constants even when the tree is worse.
    367364          }
    368 
     365          if (Math.Abs(rep.nlcerr) > 0.01) return targetVariance; // constraints are violated
    369366        } catch (ArithmeticException) {
    370           // eval MSE of original tree
    371           return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false);
    372 
     367          return targetVariance;
    373368        } catch (alglib.alglibexception) {
    374369          // eval MSE of original tree
    375           return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false);
     370          return targetVariance;
    376371        }
    377372      } else if (solver.Contains("minnlc")) {
     
    413408            // note: we keep the optimized constants even when the tree is worse.
    414409          }
     410          if (Math.Abs(rep.nlcerr) > 0.01) return targetVariance; // constraints are violated
    415411
    416412        } catch (ArithmeticException) {
    417           // eval MSE of original tree
    418           return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false);
    419 
     413          return targetVariance;
    420414        } catch (alglib.alglibexception) {
    421           // eval MSE of original tree
    422           return SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling: false);
     415          return targetVariance;
    423416        }
    424417      } else {
     
    428421
    429422      // 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);
    431425    }
    432426
Note: See TracChangeset for help on using the changeset viewer.