Exemplo n.º 1
0
    def __call__(self, function, point, state):
        """
    Computes Goldstein-Price step 
    """
        g = function.gradient(point)
        state["gradient"] = g
        G = function.hessian(point)
        state["hessian"] = G

        isPositiveDefinite = True
        d0 = None

        try:
            L = cholesky(G)
            d0 = n_solve(L.T, n_solve(L, -g))
        except:
            isPositiveDefinite = False

        if isPositiveDefinite:
            cosTheta = dot(d0, -g) / (norm(d0) * norm(g))
            if cosTheta >= self.nu:
                step = d0
            else:
                step = -g
        else:
            step = -g

        state["direction"] = step
        return step
Exemplo n.º 2
0
    def __call__(self, function, point, state):
        """
    Computes Goldstein-Price step 
    """
        g = function.gradient(point)
        state['gradient'] = g
        G = function.hessian(point)
        state['hessian'] = G

        isPositiveDefinite = True
        d0 = None

        try:
            L = cholesky(G)
            d0 = n_solve(L.T, n_solve(L, -g))
        except:
            isPositiveDefinite = False

        if isPositiveDefinite:
            cosTheta = dot(d0, -g) / (norm(d0) * norm(g))
            if cosTheta >= self.nu:
                step = d0
            else:
                step = -g
        else:
            step = -g

        state['direction'] = step
        return step
Exemplo n.º 3
0
  def __call__(self, function, point, state):
    """
    Computes Goldfeld step 
    """
    g = function.gradient(point)
    state['gradient'] = g
    G = function.hessian(point)
    state['hessian'] = G
    c = 1e-8 # is this one best?
    
    d0 = None

    try:
        L = cholesky(G)
        # reach here => isPositiveDefinite = True
        step = n_solve(L.T, n_solve(L, -g))
    except:
        # isPositiveDefinite = False
        G_eigvals = eigvalsh(G)
        minEig = min(G_eigvals)
        if minEig < 0:
            shift = -minEig + c
            
            #avoiding sparse case with big nVars
            for i in xrange(point):  G[i,i] += shift
                
        step = n_solve(G, -g)

    state['direction'] = step
    return step
Exemplo n.º 4
0
    def __call__(self, function, point, state):
        """
    Computes Goldfeld step
    """
        g = function.gradient(point)
        state['gradient'] = g
        G = function.hessian(point)
        state['hessian'] = G
        c = 1e-8  # is this one best?

        d0 = None

        try:
            L = cholesky(G)
            # reach here => isPositiveDefinite = True
            step = n_solve(L.T, n_solve(L, -g))
        except:
            # isPositiveDefinite = False
            G_eigvals = eigvalsh(G)
            minEig = min(G_eigvals)
            if minEig < 0:
                shift = -minEig + c

                #avoiding sparse case with big nVars
                for i in xrange(point):
                    G[i, i] += shift

            step = n_solve(G, -g)

        state['direction'] = step
        return step