- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我无法让 scipy.interpolate.UnivariateSpline 在插值时使用任何平滑。基于function's page以及一些previous posts ,我相信它应该使用 s
参数提供平滑。
这是我的代码:
# Imports
import scipy
import pylab
# Set up and plot actual data
x = [0, 5024.2059124920379, 7933.1645067836089, 7990.4664106277542, 9879.9717114947653, 13738.60563208926, 15113.277958924193]
y = [0.0, 3072.5653360000988, 5477.2689107965398, 5851.6866463790966, 6056.3852496014106, 7895.2332350173638, 9154.2956175610598]
pylab.plot(x, y, "o", label="Actual")
# Plot estimates using splines with a range of degrees
for k in range(1, 4):
mySpline = scipy.interpolate.UnivariateSpline(x=x, y=y, k=k, s=2)
xi = range(0, 15100, 20)
yi = mySpline(xi)
pylab.plot(xi, yi, label="Predicted k=%d" % k)
# Show the plot
pylab.grid(True)
pylab.xticks(rotation=45)
pylab.legend( loc="lower right" )
pylab.show()
结果如下:
我已经尝试使用一系列 s
值(0.01、0.1、1、2、5、50)以及显式权重,设置为相同的值 (1.0) 或随机的。我仍然无法进行任何平滑处理,结数始终与数据点数相同。特别是,我正在寻找像第 4 个点 (7990.4664106277542、5851.6866463790966) 这样的异常值以进行平滑处理。
是因为我没有足够的数据吗?如果是这样,是否可以应用类似的样条函数或聚类技术来实现对这几个数据点的平滑处理?
最佳答案
简答:您需要选择 s
的值更仔细。
UnivariateSpline 的文档指出:
Positive smoothing factor used to choose the number of knots. Number of
knots will be increased until the smoothing condition is satisfied:
sum((w[i]*(y[i]-s(x[i])))**2,axis=0) <= s
从这个可以推断出平滑的“合理”值,如果你不传递明确的权重,大约是 s = m * v
其中 m
是数据点的数量,v
数据的方差。在这种情况下,s_good ~ 5e7
.
编辑:s
的合理值当然也取决于数据中的噪声水平。文档似乎建议选择 s
在 (m - sqrt(2*m)) * std**2 <= s <= (m + sqrt(2*m)) * std**2
范围内其中 std
是与您要平滑的“噪声”相关联的标准差。
关于python - scipy.interpolate.UnivariateSpline 不平滑,无论参数如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719754/
我正在研究一个简单的函数来拟合 yield 曲线。我正在使用 Scipy.interpolate.UnivariateSpline 来完成任务。该函数应返回特定时间间隔(到期日)的 yield 值。
我有一堆代表 sigmoidal 函数的 x, y 点: x=[ 1.00094909 1.08787635 1.17481363 1.2617564 1.34867881 1.43562
我正在使用 UnivariateSpline 为我拥有的一些数据构造分段多项式。然后我想在其他程序(C 或 FORTRAN 中)中使用这些样条,因此我想了解生成的样条背后的方程式。 这是我的代码: i
我正在尝试将一些 MatLab 代码移植到 Scipy,并且我尝试了 scipy.interpolate 中的两个不同函数,interp1d和 UnivariateSpline . interp1d
我尝试使用 SciPy 的平滑单变量样条 from scipy.interpolate import UnivariateSpline spl = UnivariateSpline(x, y) 我收到
我在尝试使用 UnivariateSpline 函数插入数据时遇到了一个奇怪的问题。通过所有点进行插值 (s=0) 和样条函数不会给出整个数据集的结果。 s>=1 的结果也很奇怪。因为我认为它与我正在
scipy UnivariateSpline 不允许多值 X。我读到这已更改,但似乎对我不起作用。我用的是最新版本,刚刚用pip尝试下载,说我有最新版本。 我曾尝试将 s(平滑)从 0 和 None(
我正在尝试使用 UnivariateSpline 函数为某些数据(原始布拉格峰)生成拟合。这是我的代码: import matplotlib.pyplot as plt from scipy impo
我正在尝试使用 SciPy 的 UnivariateSpline 来定位曲线上的一个点。不幸的是,我的结果是 nan。 这是一个最小的例子: from scipy.interpolate import
我无法让 scipy.interpolate.UnivariateSpline 在插值时使用任何平滑。基于function's page以及一些previous posts ,我相信它应该使用 s 参
我正在将用 R 编写的脚本移植到 Python。在 R 中,我使用 smooth.spline,在 Python 中,我使用 SciPy UnivariateSpline。它们不会产生相同的结果(即使
我有一个实验数据,我正在尝试使用 scipy 中的 UnivariateSpline 函数拟合曲线。数据如下: x y 13 2.404070 12 1.588134 1
当 spline = UnivariateSpline(x, y, bbox=[0,1], k=3.0,s=0.0) 对比 spline = UnivariateSpline(x, y, k=3.0,
scipy.interpolate.splrep(x, y, w=None, xb=None, xe=None, k=3, task=0, s=None, t=None, full_output=0,
我正在使用 scipy.interpolate.UnivariateSpline平滑地插入大量数据。效果很好。我得到一个像函数一样运行的对象。 现在我想保存样条点以备后用,并在不需要原始数据的情况下在
我是一名优秀的程序员,十分优秀!