-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
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 NaNsVersions 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