{"record":{"id":"90877f97eca64928","repo":"stanfordnlp/CoreNLP","slug":"qninfo-update-problem-with-diagonal-update","errorCode":null,"errorMessage":"QNInfo:update() : PROBLEM WITH DIAGONAL UPDATE","messagePattern":"QNInfo:update\\(\\) : PROBLEM WITH DIAGONAL UPDATE","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/optimization/QNMinimizer.java","lineNumber":776,"sourceCode":"        final double newSi = newS[i];\n        sDs += newSi * (d[i] *= gamma) * newSi;\n      }\n      // This diagonal update was introduced by Andrew Bradley\n      for(int i = 0; i < d.length; i++) {\n        final double di = d[i], newSi = newS[i], newYi = newY[i];\n        d[i] = (1 - di * newSi * newSi / sDs) * di + newYi * newYi / sy;\n      }\n      // Here we make sure that the diagonal is alright\n      double minD = d[0], maxD = minD;\n      for(int i = 1; i < d.length; i++) {\n        final double v = d[i];\n        minD = v < minD ? v : minD;\n        maxD = v > maxD ? v : maxD;\n      }\n\n      // If things have gone bad, just fill with the SCALAR approx.\n      if(minD <= 0 || Double.isInfinite(maxD) || maxD / minD > 1e12) {\n        log.warn(\"QNInfo:update() : PROBLEM WITH DIAGONAL UPDATE\");\n        Arrays.fill(d, yy / sy);\n      }\n\n      // If s is already of size mem, remove the oldest vector and free it up.\n      if(used == mem)\n        removeFirst();\n\n      // Actually add the pair.\n      s[used] = newS;\n      y[used] = newY;\n      rho[used] = 1 / sy;\n      ++used;\n\n      return used;\n    } // end update\n  } // end class DiagonalQNInfo\n\n  public void setHistory(List<double[]> s, List<double[]> y) {","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/QNMinimizer.java#L758-L794","documentation":"QNMinimizer.QNInfo.update maintains a diagonal inverse-Hessian approximation built from s/y vector pairs. If the computed diagonal contains non-positive entries, infinities, or an extreme condition ratio (>1e12), the update is deemed corrupt and the diagonal is reset to the scalar approximation yy/sy with a warning.","triggerScenarios":"update() called after a line search producing degenerate s/y pairs — e.g. y = g_new - g_old ≈ 0, non-positive curvature, or exploding values from an ill-conditioned objective or bad step size.","commonSituations":"Training with nearly zero gradient change between iterations; features on wildly different scales; too-large steps causing oscillation and bad curvature estimates.","solutions":["Scale/normalize input features so the objective is well-conditioned.","Check line-search/step-size settings and verify the gradient contains no NaNs/infinities before the update.","Verify the function/diffFunction implementation returns correct values and gradients (a buggy gradient yields corrupt s/y pairs).","The minimizer self-recovers by filling with yy/sy — confirm training proceeds and converges; the warning alone is not fatal."],"exampleFix":"// before: unscaled features spanning [0, 1e9]\ndouble[] x = qn.minimize(f, 1e-4, initial, maxIters);\n// after — scale features to comparable ranges first\nfor (int i = 0; i < initial.length; i++) initial[i] /= featureScale[i];\ndouble[] x = qn.minimize(f, 1e-4, initial, maxIters);","handlingStrategy":"validation","validationCode":"for (double v : grad) {\n  if (Double.isNaN(v) || Double.isInfinite(v)) {\n    throw new IllegalStateException(\"bad gradient value: \" + v);\n  }\n}","typeGuard":null,"tryCatchPattern":"// the minimizer already recovers by resetting d to yy/sy;\n// wrap the training run and retrain with scaled features if the warning recurs\nif (logWarningsContain(\"PROBLEM WITH DIAGONAL UPDATE\")) {\n  retrainWithNormalizedFeatures();\n}","preventionTips":["Normalize features to comparable scales.","Verify diffFunction returns finite values.","Tune step size / line search parameters."],"tags":["java","optimization","numerical","l-bfgs"],"backgroundTag":"internal-invariant-violation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}