2 votes

Erreur de segmentation lors de l'exécution de scipy interpolate

(éditer pour éviter le problème des points sur une ligne) J'exécute le code suivant :

from scipy.interpolate import LinearNDInterpolator
import numpy as np

points = np.array([[ 0,  0],
                   [1,  0],
                   [ 0,  1]])

values = np.array([-3, 8, -2])
ip = LinearNDInterpolator(points, values)

sur mon ordinateur produit le résultat suivant

Défaut de segmentation : 11

Pour essayer de résoudre ce problème, j'ai récemment désinstallé et réinstallé numpy et scipy de manière à ce que

scipy. version '1.3.3' numpy. version '1.17.4'

Mais rien n'y fait

1voto

Ce n'est pas nécessairement une réponse mais juste un complément d'information, lorsque j'exécute ce code exact, j'obtiens ceci en sortie, en tant que couleur d'erreur :

Traceback (most recent call last):
  File "/Users/tadhgmcdonald-jensen/Documents/test.py", line 8, in <module>
    interp = LinearNDInterpolator(pts, z, fill_value= np.nan)
  File "interpnd.pyx", line 248, in scipy.interpolate.interpnd.LinearNDInterpolator.__init__
  File "qhull.pyx", line 1833, in scipy.spatial.qhull.Delaunay.__init__
  File "qhull.pyx", line 355, in scipy.spatial.qhull._Qhull.__init__
scipy.spatial.qhull.QhullError: QH6154 Qhull precision error: Initial simplex is flat (facet 1 is coplanar with the interior point)

While executing:  | qhull d Q12 Qbb Qc Qt Qz
Options selected for Qhull 2015.2.r 2016/01/18:
  run-id 923456758  delaunay  Q12-no-wide-dup  Qbbound-last  Qcoplanar-keep
  Qtriangulate  Qz-infinity-point  _pre-merge  _zero-centrum  Qinterior-keep
  Pgood  _max-width  2  Error-roundoff 5.5e-15  _one-merge 3.9e-14
  Visible-distance 1.1e-14  U-coplanar-distance 1.1e-14  Width-outside 2.2e-14
  _wide-facet 6.7e-14

precision problems (corrected unless 'Q0' or an error)
      2 flipped facets

The input to qhull appears to be less than 3 dimensional, or a
computation has overflowed.

Qhull could not construct a clearly convex simplex from points:
- p1(v3):     2     3  0.71
- p3(v2):     2     3     2
- p2(v1):     3     4   1.8
- p0(v0):     1     2 5.6e-17

The center point is coplanar with a facet, or a vertex is coplanar
with a neighboring facet.  The maximum round off error for
computing distances is 5.5e-15.  The center point, facets and distances
to the center point are as follows:

center point        2        3    1.122

facet p3 p2 p0 distance=    0
facet p1 p2 p0 distance=    0
facet p1 p3 p0 distance=    0
facet p1 p3 p2 distance=    0

These points either have a maximum or minimum x-coordinate, or
they maximize the determinant for k coordinates.  Trial points
are first selected from points that maximize a coordinate.

The min and max coordinates for each dimension are:
  0:         1         3  difference=    2
  1:         2         4  difference=    2
  2:  5.551e-17         2  difference=    2

If the input should be full dimensional, you have several options that
may determine an initial simplex:
  - use 'QJ'  to joggle the input and make it full dimensional
  - use 'QbB' to scale the points to the unit cube
  - use 'QR0' to randomly rotate the input for different maximum points
  - use 'Qs'  to search all points for the initial simplex
  - use 'En'  to specify a maximum roundoff error less than 5.5e-15.
  - trace execution with 'T3' to see the determinant for each point.

If the input is lower dimensional:
  - use 'QJ' to joggle the input and make it full dimensional
  - use 'Qbk:0Bk:0' to delete coordinate k from the input.  You should
    pick the coordinate with the least range.  The hull will have the
    correct topology.
  - determine the flat containing the points, rotate the points
    into a coordinate plane, and delete the other coordinates.
  - add one or more points to make the input full dimensional.

Je ne connais pas assez Scipy pour savoir exactement ce qui se passe, mais est-il possible que votre entrée soit invalide et que vous n'obteniez pas de sortie significative sur votre machine ? Cela pourrait être pertinent de signaler un bogue à Scipy.

scipy.version.version == '1.3.1' and numpy.version.version == '1.17.3'

1voto

tevemadar Points 5069

Comme le dit le message d'erreur dans l'autre réponse : vos 3 points ne forment pas un triangle :

y
^
4       p4       (3,4)
3    p2          (2,3)
2 p1             (1,2)
1
0  1  2  3  > x

Ils sont sur une ligne. Simplices est le nom des "triangles" génériques à n dimensions, vos points 2D sont censés former un vrai triangle (alors qu'il n'y en a que 3).

Il suffit donc de modifier n'importe quelle coordonnée de l'entrée pour que cela fonctionne.

0voto

Paul Fleming Points 44

Une bonne solution semble être de mettre en place un environnement conda propre. Ce problème pourrait provenir de la façon particulière dont python et scipy sont installés (combo de Python 3.7 de Homebrew + SciPy 1.3.x/1.4.x installé avec pip) :

https://github.com/scipy/scipy/issues/11088

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X