def test_perfect_reconstruction(families, wavelets, modes, epsilon, dtype):
    for wavelet in wavelets:
        for pmode, mmode in modes:
            print "Wavelet: %-8s Mode: %s" % (wavelet, pmode),

            w = pywt.Wavelet(wavelet)
            data_size = range(2, 40) + [100, 200, 500, 1000, 2000, 10000, 50000, 100000]

            ok, over = 0, 0
            for N in data_size:
                data = numpy.asarray(numpy.random.random(N), dtype)

                # compute dwt coefficients
                pa, pd = pywt.dwt(data, wavelet, pmode)

                # compute reconstruction
                rec = pywt.idwt(pa, pd, wavelet, pmode)

                if len(data) % 2:
                    rec = rec[:len(data)]

                rms_rec = rms(data, rec)
                if rms_rec > epsilon:
                    if not over:
                        print
                    print '[RMS_REC > EPSILON] for Mode: %s, Wavelet: %s, Length: %d, rms=%.3g' % (pmode, wavelet, len(data), rms_rec, )
                    over += 1
                else:
                    ok += 1
            if not over:
                print "- RMSE for all %d cases was under %s" % (len(data_size), epsilon)
def test_perfect_reconstruction(families, wavelets, modes, epsilon, dtype):
    for wavelet in wavelets:
        for pmode, mmode in modes:
            print "Wavelet: %-8s Mode: %s" % (wavelet, pmode),

            w = pywt.Wavelet(wavelet)
            data_size = range(
                2, 40) + [100, 200, 500, 1000, 2000, 10000, 50000, 100000]

            ok, over = 0, 0
            for N in data_size:
                data = numpy.asarray(numpy.random.random(N), dtype)

                # compute dwt coefficients
                pa, pd = pywt.dwt(data, wavelet, pmode)

                # compute reconstruction
                rec = pywt.idwt(pa, pd, wavelet, pmode)

                if len(data) % 2:
                    rec = rec[:len(data)]

                rms_rec = rms(data, rec)
                if rms_rec > epsilon:
                    if not over:
                        print
                    print '[RMS_REC > EPSILON] for Mode: %s, Wavelet: %s, Length: %d, rms=%.3g' % (
                        pmode,
                        wavelet,
                        len(data),
                        rms_rec,
                    )
                    over += 1
                else:
                    ok += 1
            if not over:
                print "- RMSE for all %d cases was under %s" % (len(data_size),
                                                                epsilon)
示例#3
0
data = [1,2,3,4,5,6]

############################################################################
print "Case 1 (custom filter bank - Haar wavelet)"

myBank = FilterBank()
# pass the user supplied filter bank as argument
myWavelet = pywt.Wavelet(name="UserSuppliedWavelet", filter_bank=myBank)
#print myWavelet.get_filters_coeffs()

print "data:", data
a, d = pywt.dwt(data, myWavelet)
print "a:", a
print "d:", d
print "rec:", pywt.idwt(a, d, myWavelet)

############################################################################
print "-" * 75
print "Case 2 (Wavelet object as filter bank - db2 wavelet)"

# builtin wavelets can also be treated as filter banks with theirs
# filter_bank attribute

builtinWavelet = pywt.Wavelet('db2')
myWavelet = pywt.Wavelet(name="UserSuppliedWavelet", filter_bank=builtinWavelet)

print "data:", data
a, d = pywt.dwt(data, myWavelet)
print "a:", a
print "d:", d
示例#4
0
    if size > 500000:
        print "Warning, too big data size may cause page swapping if computer does not have enough memory."

    data = numpy.ones((size, ), numpy.float64)

    print("%d/%d" % (j + 1, len(sizes))).rjust(6), str(size).rjust(9),
    for i, w in enumerate(wavelets):
        min_t1, min_t2 = 9999., 9999.
        for _ in xrange(repeat):
            t1 = clock()
            (a, d) = pywt.dwt(data, w, mode)
            t1 = clock() - t1
            min_t1 = min(t1, min_t1)

            t2 = clock()
            a0 = pywt.idwt(a, d, w, mode)
            t2 = clock() - t2
            min_t2 = min(t2, min_t2)

        times_dwt[i].append(min_t1)
        times_idwt[i].append(min_t2)
        print '.',
    gc.collect()
    print

for j, (times, name) in enumerate([(times_dwt, 'dwt'), (times_idwt, 'idwt')]):
    pylab.figure(j)
    pylab.title(name)
    for i, n in enumerate(wavelet_names):
        pylab.loglog(sizes, times[i], label=n)
示例#5
0
    if size > 500000:
        print "Warning, too big data size may cause page swapping if computer does not have enough memory."

    data = numpy.ones((size,), numpy.float64)

    print ("%d/%d" % (j + 1, len(sizes))).rjust(6), str(size).rjust(9),
    for i, w in enumerate(wavelets):
        min_t1, min_t2 = 9999.0, 9999.0
        for _ in xrange(repeat):
            t1 = clock()
            (a, d) = pywt.dwt(data, w, mode)
            t1 = clock() - t1
            min_t1 = min(t1, min_t1)

            t2 = clock()
            a0 = pywt.idwt(a, d, w, mode)
            t2 = clock() - t2
            min_t2 = min(t2, min_t2)

        times_dwt[i].append(min_t1)
        times_idwt[i].append(min_t2)
        print ".",
    gc.collect()
    print


for j, (times, name) in enumerate([(times_dwt, "dwt"), (times_idwt, "idwt")]):
    pylab.figure(j)
    pylab.title(name)
    for i, n in enumerate(wavelet_names):
        pylab.loglog(sizes, times[i], label=n)