Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimization fails with np.longdouble and 'tnc' or 'l-bfgs' with nevo example #1

Closed
chrisconlon opened this issue Apr 26, 2018 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@chrisconlon
Copy link
Collaborator

chrisconlon commented Apr 26, 2018

Using Nevo dataset and np.longdouble precision fails under the 'l-bfgs-b' and 'tnc' solvers immediately errors out.

Works fine with 'knitro' and 'slsqp' solver.

pyblp.options.dtype = np.longdouble
pyblp.options.digits = 3
pyblp.options.verbose = True

nevo_results_lbfgs = nevo_problem.solve(nevo_sigma,nevo_pi,steps=1,optimization=pyblp.Optimization('l-bfgs-b'))
nevo_results_tnc = nevo_problem.solve(nevo_sigma,nevo_pi,steps=1,optimization=pyblp.Optimization('tnc'))

LBFGS trace:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-30-28ef3977a353> in <module>()
      1 ### L-BFGS+TNC fails with high precision numerics
----> 2 nevo_results_lbfgs = nevo_problem.solve(nevo_sigma,nevo_pi,steps=1,optimization=pyblp.Optimization('l-bfgs-b'))
      3 #nevo_results_tnc = nevo_problem.solve(nevo_sigma,nevo_pi,steps=1,optimization=pyblp.Optimization('tnc'))

~/anaconda3/lib/python3.6/site-packages/pyblp/problem.py in solve(self, sigma, pi, sigma_bounds, pi_bounds, delta, WD, WS, steps, optimization, custom_display, error_behavior, error_punishment, iteration, linear_costs, linear_fp, center_moments, se_type, processes)
    423             bounds = [p.bounds for p in parameter_info.unfixed]
    424             verbose = options.verbose and not custom_display
--> 425             theta = optimization._optimize(objective_function, theta, bounds, verbose=verbose)
    426             end_time = time.time()
    427             output("")

~/anaconda3/lib/python3.6/site-packages/pyblp/utilities/optimization.py in _optimize(self, objective_function, start_values, bounds, verbose)
    202             if self._supports_bounds:
    203                 minimize_kwargs['bounds'] = bounds
--> 204             return scipy.optimize.minimize(objective_function, start_values, **minimize_kwargs).x
    205 
    206         # set default Knitro options

~/anaconda3/lib/python3.6/site-packages/scipy/optimize/_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
    485     elif meth == 'l-bfgs-b':
    486         return _minimize_lbfgsb(fun, x0, args, jac, bounds,
--> 487                                 callback=callback, **options)
    488     elif meth == 'tnc':
    489         return _minimize_tnc(fun, x0, args, jac, bounds, callback=callback,

~/anaconda3/lib/python3.6/site-packages/scipy/optimize/lbfgsb.py in _minimize_lbfgsb(fun, x0, args, jac, bounds, disp, maxcor, ftol, gtol, eps, maxfun, maxiter, iprint, callback, maxls, **unknown_options)
    326         _lbfgsb.setulb(m, x, low_bnd, upper_bnd, nbd, f, g, factr,
    327                        pgtol, wa, iwa, task, iprint, csave, lsave,
--> 328                        isave, dsave, maxls)
    329         task_str = task.tostring()
    330         if task_str.startswith(b'FG'):

ValueError: failed to initialize intent(inout) array -- expected elsize=8 but got 16

TNC trace:

ValueError                                Traceback (most recent call last)
<ipython-input-31-df7d85ccaaa8> in <module>()
      1 ### L-BFGS+TNC fails with high precision numerics
      2 #nevo_results_lbfgs = nevo_problem.solve(nevo_sigma,nevo_pi,steps=1,optimization=pyblp.Optimization('l-bfgs-b'))
----> 3 nevo_results_tnc = nevo_problem.solve(nevo_sigma,nevo_pi,steps=1,optimization=pyblp.Optimization('tnc'))

~/anaconda3/lib/python3.6/site-packages/pyblp/problem.py in solve(self, sigma, pi, sigma_bounds, pi_bounds, delta, WD, WS, steps, optimization, custom_display, error_behavior, error_punishment, iteration, linear_costs, linear_fp, center_moments, se_type, processes)
    423             bounds = [p.bounds for p in parameter_info.unfixed]
    424             verbose = options.verbose and not custom_display
--> 425             theta = optimization._optimize(objective_function, theta, bounds, verbose=verbose)
    426             end_time = time.time()
    427             output("")

~/anaconda3/lib/python3.6/site-packages/pyblp/utilities/optimization.py in _optimize(self, objective_function, start_values, bounds, verbose)
    202             if self._supports_bounds:
    203                 minimize_kwargs['bounds'] = bounds
--> 204             return scipy.optimize.minimize(objective_function, start_values, **minimize_kwargs).x
    205 
    206         # set default Knitro options

~/anaconda3/lib/python3.6/site-packages/scipy/optimize/_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
    488     elif meth == 'tnc':
    489         return _minimize_tnc(fun, x0, args, jac, bounds, callback=callback,
--> 490                              **options)
    491     elif meth == 'cobyla':
    492         return _minimize_cobyla(fun, x0, args, constraints, **options)

~/anaconda3/lib/python3.6/site-packages/scipy/optimize/tnc.py in _minimize_tnc(fun, x0, args, jac, bounds, eps, scale, offset, mesg_num, maxCGit, maxiter, eta, stepmx, accuracy, minfev, ftol, xtol, gtol, rescale, disp, callback, **unknown_options)
    407                                         offset, messages, maxCGit, maxfun,
    408                                         eta, stepmx, accuracy, fmin, ftol,
--> 409                                         xtol, pgtol, rescale, callback)
    410 
    411     funv, jacv = func_and_grad(x)

ValueError: tnc: invalid gradient vector.
@jeffgortmaker jeffgortmaker self-assigned this Apr 27, 2018
@jeffgortmaker jeffgortmaker added the bug Something isn't working label Apr 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants