确定“摆动性”数据集 - Python
我正在开发一款需要实现一组数据的波动性的软件。这是我将收到的输入示例,与每个垂直像素带的亮度图合并:
很容易看出左边距确实摆动(即有很多最小值/最大值),我想生成图像的一组关键点。我已经对数据应用了高斯平滑函数大约 10 次,但一开始它似乎相当不稳定。
有什么想法吗?
这是我的原始代码,但它不会产生非常好的结果(对于摆动):
def local_maximum(list, center, delta):
maximum = [0, 0]
for i in range(delta):
if list[center + i] > maximum[1]: maximum = [center + i, list[center + i]]
if list[center - i] > maximum[1]: maximum = [center - i, list[center - i]]
return maximum
def count_maxima(list, start, end, delta, threshold = 10):
count = 0
for i in range(start + delta, end - delta):
if abs(list[i] - local_maximum(list, i, delta)[1]) < threshold: count += 1
return count
def wiggliness(list, start, end, delta, threshold = 10):
return float(abs(start - end) * delta) / float(count_maxima(list, start, end, delta, threshold))
I'm working on a piece of software which needs to implement the wiggliness of a set of data. Here's a sample of the input I would receive, merged with the lightness plot of each vertical pixel strip:
It is easy to see that the left margin is really wiggly (i.e. has a ton of minima/maxima), and I want to generate a set of critical points of the image. I've applied a Gaussian smoothing function to the data ~ 10 times, but it seems to be pretty wiggly to begin with.
Any ideas?
Here's my original code, but it does not produce very nice results (for the wiggliness):
def local_maximum(list, center, delta):
maximum = [0, 0]
for i in range(delta):
if list[center + i] > maximum[1]: maximum = [center + i, list[center + i]]
if list[center - i] > maximum[1]: maximum = [center - i, list[center - i]]
return maximum
def count_maxima(list, start, end, delta, threshold = 10):
count = 0
for i in range(start + delta, end - delta):
if abs(list[i] - local_maximum(list, i, delta)[1]) < threshold: count += 1
return count
def wiggliness(list, start, end, delta, threshold = 10):
return float(abs(start - end) * delta) / float(count_maxima(list, start, end, delta, threshold))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下低通/高通/陷波/带通滤波器、傅里叶变换或小波。基本思想是有很多不同的方法来计算不同时间段内量化的信号的频率内容。
如果我们能弄清楚什么是摆动,那就会有帮助。我想说最左边的边距是摇摆不定的 b/c 它具有更多的高频内容,您可以通过使用傅立叶变换来可视化。
如果您对该红色信号采用高通滤波器,您将只获得高频内容,然后您可以测量幅度并进行阈值以确定摆动。但我想,摇摆背后只需要更多的形式主义。
Take a look at lowpass/highpass/notch/bandpass filters, fourier transforms, or wavelets. The basic idea is there's lots of different ways to figure out the frequency content of a signal quantized over different time-periods.
If we can figure out what wiggliness is, that would help. I would say the leftmost margin is wiggly b/c it has more high-frequency content, which you could visualize by using a fourier transform.
If you take a highpass filter of that red signal, you'll get just the high frequency content, and then you can measure the amplitudes and do thresholds to determine wiggliness. But I guess wiggliness just needs more formalism behind it.
对于此类事情,numpy 使事情变得更加容易,因为它提供了用于操作矢量数据的有用函数,例如向每个元素添加标量、计算平均值等。
例如,您可以尝试使用原始数据的过零率-wigginess1 或第一个差异 -wigginess2(取决于 wigginess 应该是什么,确切地说,如果要忽略全球趋势,您可能应该使用差异数据)。对于 x,您可以从原始数据中获取感兴趣的切片或窗口,从而获得一种局部摆动的度量。
如果您使用原始数据,在消除偏差后,您可能还需要将所有小于某个阈值的值设置为 0 以忽略低幅度摆动。
For things like these, numpy makes things much easier, as it provides useful functions for manipulating vector data, e.g. adding a scalar to each element, calculating the average value etc.
For example, you might try with zero crossing rate of either the original data-wiggliness1 or the first difference-wiggliness2 (depending on what wiggliness is supposed to be, exactly-if global trends are to be ignored, you should probably use the difference data). For x you would take the slice or window of interest from the original data, getting a sort of measure of local wiggliness.
If you use the original data, after removing the bias you might also want to set all values smaller than some threshold to 0 to ignore low-amplitude wiggles.