/** * @return The covariance matrix of the fit parameters. * @throws LMAMatrix.InvertException if the inversion of alpha fails. Note that even if the fit * does NOT throw the invert exception, this method can still do it, because here alpha is * inverted with lambda = 0. */ public double[][] getCovarianceMatrixOfStandardErrorsInParameters() throws LMAMatrix.InvertException { double[][] result = new double[parameters.length][parameters.length]; double oldLambda = lambda; lambda = 0; updateAlpha(); try { alpha.invert(); } catch (LMAMatrix.InvertException e) { // restore alpha just in case lambda = oldLambda; updateAlpha(); throw new LMAMatrix.InvertException( "Inverting alpha failed with lambda = 0\n" + e.getMessage()); } for (int i = 0; i < result.length; i++) { for (int j = 0; j < result.length; j++) { result[i][j] = alpha.getElement(i, j); } } alpha.invert(); lambda = oldLambda; updateAlpha(); return result; }
/** * Solves the increments array ( <code>this.da</code>) using alpha and beta. Then updates the * <code>this.incrementedParameters</code> array. NOTE: Inverts alpha. Call at least <code> * updateAlpha()</code> before calling this. */ protected void solveIncrements() throws LMAMatrix.InvertException { alpha.invert(); // throws InvertException if matrix is singular alpha.multiply(beta, da); for (int i = 0; i < parameters.length; i++) { incrementedParameters[i] = parameters[i] + da[i]; } }
/** Calculates all elements for <code>this.alpha</code>. */ protected void updateAlpha() { for (int i = 0; i < parameters.length; i++) { for (int j = 0; j < parameters.length; j++) { alpha.setElement(i, j, calculateAlphaElement(i, j)); } } }