public void iterate ( ) { // build covmat out of fitting matrix by multiplying diagonal elements with // 1+lambda for ( int i = 0 ; i < numfit ; i ++ ) { System . arraycopy ( alpha [ i ] , 0 , covmat [ i ] , 0 , numfit ) ; covmat [ i ] [ i ] *= ( 1.0 + lambda ) ; } // Solve the equation system (Gauss-Jordan) LinearEquationSystem ls = new LinearEquationSystem ( covmat , beta ) ; ls . solveByTotalPivotSearch ( ) ; // update covmat with the inverse covmat = ls . getCoefficents ( ) ; // and deltaparams with the solution vector deltaparams = ls . getRHS ( ) ; // deltaparams = beta; for ( int i = 0 , i2 = 0 ; i < numparams ; i ++ ) { if ( dofit [ i ] ) { paramstry [ i ] = params [ i ] + deltaparams [ i2 ++ ] ; } } double newchisq = simulateParameters ( paramstry ) ; // have the results improved? if ( newchisq < chisq ) { // TODO: Do we need a larger limit than MIN_NORMAL? if ( lambda * 0.1 > Double . MIN_NORMAL ) { lambda *= 0.1 ; } chisq = newchisq ; // keep modified covmat as new alpha matrix // and da as new beta for ( int i = 0 ; i < numfit ; i ++ ) { System . arraycopy ( covmat [ i ] , 0 , alpha [ i ] , 0 , numfit ) ; beta [ i ] = deltaparams [ i ] ; } System . arraycopy ( paramstry , 0 , params , 0 , numparams ) ; } else { // TODO: Do we need a larger limit than MAX_VALUE? // Does it ever make sense to go as far up? // Anyway, this should prevent overflows. if ( lambda * 10 < Double . MAX_VALUE ) { lambda *= 10 ; } } }
Perform an iteration of the approximation loop .