- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想向量化以下函数
def nppolyfit(pnp_array, **kwargs):
""" Moving polyfit
"""
win_size = kwargs['length']
degree = kwargs['degree']
xdata = range(win_size)
res = np.zeros(pnp_array.shape)
for i in range(win_size, len(pnp_array) + 1):
res[i-1] = np.poly1d(np.polyfit(xdata , pnp_array[i - win_size : i], deg = degree))(win_size)
return res
到目前为止做了什么:
def rolling_window(a, window):
shp = a.shape[:-1] + (a.shape[-1] - window + 1, window)
strides = a.strides + (a.strides[-1],)
return np.lib.stride_tricks.as_strided(a, shape=shp, strides=strides)
def nppolyfitv(pnp_array, **kwargs):
""" Moving polyfit
"""
win_size = kwargs['length']
degree = kwargs['degree']
xdata = np.arange(win_size)
ydata = rolling_window(pnp_array, win_size).T
fit = np.polyfit(xdata, ydata, deg = degree)
res = np.zeros(len(pnp_array))
res[win_size-1:] = np.polynomial.polynomial.polyval(np.zeros(len(pnp_array)), fit).T[len(pnp_array) - 1,:]
return res
但看起来我遗漏了什么或做错了什么。你能纠正我吗?也许还有另一种更有效的解决方案?谢谢。
测试用例:
import numpy as np
npd = np.arange(30)
win_size1 = 11
degree = 1
c1 = nppolyfit(npd, length=win_size1, degree=degree)
c1v = nppolyfitv(npd, length=win_size1, degree=degree)
print(c1)
print(c1v)
结果是:
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 11. 12. 13. 14. 15.
16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 30.
59. 88. 117. 146. 175. 204. 233. 262. 291. 320. 349. 378.
407. 436. 465. 494. 523. 552.]
最佳答案
polyfit
方法返回多项式系数,最高幂优先。
polyval
方法期望系数具有最低幂优先。将一种方法的输出提供给另一种方法时,请考虑到这一点。
此外,polyval
的 x 参数不合逻辑:np.zeros(len(pnp_array))
。为什么要多次要求 polyval
计算同一点 0 处的多项式?特别是因为您的非矢量化函数计算了 win_size
处的多项式。为了与非矢量化方法保持一致,将行替换为
res[win_size-1:] = np.polynomial.polynomial.polyval(np.zeros(len(pnp_array)), fit).T[len(pnp_array) - 1,:]
与
res[win_size-1:] = np.polynomial.polynomial.polyval(win_size, fit[::-1])
那么测试用例的两个输出是相同的。
(也就是说,我也不知道你为什么要在窗口的右边缘计算多项式;中间的值会更具代表性吗?但这由你决定。)
关于python - 为移动窗口向量化 numpy polyfit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47440161/
我想使用Tensorflow的transform_graph工具优化图形。我尝试优化 MultiNet 中的图表(以及其他具有类似编码器-解码器架构的)。然而,优化后的图在使用 quantize_we
我试图在 C# 中将图像量化为 10 种颜色,但在绘制量化图像时遇到问题,我已经制作了映射表并且它是正确的,我已经制作了原始图像的副本并且正在更改基于映射表的像素颜色,我使用下面的代码: bm = n
我需要降低UIImage的颜色深度,但是我不知道该怎么做。结果应与在Photoshop中应用索引颜色相同。 我的目标是要具有较低的色深(32色或更低)。也许这是我的错,但我没有找到解决方法。令人惊讶的
我有大量的 numpy 向量,每个形状 (3,) 都有 8 位整数值: vec = np.random.randint(2**8, size=3) 我想通过一些已知的缩减因子将这些向量量化到更小的空间
我正在用 jQuery 编写一个心理学应用程序。我的项目的一部分需要测量用户对声音的 react 时间(用户按下一个键)。因此,我需要在调用(&时间戳)声音文件和实际开始播放之间的延迟尽可能小地播放声
最近,我开始使用 Tensorflow + Keras 创建神经网络,我想尝试 Tensorflow 中提供的量化功能。到目前为止,使用 TF 教程中的示例进行试验效果很好,我有这个基本的工作示例(来
使用当前的 Tensorflow quantization ops ,我将如何在推理过程中模拟每 channel 量化?这paper将每层量化定义为 We can specify a single q
我已经卡住了我的模型并获得了 .pb 文件。然后我在 Linux 上使用 tocoConverter 量化我的模型,因为 Windows 不支持它。我有 quantized_model.tflite。
我将 git 用于一个稍微不寻常的目的——它在我写小说时存储我的文本。 (我知道,我知道......令人讨厌。) 我正在尝试跟踪生产力,并想衡量后续提交之间的差异程度。作家代表“作品”的是“文字”,至
quantization有什么区别和 simplification ? 量化是另一种简化方式吗? 在某些情况下使用量化更好吗? 或者我应该同时使用两者? 最佳答案 几何体的总大小由两个因素控制:点数和
扎克伯格说,Llama3-8B还是太大了,不适合放到手机中,有什么办法? 量化、剪枝、蒸馏,如果你经常关注大语言模型,一定会看到这几个词,单看这几个字,我们很难理解它们都干了些什么,但
相对于
我正在将一些我无法控制的 XML 转换为 XHTML。 XML 模式定义了一个 段落标记和 和 用于列表。 我经常在这个 XML 中找到嵌套在段落中的列表。因此,直接转换会导致 s 嵌套在 中s,
我看到过这样的说法:CNN 的更深层次可以学习识别更复杂的特征。这通常附带一张早期过滤器识别直线/简单曲线的图片,以及后期过滤器识别更复杂图案的图片。它具有直观意义:您距离数据越远,您对数据的理解就越
在使用 C++ 的带有 tensorflow lite 的树莓派上,对象检测无法正常工作。我的代码编译并运行,但输出似乎从未得到正确填充。我是否会遗漏任何依赖项或错误地访问结果? 我遵循了以下教程:
如何衡量/量化 Corona SDK 游戏应用中的“迟缓”? 我在我构建的基于 Corona SDK 的物理游戏(使用 Box2D)上寻找旧手机(例如 iPhone 4、Samsung GT-I900
我正在尝试创建一个 Tensorflow 量化模型,以便使用 Coral USB 加速器进行推理。这是我的问题的一个最小的独立示例: import sys import tensorflow as t
我有一个分位数回归模型,其中包含 1 个回归变量和 1 个回归变量。我想假设检验回归量在每个分位数上都相等。我想到的一种方法是在 {0.01,0.02,....,0.99} 上测试所有 tau。但是,
要求做,在 PGM 文件上使用 KMeans 进行 vector 量化(或图像压缩) 图像是 PMG 文件,其中 b = block 大小,k = 次数,t = 迭代,-g = 初始质心 图像是这样的
我是一名优秀的程序员,十分优秀!