English 中文(简体)
• 如何推广白鲸,以便使用N-dimensional数据?
原标题:How to extend pyWavelets to work with N-dimensional data?

如果是,请让我知道,这可能是一个不同论坛的问题。 我注意到,只有14人追随波塔。

I ve here an elegant way of extending the wavelet decomposition in pywt (pyWavelets package) to multiple dimensions. This should run out of the box if pywt is installed. Test 1 shows the decomposition and recomposition of a 3D array. All, one has to do is increase the number of dimensions and the code will work in decomposing/recomposing with 4, 6 or even 18 dimensions of data.

I ve取而代之。 wave和牛肉。 这里的波浪功能。 另外,在dec中,我还展示了新的波节的功能如何像旧的一样运作。

There is one catch though: It represents the wavelet coefficients as an array of the same shape as the data. As a consequence, with my limited knowledge of wavelets, I ve only been able to use it for Haar wavelets. Others like DB4 for example bleed coefficients over the edges of this strict bounds (not a problem with the current representation of coefficients as list of arrays [CA, CD1 ... CDN]. Another catch is that I ve only worked this with 2^N edge cuboids of data.

理论上,我认为,应当能够确保“混合”不会发生。 关于这种波束分解和再沉积的算法,由William Press、Saul A teukolsky、William T. Vetterling和Brian P. Flannery(第二版)讨论。 虽然这一算法假定在边缘而不是其他形式的对冲延伸(如z),但这种方法很笼统,足以为其他形式的延伸工作。

Any suggestion on how to extend this work to other wavelets?

NOTE: The query is also addressed on

Thanks, Ajo

import pywt
import sys
import numpy as np

def waveFn(wavelet):
    if not isinstance(wavelet, pywt.Wavelet):
        return pywt.Wavelet(wavelet)
    else:
        return wavelet

# given a single dimensional array ... returns the coefficients.
def wavedec(data, wavelet, mode= sym ):
    wavelet = waveFn(wavelet)

    dLen = len(data)
    coeffs = np.zeros_like(data)
    level = pywt.dwt_max_level(dLen, wavelet.dec_len)

    a = data    
    end_idx = dLen
    for idx in xrange(level):
        a, d = pywt.dwt(a, wavelet, mode)
        begin_idx = end_idx/2
        coeffs[begin_idx:end_idx] = d
        end_idx = begin_idx

    coeffs[:end_idx] = a
    return coeffs

def waverec(data, wavelet, mode= sym ):
    wavelet = waveFn(wavelet)

    dLen = len(data)
    level = pywt.dwt_max_level(dLen, wavelet.dec_len)

    end_idx = 1
    a = data[:end_idx] # approximation ... also the original data 
    d = data[end_idx:end_idx*2]    
    for idx in xrange(level):
        a = pywt.idwt(a, d, wavelet, mode)
        end_idx *= 2
        d = data[end_idx:end_idx*2]
    return a

def fn_dec(arr):
    return np.array(map(lambda row: reduce(lambda x,y : np.hstack((x,y)), pywt.wavedec(row,  haar ,  zpd )), arr))
    # return np.array(map(lambda row: row*2, arr))

if __name__ ==  __main__ :
    test  = 1
    np.random.seed(10)
    wavelet = waveFn( haar )
    if test==0:
        # SIngle dimensional test.
        a = np.random.randn(1,8)
        print "original values A"
        print a
        print "decomposition of A by method in pywt"
        print fn_dec(a)
        print " decomposition of A by my method"
        coeffs =  wavedec(a[0],  haar ,  zpd )
        print coeffs
        print "recomposition of A by my method"
        print waverec(coeffs,  haar ,  zpd )
        sys.exit()
    if test==1:
        a = np.random.randn(4,4,4)
        # 2 D test
        print "original value of A"
        print a

        # decompose the signal into wavelet coefficients.
        dimensions = a.shape
        for dim in dimensions:
            a = np.rollaxis(a, 0, a.ndim)
            ndim = a.shape
            #a = fn_dec(a.reshape(-1, dim))
            a = np.array(map(lambda row: wavedec(row, wavelet), a.reshape(-1, dim)))
            a = a.reshape(ndim)
        print " decomposition of signal into coefficients"
        print a

        # re-composition of the coefficients into original signal
        for dim in dimensions:
            a = np.rollaxis(a, 0, a.ndim)
            ndim = a.shape
            a = np.array(map(lambda row: waverec(row, wavelet), a.reshape(-1, dim)))
            a = a.reshape(ndim)
        print "recomposition of coefficients to signal"
        print a
最佳回答

First of all, I would like to point you to the function that already implements Single-level Multi-dimensional Transform (Source). It returns a dictionary of n-dimensional coefficients arrays. Coefficients are addressed by keys that describe type of the transform (approximation/details) applied to each of the dimensions.

例如,就2D案件而言,其结果是具有近似值和详细系数阵列的词典:

>>> pywt.dwtn([[1,2,3,4],[3,4,5,6],[5,6,7,8],[7,8,9,10]],  db1 )
{ aa : [[5.0, 9.0], [13.0, 17.0]],
  ad : [[-1.0, -1.0], [-1.0, -1.0]],
  da : [[-2.0, -2.0], [-2.0, -2.0]],
  dd : [[0.0, 0.0], [0.0, -0.0]]}

基于这一点,应当很容易将其扩大到多层次案件。

www.un.org/Depts/DGACM/index_spanish.htm 在此,我参加了讨论部分:https://gist.github.com/934166

我也想谈谈你在你们的提问中提到的一个问题:

There is one catch though: It represents the wavelet coefficients as an array of the same shape as the data.

在我看来,把成果作为投入数据相同的形式/规模的阵容,这种做法是有害的。 这使整个事情变得不必要复杂,难以理解和开展工作,因为你必须作出假设或维持一个二级数据结构,编制索引,以便能够在产出阵列中获取系数,并进行反向的转变(见Matlab关于dec/waverec的文献)。

而且,尽管它在纸面上发挥了巨大作用,但由于你提到的问题,它并不总是适合真正的世界应用:大部分投入数据规模不是2天线,而与波莱特过滤器相联的信号的淡化结果更大,“储存空间”反过来又可能导致数据损失和不完美的重建。

避免这些问题 我建议使用更多的自然数据结构来代表结果数据等级,如沙尔名单、字典和 t(如果有的话)。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签