# Check second partial derivatives in turn. for i in range(n): xph = self.x.copy() xph[i] += h xmh = self.x.copy() xmh[i] -= h dgdx = (nlp.igrad(k, xph) - nlp.igrad(k, xmh)) / (2 * h) for j in range(i + 1): dgjdxi = dgdx[j] err = abs(Hk[i, j] - dgjdxi) / (1 + abs(Hk[i, j])) line = self.d2fmt % (k + 1, i, j, Hk[i, j], dgjdxi, err) if verbose: sys.stderr.write(line) if err > self.tol: errs.append(line) return errs if __name__ == '__main__': import sys from nlpy.model import AmplModel nlp = AmplModel(sys.argv[1]) print 'Checking at x = ', nlp.x0 derchk = DerivativeChecker(nlp, nlp.x0) derchk.check(verbose=True) nlp.close()
if err > 1.0e-12: err_matvec += 1 print 'Inaccurate matvec:' print hp1 print hp2 print 'Found %d inaccurate matvecs.' % err_matvec # Solve problem # TRIP.SolveOuter() # Display final statistics # print 'Final variables:'; print TRIP.x # print 'Final multipliers:'; print TRIP.z # print # print 'Optimal: ', TRIP.optimal # print 'Variables: ', TRIP.nlp.n # print '# lower, upper, 2-sided bounds: %-d, %-d, %-d' % \ # (TRIP.nlowerB, TRIP.nupperB, TRIP.nrangeB) # print 'Primal feasibility error = %15.7e' % TRIP.pRes # print 'Dual feasibility error = %15.7e' % TRIP.dRes # print 'Complementarity error = %15.7e' % TRIP.cRes # print 'Number of function evals = %d' % TRIP.nlp.feval # print 'Number of gradient evals = %d' % TRIP.nlp.geval # print 'Number of Hessian evals = %d' % TRIP.nlp.Heval # print 'Number of matvec products = %d' % TRIP.nlp.Hprod # print 'Final objective value = %15.7e' % TRIP.f # print 'Solution time: ', TRIP.tsolve nlp.close()
# Check for equality-constrained problem. n_ineq = nlp.nlowerC + nlp.nupperC + nlp.nrangeC if nlp.nbounds > 0 or n_ineq > 0: msg = '%s has %d bounds and %d inequality constraints\n' log.error(msg % (nlp.name, nlp.nbounds, n_ineq)) error = True else: ProblemName = os.path.basename(ProblemName) if ProblemName[-3:] == '.nl': ProblemName = ProblemName[:-3] t_setup, funn = pass_to_funnel(nlp, **opts) if multiple_problems: log.info(fmt % (ProblemName, funn.niter, funn.nlp.feval, funn.f, funn.dResid, funn.pResid, t_setup, funn.tsolve, funn.optimal)) nlp.close() # Close model. if not multiple_problems and not error: # Output final statistics log.info('--------------------------------') log.info('Funnel: End of Execution') log.info(' Problem : %-s' % ProblemName) log.info(' Number of variables : %-d' % nlp.n) log.info(' Number of linear constraints : %-d' % nlp.nlin) log.info(' Number of general constraints: %-d' % (nlp.m - nlp.nlin)) log.info(' Initial/Final Objective : %-g/%-g' % (funn.f0, funn.f)) log.info(' Number of iterations : %-d' % funn.niter) log.info(' Number of function evals : %-d' % funn.nlp.feval) log.info(' Number of gradient evals : %-d' % funn.nlp.geval) #log.info(' Number of Hessian evals : %-d' % funn.nlp.Heval) log.info(' Number of Hessian matvecs : %-d' % funn.nlp.Hprod)