2135b0efe977edbecd3cc4b28d9e50027e2929b6,scipy/optimize/optimize.py,,_minimize_newtoncg,#Any#Any#Any#Any#Any#Any#Any#Any#Any#Any#Any#Any#,1400

Before Change



        k2 = 0
        cg_maxiter = 20*len(x0)
        while (numpy.add.reduce(numpy.abs(ri)) > termcond) and (k2 < cg_maxiter):
            if fhess is None:
                if fhess_p is None:
                    Ap = approx_fhess_p(xk, psupi, fprime, epsilon)
                else:
                    Ap = fhess_p(xk, psupi, *args)
                    hcalls = hcalls + 1
            else:
                Ap = numpy.dot(A, psupi)
            // check curvature
            Ap = asarray(Ap).squeeze()  // get rid of matrices...
            curv = numpy.dot(psupi, Ap)
            if 0 <= curv <= 3 * float64eps:
                break
            elif curv < 0:
                if (i > 0):
                    break
                else:
                    // fall back to steepest descent direction
                    xsupi = dri0 / (-curv) * b
                    break
            alphai = dri0 / curv
            xsupi = xsupi + alphai * psupi
            ri = ri + alphai * Ap
            dri1 = numpy.dot(ri, ri)
            betai = dri1 / dri0
            psupi = -ri + betai * psupi
            i = i + 1
            dri0 = dri1          // update numpy.dot(ri,ri) for next time.
            k2 += 1

        if k2 >= cg_maxiter:
            // curvature keeps increasing, bail out
            break

After Change


            A = fhess(*(xk,) + args)
            hcalls = hcalls + 1

        for k2 in xrange(cg_maxiter):
            if numpy.add.reduce(numpy.abs(ri)) <= termcond:
                break
            if fhess is None:
                if fhess_p is None:
                    Ap = approx_fhess_p(xk, psupi, fprime, epsilon)
                else:
                    Ap = fhess_p(xk, psupi, *args)
                    hcalls = hcalls + 1
            else:
                Ap = numpy.dot(A, psupi)
            // check curvature
            Ap = asarray(Ap).squeeze()  // get rid of matrices...
            curv = numpy.dot(psupi, Ap)
            if 0 <= curv <= 3 * float64eps:
                break
            elif curv < 0:
                if (i > 0):
                    break
                else:
                    // fall back to steepest descent direction
                    xsupi = dri0 / (-curv) * b
                    break
            alphai = dri0 / curv
            xsupi = xsupi + alphai * psupi
            ri = ri + alphai * Ap
            dri1 = numpy.dot(ri, ri)
            betai = dri1 / dri0
            psupi = -ri + betai * psupi
            i = i + 1
            dri0 = dri1          // update numpy.dot(ri,ri) for next time.
        else:
            // curvature keeps increasing, bail out
            break

        pk = xsupi  // search direction is solution to system.
        gfk = -b    // gradient at xk

        try:
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: scipy/scipy
Commit Name: 2135b0efe977edbecd3cc4b28d9e50027e2929b6
Time: 2016-06-19
Author: denis@laxalde.org
File Name: scipy/optimize/optimize.py
Class Name:
Method Name: _minimize_newtoncg


Project Name: scipy/scipy
Commit Name: 04b8d87d6dfcca50c1244d0f012bbad1ab2e093c
Time: 2011-11-03
Author: johann.cohentanugi@gmail.com
File Name: scipy/optimize/linesearch.py
Class Name:
Method Name: scalar_search_wolfe1


Project Name: scipy/scipy
Commit Name: 04b8d87d6dfcca50c1244d0f012bbad1ab2e093c
Time: 2011-11-03
Author: johann.cohentanugi@gmail.com
File Name: scipy/optimize/linesearch.py
Class Name:
Method Name: scalar_search_wolfe2