Python scipy版本能否更改scipy.interpolate.griddata结果?
我的问题始于scipy 1.2.3及其函数scipy.interpolate.griddata,它执行插值并为我提供参考数据集。(我对立方体2d插值感兴趣,请参见下面的测试用例) 将scipy更新为scipy 1.5.2后,我无法生成与以前完全相同的结果…而且差异是不容忽视的。Python scipy版本能否更改scipy.interpolate.griddata结果?,python,scipy,interpolation,Python,Scipy,Interpolation,我的问题始于scipy 1.2.3及其函数scipy.interpolate.griddata,它执行插值并为我提供参考数据集。(我对立方体2d插值感兴趣,请参见下面的测试用例) 将scipy更新为scipy 1.5.2后,我无法生成与以前完全相同的结果…而且差异是不容忽视的。 通过测试anaconda发行版中提供的以前版本的scipy,如果我安装scipy 1.3.2,我会精确生成初始插值结果 因此,我认为griddata或其子组件是在scipy 1.3.2之后更新的 但是我在Scipy发行说
通过测试anaconda发行版中提供的以前版本的scipy,如果我安装scipy 1.3.2,我会精确生成初始插值结果 因此,我认为griddata或其子组件是在scipy 1.3.2之后更新的 但是我在Scipy发行说明中找不到任何关于它的解释:,GitHub上的Scipy/Scipy/interpolate/ndgriddata.py的历史记录中没有任何内容,GitHub上的Scipy/Scipy/interpolate/interpind.pyx的历史记录中也没有任何内容。也许我没看到什么明显的东西 有没有人遇到过这样的问题:更新scipy已经改变了scipy.interpolate.griddata给出的结果
为了制作一个测试用例,我从以下方面借用了一些代码:(非常感谢)
在我的计算机Windows 7、Python 3.7、scipy 1.5.2上的测试结果:
Arrays are not almost equal to 5 decimals
Mismatched elements: 38 / 40 (95%)
Max absolute difference: 0.03821737
Max relative difference: 0.67726368
x: array([[ 1.22465e-16, 2.99260e-02, 4.64922e-02, 3.63387e-02,
-1.17334e-02, -4.10790e-02, -3.53277e-02, -1.32599e-02,
6.57517e-03, 1.46194e-02, 1.29942e-02, 4.60176e-03,...
y: array([[ 1.22465e-16, 2.97398e-02, 4.62030e-02, 3.61127e-02,
-1.15711e-02, -3.85005e-02, -3.03032e-02, -9.36536e-03,
3.92018e-03, 1.17290e-02, 1.37729e-02, 6.40206e-03,...
我可以观察到这些差异是不容忽视的 由于1.4.0版的行为已经不同,因此在1.3.2和1.4.0之间的所有文件上运行二等分,并从源代码为运行测试脚本的每个提交构建SciPy,这有助于缩小相关更改的范围 结果是,行为的改变是由一种新的
qh\u new\u qhull\u scipy
算法引入的。griddata
函数依次使用此算法。根据qh_new_qhull之前已修补,因此您获得的新结果很可能是正确的
下面是缩小到相关提交的详细步骤 准备步骤:
git克隆https://github.com/scipy/scipy.git
;和mv-scipy-scipy-source
pip Install tempita
)所需的依赖项test.py
中,并删除try/except
中围绕np.testing.assert_几乎相等的
main
脚本(这将花费很长时间)从pathlib导入路径
导入shlex
导入子流程
导入系统
def日志(消息,*,级别=0,换行符=False):
缩进=“”*级
打印(f'{indent}{msg}',end='\n'如果换行符为else',flush=True)
def运行(指令,**kwargs):
如果cmd.startswith('git'):
kwargs['cwd']='scipy source'
update(check=True,capture\u output=True,text=True)
返回subprocess.run(shlex.split(cmd),**kwargs.stdout.strip()
def运行日志(cmd,**kwargs):
exc,*args=shlex.split(cmd)
exc=路径(exc).name
日志(f'{.join([exc,*args])}',级别=1)
text=run(cmd,**kwargs.strip()
如果文本:
text=text.splitlines()[-1]
日志(文本,换行符=True)
返回文本
python=sys.exe
祖先=运行('git merge base v1.3.2 v1.4.0')
commits=run(f'git--no pager log--pretty=oneline--reverse--祖先路径{祖先}..v1.4.0')。splitlines()
提交=[x.split(“”,maxsplit=1)[0]用于提交中的x]
log(f'Scanning{len(commits)}commits',换行符=True)
低,高=0,len(提交)
索引=(低+高)//2
当0 如果high-low能够精确定位相关的变化,您可以执行以下操作。对于仍然有效的版本和结果更改的第一个版本之间的每次提交,从源代码处编译scipy
包,并检查行为是否更改。这样,您就可以识别相关的提交(假定它是为特定的提交而构建的,否则您至少可以识别一组提交)。在一个自动化脚本的帮助下,执行卸载、构建、安装和测试步骤应该不会太困难。谢谢@a_guest的评论。您的方法可能有助于找到发散提交。但是我认为我没有足够的技术来做这样的手术。我更喜欢在Windows上工作,在这个平台上从源代码构建Scipy似乎既困难又耗时。不过,我会记录下我自己,并且仍然会考虑你的方法。非常感谢@a_guest。您已经找到了我在scipy.interpolate.griddata中观察到的更改的来源。我认为我做不到这项工作。我必须用你的答案来提高自己。再次感谢你。预祝大家2021年新年快乐。
Arrays are not almost equal to 5 decimals
Mismatched elements: 38 / 40 (95%)
Max absolute difference: 0.03821737
Max relative difference: 0.67726368
x: array([[ 1.22465e-16, 2.99260e-02, 4.64922e-02, 3.63387e-02,
-1.17334e-02, -4.10790e-02, -3.53277e-02, -1.32599e-02,
6.57517e-03, 1.46194e-02, 1.29942e-02, 4.60176e-03,...
y: array([[ 1.22465e-16, 2.97398e-02, 4.62030e-02, 3.61127e-02,
-1.15711e-02, -3.85005e-02, -3.03032e-02, -9.36536e-03,
3.92018e-03, 1.17290e-02, 1.37729e-02, 6.40206e-03,...
$ python main.py
Scanning 1281 commits
19f4c290 (640)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+18219f5
git checkout 19f4c2900d6c62d1e56c2faecd8a2b1d584c094e:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+19f4c29
python test.py: failed
983e83e5 (320)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+19f4c29
git checkout 983e83e549a1c6f04b4657d2396dc47ab4b8d0e1:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+983e83e
python test.py:
a3276047 (480)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+983e83e
git checkout a3276047bb3493eeab6dac5148615cc8010faac0:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+a327604
python test.py: failed
35f86bc3 (400)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+a327604
git checkout 35f86bc33016dc88fc4340e4dc3f23bf86e4f311:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+35f86bc
python test.py: failed
7b0345e9 (360)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+35f86bc
git checkout 7b0345e9c038d7c1082ec0097f1ed4a626734bf4:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+7b0345e
python test.py: failed
f9525c3c (340)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+7b0345e
git checkout f9525c3ce7a9b63afda23b0af2ad32c7fbcedaa9:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+f9525c3
python test.py:
4a71ecf7 (350)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+f9525c3
git checkout 4a71ecf72be8321eb9a5faf7307f4c18cb0cb500:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+4a71ecf
python test.py: failed
9b7879b8 (345)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+4a71ecf
git checkout 9b7879b832aa52131383999fc7dd0dfa3575a4c2:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+9b7879b
python test.py: failed
5481d175 (342)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+9b7879b
git checkout 5481d175bb29d7162ac9eed18bb9181a2b566f20:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+5481d17
python test.py:
f2854466 (343)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+5481d17
git checkout f28544666cbc74c86c21fc2b320bc31f9fbd1c2c:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+f285446
python test.py:
18219f5a (344)
python -m pip uninstall -y scipy: Successfully uninstalled scipy-1.4.0.dev0+f285446
git checkout 18219f5a1971be9a3fd6d590aeb496a419e8cd0e:
python -m pip install .: Successfully installed scipy-1.4.0.dev0+18219f5
python test.py: failed