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

Exponential CDF gradient is failing #5289

Closed
AlexAndorra opened this issue Dec 27, 2021 · 1 comment · Fixed by #5374
Closed

Exponential CDF gradient is failing #5289

AlexAndorra opened this issue Dec 27, 2021 · 1 comment · Fixed by #5374
Assignees

Comments

@AlexAndorra
Copy link
Contributor

Description of your problem

The gradient of the Exponential distribution in PyMC is failing because it contains missing or infinite values.
If you use the new find_constrained_prior function for instance:

pm.find_constrained_prior(pm.Exponential, lower=0, upper=1, init_guess={"lam": 1})

you get a ValueError: array must not contain infs or NaNs

Complete error traceback
ValueError                                Traceback (most recent call last)
<ipython-input-3-1eea11105ccf> in <module>
----> 1 pm.find_constrained_prior(pm.Exponential, lower=0, upper=1, init_guess={"lam": 1})

~/tptm_alex/pymc/pymc/func_utils.py in find_constrained_prior(distribution, lower, upper, init_guess, mass, fixed_params)
    112         jac = "2-point"
    113
--> 114     opt = optimize.least_squares(cdf_error_fn, x0=list(init_guess.values()), jac=jac)
    115     if not opt.success:
    116         raise ValueError("Optimization of parameters failed.")

~/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/scipy/optimize/_lsq/least_squares.py in least_squares(fun, x0, jac, bounds, method, ftol, xtol, gtol, x_scale, loss, f_scale, diff_step, tr_solver, tr_options, jac_sparsity, max_nfev, verbose, args, kwargs)
    926
    927     elif method == 'trf':
--> 928         result = trf(fun_wrapped, jac_wrapped, x0, f0, J0, lb, ub, ftol, xtol,
    929                      gtol, max_nfev, x_scale, loss_function, tr_solver,
    930                      tr_options.copy(), verbose)

~/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/scipy/optimize/_lsq/trf.py in trf(fun, jac, x0, f0, J0, lb, ub, ftol, xtol, gtol, max_nfev, x_scale, loss_function, tr_solver, tr_options, verbose)
    117     # functions are kept the most readable.
    118     if np.all(lb == -np.inf) and np.all(ub == np.inf):
--> 119         return trf_no_bounds(
    120             fun, jac, x0, f0, J0, ftol, xtol, gtol, max_nfev, x_scale,
    121             loss_function, tr_solver, tr_options, verbose)

~/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/scipy/optimize/_lsq/trf.py in trf_no_bounds(fun, jac, x0, f0, J0, ftol, xtol, gtol, max_nfev, x_scale, loss_function, tr_solver, tr_options, verbose)
    465         if tr_solver == 'exact':
    466             J_h = J * d
--> 467             U, s, V = svd(J_h, full_matrices=False)
    468             V = V.T
    469             uf = U.T.dot(f)

~/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/scipy/linalg/decomp_svd.py in svd(a, full_matrices, compute_uv, overwrite_a, check_finite, lapack_driver)
    106
    107     """
--> 108     a1 = _asarray_validated(a, check_finite=check_finite)
    109     if len(a1.shape) != 2:
    110         raise ValueError('expected matrix')

~/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/scipy/_lib/_util.py in _asarray_validated(a, check_finite, sparse_ok, objects_ok, mask_ok, as_inexact)
    291             raise ValueError('masked arrays are not supported')
    292     toarray = np.asarray_chkfinite if check_finite else np.asarray
--> 293     a = toarray(a)
    294     if not objects_ok:
    295         if a.dtype is np.dtype('O'):

~/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/numpy/lib/function_base.py in asarray_chkfinite(a, dtype, order)
    486     a = asarray(a, dtype=dtype, order=order)
    487     if a.dtype.char in typecodes['AllFloat'] and not np.isfinite(a).all():
--> 488         raise ValueError(
    489             "array must not contain infs or NaNs")
    490     return a

ValueError: array must not contain infs or NaNs

Versions and main components

  • PyMC/PyMC3 Version: dev version
  • Aesara/Theano Version: 2.3.3
  • Python Version: 3.9.7
  • Operating system: MacOS
  • How did you install PyMC/PyMC3: local install
@ricardoV94 ricardoV94 changed the title Exponential gradient is failing Exponential CDF gradient is failing Dec 27, 2021
@ricardoV94 ricardoV94 added the needs info Additional information required label Dec 27, 2021
@ricardoV94 ricardoV94 added pytensor and removed needs info Additional information required labels Jan 5, 2022
@ricardoV94 ricardoV94 self-assigned this Jan 5, 2022
@ricardoV94
Copy link
Member

This should be fixed by aesara-devs/aesara#725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants