Changeset 17311 for branches/2994AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/ConstrainedNLSInternal.cs
 Timestamp:
 10/04/19 09:34:18 (3 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/2994AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/ConstrainedNLSInternal.cs
r17240 r17311 41 41 public double[] BestConstraintValues => bestConstraintValues; 42 42 43 44 // for debugging (must be in the same order as processed below) 45 public IEnumerable<string> ConstraintDescriptions { 46 get { 47 foreach (var elem in problemData.IntervalConstraints.Constraints) { 48 if (!elem.Enabled) continue; 49 if (elem.Interval.UpperBound < double.PositiveInfinity) { 50 yield return elem.Expression + " < " + elem.Interval.UpperBound; 51 } 52 if (elem.Interval.LowerBound > double.NegativeInfinity) { 53 yield return "" + elem.Expression + " < " + (1) * elem.Interval.LowerBound; 54 } 55 } 56 } 57 } 58 43 59 public bool CheckGradient { get; internal set; } 44 60 … … 47 63 private SymbolicDataAnalysisExpressionTreeLinearInterpreter interpreter; 48 64 private readonly NLOpt.nlopt_func calculateObjectiveDelegate; // must hold the delegate to prevent GC 49 private readonly NLOpt.nlopt_precond preconditionDelegate;65 // private readonly NLOpt.nlopt_precond preconditionDelegate; 50 66 private readonly IntPtr[] constraintDataPtr; // must hold the objects to prevent GC 51 67 private readonly NLOpt.nlopt_func[] calculateConstraintDelegates; // must hold the delegates to prevent GC … … 217 233 // throw new InvalidOperationException($"NLOpt failed {res} {NLOpt.nlopt_get_errmsg(nlopt)}"); 218 234 return; 219 } else if (minf <= bestError) {235 } else if (minf <= bestError) { 220 236 bestSolution = x; 221 237 bestError = minf; … … 302 318 303 319 if (double.IsNaN(sse)) { 304 if (grad!=null) Array.Clear(grad, 0, grad.Length);320 if (grad != null) Array.Clear(grad, 0, grad.Length); 305 321 return double.MaxValue; 306 322 } … … 367 383 UpdateThetaValues(curX); 368 384 var intervalEvaluator = new IntervalEvaluator(); 385 var refIntervalEvaluator = new IntervalInterpreter(); 386 369 387 var constraintData = Marshal.PtrToStructure<ConstraintData>(data); 370 388 … … 373 391 var interval = intervalEvaluator.Evaluate(constraintData.Tree, dataIntervals, constraintData.ParameterNodes, 374 392 out double[] lowerGradient, out double[] upperGradient); 393 394 var refInterval = refIntervalEvaluator.GetSymbolicExpressionTreeInterval(constraintData.Tree, dataIntervals); 395 if (Math.Abs(interval.LowerBound  refInterval.LowerBound) > Math.Abs(interval.LowerBound) * 1e4) throw new InvalidProgramException($"Intervals don't match. {interval.LowerBound} <> {refInterval.LowerBound}"); 396 if (Math.Abs(interval.UpperBound  refInterval.UpperBound) > Math.Abs(interval.UpperBound) * 1e4) throw new InvalidProgramException($"Intervals don't match. {interval.UpperBound} <> {refInterval.UpperBound}"); 375 397 376 398 // we transformed this to a constraint c(x) <= 0, so only the upper bound is relevant for us … … 405 427 UpdateConstraintViolations(constraintData.Idx, interval.UpperBound); 406 428 if (double.IsNaN(interval.UpperBound)) { 407 Array.Clear(grad, 0, grad.Length);429 if(grad!=null)Array.Clear(grad, 0, grad.Length); 408 430 return double.MaxValue; 409 431 } else return interval.UpperBound;
Note: See TracChangeset
for help on using the changeset viewer.