Esempio n. 1
0
def run_leastsq_bound(problem, ftol, xtol, gtol, jac,
                      scaling=None, **kwargs):
    bounds, lb, ub = scipy_bounds(problem)

    if scaling is None:
        diag = np.ones_like(problem.x0)
    else:
        diag = None

    if jac in ['2-point', '3-point']:
        jac = None
    else:
        jac = problem.jac

    x, cov_x, info, mesg, ier = leastsqbound(
        problem.fun, problem.x0, bounds=bounds, full_output=True,
        Dfun=jac, ftol=ftol, xtol=xtol, gtol=gtol, diag=diag, **kwargs)

    x = make_strictly_feasible(x, lb, ub)
    f = problem.fun(x)
    g = problem.grad(x)
    optimality = CL_optimality(x, g, lb, ub)
    active = find_active_constraints(x, lb, ub)
    return (info['nfev'], optimality, 0.5 * np.dot(f, f),
            np.sum(active != 0), ier)
Esempio n. 2
0
def run_l_bfgs_b(problem, ftol, gtol, xtol, jac):
    bounds, l, u = scipy_bounds(problem)
    factr = ftol / np.finfo(float).eps
    if jac in ['2-point', '3-point']:
        grad = None
        approx_grad = True
    else:
        grad = problem.grad
        approx_grad = False
    x, cost, info = fmin_l_bfgs_b(
        problem.obj_value, problem.x0, fprime=grad, bounds=bounds,
        approx_grad=approx_grad, m=100, factr=factr, pgtol=gtol, iprint=-1)
    g = problem.grad(x)
    optimality = CL_optimality(x, g, l, u)
    active = find_active_constraints(x, l, u)
    return (info['funcalls'], optimality, cost, np.sum(active != 0),
            info['warnflag'])