Package: python-pywt
Version: 0.1.7~svn97-1
Severity: normal

Yet another obstacle I found while analysing some of my data.
If pruning has occured, wp.reconstruct() might fail when I guess it should have 
not.

,---
| /usr/lib/python2.4/site-packages/pywt/wavelet_packets.pyc in 
reconstruct(self, update)
|      85                 raise ValueError, "Can not reconstruct. Tree is 
missing data"
|      86             else:
| ---> 87                 rec = idwt(data_a, data_d, self.wavelet, self.mode, 
correct_size=True)
|      88                 if update:
|      89                     self.data = rec
|
| /usr/lib/python2.4/site-packages/pywt/_pywt.so in pywt._pywt.idwt()
|
| ValueError: Coefficients arrays must satisfy (0 <= len(cA) - len(cD) <= 1).
`---

Length at the place of failure are

ipdb> len(data_a)
260
ipdb> len(data_d)
252

behavior stays the same when I change padding mode to 'sym'.
Also problem doesn't occur if none of the nodes got pruned

I am attaching again that example file with embedded data snippet and adjusted
threshold to reproduce the problem.

-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (991, 'testing'), (990, 'unstable'), (300, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-686 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash

Versions of packages python-pywt depends on:
ii  libc6                         2.7-15     GNU C Library: Shared libraries
ii  python                        2.5.2-2    An interactive high-level object-o
ii  python-central                0.6.8      register and build utility for Pyt
ii  python-numpy                  1:1.1.0-3  Numerical Python adds a fast array

python-pywt recommends no packages.

python-pywt suggests no packages.

-- debconf-show failed
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pywt import WaveletPacket
import pylab
import math
import numpy

#x = pylab.arrayrange(612-80, 20, -0.5)/150.
#data = pylab.sin(20*pylab.log(x)) * pylab.sign((pylab.log(x)))

data = numpy.array(
	[-0.34573659, -0.38810292, -0.45543289, -0.30603009, -0.1243628 ,
       -0.12558162,  0.0298495 ,  0.51478487,  0.8938365 ,  0.73296654,
        0.25564462,  0.18708593,  0.33945757,  0.11521387,  0.01981713,
        0.17223004,  0.27229831,  0.34833428,  0.32712582,  0.57411432,
        0.84752387,  0.63009703,  0.25494909,  0.17051926,  0.47685269,
        0.51836729,  0.30156392,  0.57711917,  0.87500638,  0.74624652,
        0.29505485, -0.12490962, -0.05453217,  0.22704136,  0.4834733 ,
        0.53429389,  0.32919055,  0.37594539,  0.81264687,  0.70471901,
       -0.21471409, -0.494104  , -0.12448001,  0.20966017,  0.69090933,
        0.74746501,  0.35667574,  0.17011094,  0.28702021,  0.42441538,
       -0.06605265, -0.98859781, -1.03666663, -0.25471625,  0.12900937,
        0.05600312,  0.08820164,  0.25174344,  0.38751057,  0.2893925 ,
       -0.06552365, -0.37944648, -0.41763771, -0.26762265, -0.06390376,
        0.1418543 , -0.06881711, -0.59654725, -0.44554675,  0.03705724,
       -0.10672796, -0.48229194, -0.47481367,  0.0671913 ,  0.7202397 ,
        0.55356973, -0.20201714, -0.24423063,  0.2410042 ,  0.1758634 ,
       -0.38244367, -0.85359514, -0.89553839, -0.66121352, -0.4836694 ,
       -0.26402989, -0.02437426,  0.11115174, -0.01598396, -0.33173251,
       -0.2154655 , -0.03343722, -0.23002645, -0.37420931, -0.40847069,
       -0.38042581, -0.37264973, -0.34534425, -0.34621239, -0.45104039,
       -0.41669124, -0.39197695, -0.40836936, -0.41242203, -0.50930172,
       -0.66101074, -0.70279622, -0.54050344, -0.56988621, -0.60800582,
       -0.43425202, -0.40210819, -0.26260108,  0.09008174,  0.34366187,
        0.17083512, -0.26701128, -0.11252782,  0.54705787,  0.78186125,
        0.42036369,  0.06707341,  0.38804147,  1.02385187,  0.78289628,
        0.03741382, -0.05829134,  0.09545194,  0.19760814,  0.48429587,
        0.65382117,  0.59562671,  0.15905438, -0.2841897 , -0.17725979,
       -0.00769951,  0.13430153,  0.4074778 ,  0.67588735,  0.73942482,
        0.52059728,  0.50374937,  0.2956422 , -0.40126958, -0.46746603,
        0.08772394,  0.42896676,  0.54153472,  0.60222602,  0.73305005,
        0.94797075,  0.84156698,  0.14969313, -0.28262892, -0.01854044,
        0.36948362,  0.75414896,  0.71608871,  0.12448686,  0.03415477,
        0.71146995,  1.02768123,  0.13064073, -1.07957816, -1.18031585,
       -0.4316408 ,  0.20752712,  0.39356601,  0.11908912, -0.25279516,
       -0.27945498, -0.23358169, -0.62040937, -0.91403097, -1.08253109,
       -1.3643012 , -0.90408862, -0.13326721, -0.03532824, -0.30052918,
       -0.30869764,  0.14190483,  0.16872986, -0.52904379, -0.82950765,
       -0.57574642, -0.35260922, -0.40631461, -0.84412497, -1.18531418,
       -0.94343036, -0.24132943,  0.0948167 , -0.54436576, -0.97514445,
       -0.44504359, -0.06588518, -0.36086997, -1.01898432, -1.42372036,
       -0.98361838, -0.49887896, -0.51098716, -0.49566799, -0.45534325,
       -0.27971864, -0.01289146, -0.06996948, -0.22960928, -0.21719246,
       -0.12586229, -0.26791307, -0.28670284, -0.08482055, -0.24696115,
       -0.1251926 ,  0.40114737,  0.4108803 ,  0.23961042,  0.16801332,
       -0.03215366,  0.03253647,  0.18988416,  0.0640558 ,  0.11062526,
        0.25257105,  0.04069111, -0.11823228,  0.04848703,  0.31178865,
        0.54475868,  0.39140043,  0.10510263,  0.3624824 ,  0.74902427,
        0.74371761,  0.48868194,  0.2298651 ,  0.13388744,  0.35414925,
        0.45046723,  0.10623782,  0.08053232,  0.44768173,  0.58874184,
        0.5156281 ,  0.32252964,  0.19333769,  0.27537739,  0.41304928,
        0.67002833,  0.59858018,  0.20810364,  0.66726983,  0.29272726,
       -2.20618391, -3.60798836, -2.54817486, -0.59640121,  1.0147121 ,
        1.74119568,  2.09057379,  2.30470371,  2.08168745,  1.40284204,
        0.58587623,  0.18220828,  0.42282817,  0.75473732,  0.39250791,
       -0.32354969, -0.55786163, -0.26725572,  0.03839639, -0.01886539,
       -0.42838663, -0.74645865, -0.78762144, -0.97687823, -1.22139239,
       -1.46928108, -1.8911221 , -1.86606503, -1.24852216, -0.90137899,
       -0.8604095 , -0.61489344, -0.42976227, -0.3579028 , -0.2550112 ,
       -0.3609733 , -0.74349201, -1.00684309, -1.03567755, -1.21463203,
       -1.40274465, -1.18434763, -0.80010295, -0.7885856 , -0.91457433,
       -0.72191888, -0.38094512, -0.16468807, -0.09077492, -0.10387847,
       -0.33666795, -0.75029886, -0.69107533, -0.19301286, -0.16300914,
       -0.54537416, -0.7384879 , -0.50050598, -0.08110276,  0.07275747,
        0.03492078, -0.09517509, -0.21966211, -0.06074491,  0.38211671,
        0.5190568 , -0.0422433 , -0.36352664, -0.10866001,  0.05437544,
        0.20974973,  0.42473951,  0.51390868,  0.44973576,  0.43922538,
        0.4202809 ,  0.35035506,  0.34382021,  0.02264159, -0.19176336,
        0.27686051,  0.61395586,  0.10884806, -0.52761126, -0.54345381,
       -0.1845329 ,  0.34844601,  0.85585701,  0.82573956,  0.29480994,
        0.199698  ,  0.58821958,  0.4097842 , -0.20117182, -0.68529505,
       -0.59920287,  0.26265663,  0.71709168,  0.44523397,  0.42030042,
        0.49547005,  0.40141755,  0.17532146, -0.37080652, -0.53917825,
       -0.09434764,  0.14409591,  0.13886316,  0.16051713,  0.1942763 ,
        0.50213385,  0.71408552,  0.05108832, -0.76438487, -0.72354162,
       -0.19283007,  0.2826573 ,  0.6727984 ,  0.51177317, -0.12549853,
       -0.06878713,  0.19995314, -0.35836998, -0.87287205, -0.77882993,
       -0.40312099,  0.2622945 ,  0.47721502, -0.07341472, -0.17401099,
        0.36486512,  0.643592  ,  0.37585711, -0.14986593, -0.53286755,
       -0.32185614,  0.17663859,  0.0592976 , -0.3324503 , -0.40202484,
       -0.19658361,  0.13577379,  0.10627493, -0.11760357, -0.05091718,
        0.01814876,  0.0342852 , -0.06658879, -0.54144925, -0.78274566,
       -0.4885661 , -0.33449933, -0.45626563, -0.54729432, -0.41983923,
        0.03955875,  0.26681873,  0.14632468, -0.05237956, -0.19973294,
        0.25775492,  0.52370071,  0.02199412, -0.19693415, -0.11562894,
        0.13920403,  0.50373054,  0.14508082, -0.1909228 ,  0.19551201,
        0.57926255,  0.81666166,  0.63755333,  0.18111664,  0.10651836,
        0.14200762,  0.28636914,  0.53723407,  0.35189441,  0.06825569,
        0.21778929,  0.50156486,  0.68994433,  0.91903323,  0.88751686,
        0.36196166, -0.23109406, -0.24008749,  0.4001154 ,  0.85797894,
        0.70444155,  0.25895256,  0.23918585,  0.82937747,  0.99962109,
        0.73064375,  0.42680928, -0.01835891,  0.21443914,  0.82717419,
        0.77688968,  0.55637294,  0.56584096,  0.56064045,  0.40366352,
        0.19031163,  0.1587998 ,  0.26224095,  0.51827961,  0.84558535,
        0.82341897,  0.65705061,  1.01285124,  1.28659916,  0.53027087,
       -0.4946177 , -0.57538098,  0.20680973,  0.9103815 ,  1.01510572,
        0.50717121, -0.01748215,  0.49862108,  1.36912179,  0.92974395,
       -0.11509538, -0.30563056, -0.04620126,  0.21577227,  0.3976962 ,
        0.14059401, -0.04423112,  0.15467754,  0.2684986 ,  0.15839657,
       -0.10493945, -0.01085244,  0.56424832,  0.75706172,  0.53177583,
        0.42576602,  0.35808924,  0.35696232,  0.43182141,  0.49328208],
	dtype=N.float32)

x = P.arange(-0.5,0.5,1.0/len(data))

#from sample_data import ecg as data
#data = numpy.array(data, numpy.float64) / 100.

## simple energy based criteria, not very efficient
def select(node, min_energy):
    if node.energy() < math.log(min_energy):
        print node.path, "marked as ZT", len(node.data)
        node.markZeroTree()
        return False # stop processing child nodes
    return True

## create our tree
wp = WaveletPacket(data, wavelet='sym3', mode='sp1', maxlevel=6)

treshold = 0.21
base_energy = wp.energy()
wp.walk(select, (treshold*base_energy,))


print "Non-zero trees:"
for node in wp.get_nonzero():
    print node.path, len(node.data)

new_data = wp.reconstruct()
print "Reconstructing %d samples using %d coefficients" % (wp.data_size, sum([len(node.data) for node in wp.get_nonzero()]))
print "Mean difference:", sum(abs(new_data - data))/len(data)
print "Retaining %.2f%% energy" % (100-(base_energy-wp.energy())*100./base_energy)

pylab.plot(x, data, label="orig")
pylab.plot(x, wp.data, label="rec")
pylab.xlim(min(x), max(x))

#pylab.plot(data, label="orig")
#pylab.plot(wp.data, label="rec")
#pylab.xlim(0, len(data)-1)

pylab.legend()
pylab.show()
_______________________________________________
Python-modules-team mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/python-modules-team

Reply via email to