-
Notifications
You must be signed in to change notification settings - Fork 62
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
Issue using .fit() #94
Comments
I haven't seen this before. It's possible something I use from scipy has
changed.
Can you post or send me a full stack trace of the error? Just so I can see
which line in pwlf is triggering this use l issue.
…On Thu, Apr 14, 2022, 06:40 aaronnkang ***@***.***> wrote:
Every time I try used .fit(n) to fit a pwlf with n number of segments I
get the following error:
The map-like callable must be of the form f(func, iterable), returning a
sequence of numbers the same length as 'iterable'
Any ideas?
—
Reply to this email directly, view it on GitHub
<#94>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADJ5Z4L77G6XVACZ2NXGASTVFAN6FANCNFSM5TN2BDSA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Can you tell me which version of python and scipy are you using?
…On Thu, Apr 14, 2022, 07:23 Charles Jekel ***@***.***> wrote:
I haven't seen this before. It's possible something I use from scipy has
changed.
Can you post or send me a full stack trace of the error? Just so I can see
which line in pwlf is triggering this use l issue.
On Thu, Apr 14, 2022, 06:40 aaronnkang ***@***.***> wrote:
> Every time I try used .fit(n) to fit a pwlf with n number of segments I
> get the following error:
>
> The map-like callable must be of the form f(func, iterable), returning a
> sequence of numbers the same length as 'iterable'
>
> Any ideas?
>
> —
> Reply to this email directly, view it on GitHub
> <#94>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ADJ5Z4L77G6XVACZ2NXGASTVFAN6FANCNFSM5TN2BDSA>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
|
I am getting the same issue, it appears the DifferentialEvolutionSolver is generating infs/nans that cause the error. I am running Python 3.9.13 and Scipy 1.9.1. ValueError Traceback (most recent call last) File ~\anaconda3\envs\gee\lib\site-packages\scipy_lib_util.py:407, in _FunctionWrapper.call(self, x) File ~\anaconda3\envs\gee\lib\site-packages\pwlf\pwlf.py:590, in PiecewiseLinFit.fit_with_breaks_opt(self, var) File ~\anaconda3\envs\gee\lib\site-packages\pwlf\pwlf.py:1491, in PiecewiseLinFit.lstsq(self, A, calc_slopes) File ~\anaconda3\envs\gee\lib\site-packages\scipy\linalg_basic.py:1135, in lstsq(a, b, cond, overwrite_a, overwrite_b, check_finite, lapack_driver) File ~\anaconda3\envs\gee\lib\site-packages\scipy_lib_util.py:287, in _asarray_validated(a, check_finite, sparse_ok, objects_ok, mask_ok, as_inexact) File ~\anaconda3\envs\gee\lib\site-packages\numpy\lib\function_base.py:627, in asarray_chkfinite(a, dtype, order) ValueError: array must not contain infs or NaNs The above exception was the direct cause of the following exception: RuntimeError Traceback (most recent call last) Cell In [25], line 30, in process_point(dataset, latitude, longitude) Cell In [27], line 60, in fit_pwlf(df, break_guesses) File ~\anaconda3\envs\gee\lib\site-packages\pwlf\pwlf.py:771, in PiecewiseLinFit.fit(self, n_segments, x_c, y_c, bounds, **kwargs) File ~\anaconda3\envs\gee\lib\site-packages\scipy\optimize_differentialevolution.py:392, in differential_evolution(func, bounds, args, strategy, maxiter, popsize, tol, mutation, recombination, seed, callback, disp, polish, init, atol, updating, workers, constraints, x0, integrality, vectorized) File ~\anaconda3\envs\gee\lib\site-packages\scipy\optimize_differentialevolution.py:984, in DifferentialEvolutionSolver.solve(self) File ~\anaconda3\envs\gee\lib\site-packages\scipy\optimize_differentialevolution.py:1123, in DifferentialEvolutionSolver._calculate_population_energies(self, population) RuntimeError: The map-like callable must be of the form f(func, iterable), returning a sequence of numbers the same length as 'iterable' |
Thanks for that full traceback. I think I know what the issue is, it's this block of code in the lstsq fit try:
ssr = self.lstsq(A)
except linalg.LinAlgError:
# the computation could not converge!
# on an error, return ssr = np.print_function
# You might have a singular Matrix!!!
ssr = np.inf
if ssr is None:
ssr = np.inf
# something went wrong...
self.ssr = ssr The new version of DE seems not to be able to handle np.inf. I have not been following how DE has been changing in scipy. It has gone through several changes throughout the years. It might be a bug with scipy's DE if this used to be supported. As a hotfix, can you try using a very very big number instead of np.inf? |
Sorry for the false alarm, after further exploration, I discovered my preprocessing was generating a NaN that was causing the issue. The code appears to work fine as is. |
Every time I try use .fit(n) to fit a pwlf with n number of segments I get the following error:
The map-like callable must be of the form f(func, iterable), returning a sequence of numbers the same length as 'iterable'
Any ideas?
The text was updated successfully, but these errors were encountered: