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 = 0.5 * problem.grad(x) optimality = CL_optimality(x, g, lb, ub) active = find_active_constraints(x, lb, ub) return info['nfev'], optimality, np.dot(f, f), np.sum(active != 0), ier
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, obj_value, 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 = 0.5 * problem.grad(x) optimality = CL_optimality(x, g, l, u) active = find_active_constraints(x, l, u) return (info['funcalls'], optimality, obj_value, np.sum(active != 0), info['warnflag'])
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, obj_value, 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 = 0.5 * problem.grad(x) optimality = CL_optimality(x, g, l, u) active = find_active_constraints(x, l, u) return (info['funcalls'], optimality, obj_value, np.sum(active != 0), info['warnflag'])
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 = 0.5 * problem.grad(x) optimality = CL_optimality(x, g, lb, ub) active = find_active_constraints(x, lb, ub) return info['nfev'], optimality, np.dot(f, f), np.sum(active != 0), ier