scipy: ENH: `interpolate.make_splrep`: fails for ill-conditioned problems
Describe your issue.
make_splrep( x, y, w=weights, k=order, s=smoothness, )
with:
x = 20.00000 153.81000 175.57000 202.47000 237.11000 253.61000 258.56000 273.40000 284.54000 293.61000 298.56000 301.86000 305.57000 307.22000 308.45000 310.10000 310.10000 310.50000
y = 53.00000 49.50000 48.60000 46.80000 43.20000 40.32000 39.60000 36.00000 32.40000 28.80000 25.20000 21.60000 18.00000 14.40000 10.80000 7.20000 3.60000 0.00000
w = 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723 1.38723
k = 2
s = 12.0
returns a RuntimeError ‘Internal error. Please report it to SciPy developers’.
Note that in this case x includes two duplicated values.
Running this without specifying the weights, produces a valid bspline object.
Also note that this same example run with the old splrep() and the same arguments, does not fail and produces a valid (t,c,k) for a bspline object.
Reproducing Code Example
from scipy.interpolate import make_splrep
x = [20.00000,
153.81000,
175.57000,
202.47000,
237.11000,
253.61000,
258.56000,
273.40000,
284.54000,
293.61000,
298.56000,
301.86000,
305.57000,
307.22000,
308.45000,
310.10000,
310.10000,
310.50000]
y = [53.00000,
49.50000,
48.60000,
46.80000,
43.20000,
40.32000,
39.60000,
36.00000,
32.40000,
28.80000,
25.20000,
21.60000,
18.00000,
14.40000,
10.80000,
7.20000,
3.60000,
0.00000]
w = [1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723,
1.38723]
k = 2
s = 12.0
make_splrep(
x,
y,
w=weights,
k=order,
s=smoothness,
)
Error message
networkmodelconnector.exceptions.BSplineFitException: Internal error. Please report it to SciPy developers.
SciPy/NumPy/Python version and system information
1.15.2 1.26.4 sys.version_info(major=3, minor=11, micro=11, releaselevel='final', serial=0)
Build Dependencies:
blas:
detection method: extraframeworks
found: true
include directory: unknown
lib directory: unknown
name: Accelerate
openblas configuration: unknown
pc file directory: unknown
version: unknown
lapack:
detection method: extraframeworks
found: true
include directory: unknown
lib directory: unknown
name: Accelerate
openblas configuration: unknown
pc file directory: unknown
version: unknown
pybind11:
detection method: config-tool
include directory: unknown
name: pybind11
version: 2.13.6
Compilers:
c:
commands: cc
linker: ld64
name: clang
version: 15.0.0
c++:
commands: c++
linker: ld64
name: clang
version: 15.0.0
cython:
commands: cython
linker: cython
name: cython
version: 3.0.12
fortran:
commands: gfortran
linker: ld64
name: gcc
version: 13.3.0
pythran:
include directory: ../../../../../../private/var/folders/2s/h6hvv9ps03xgz_krkkstvq_r0000gn/T/pip-build-env-p7gx8hhw/overlay/lib/python3.11/site-packages/pythran
version: 0.17.0
Machine Information:
build:
cpu: aarch64
endian: little
family: aarch64
system: darwin
cross-compiled: false
host:
cpu: aarch64
endian: little
family: aarch64
system: darwin
Python Information:
path: /private/var/folders/2s/h6hvv9ps03xgz_krkkstvq_r0000gn/T/cibw-run-4oaw7jjs/cp311-macosx_arm64/build/venv/bin/python
version: '3.11'
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (13 by maintainers)
Several things seem to be going on here.
First, this OP statement does not seem to be correct:
Using
x,yandwfrom the OP,So the weighted problem is ill-defined. The unweighted problem, however
splrepdoes produce a non-nan result. Moreover, for the unweighted problem,make_splrepis equivalent tosplrep:Could you please confirm or clarify @jamesuber ? It’d be helpful to see a case where
splrepproduces a non-nan result butmake_splrepfails.Second, decreasing the value of
sbelow some threshold ,splrepstarts emitting a warning (+returns nans):At the same threshold,
make_splrepfails with an “Internal SciPy error”. This is bad and should be caught earlier. Checking for a zero pivot and raising an informative error sounds like a good solution @czgdp1807