Closed felixblanke closed 4 months ago
I was merging, but then I thought that not computing the entire tree immediately should never be a problem. We eagerly computed the entire tree because we knew we needed it for the deepfake detection project. But generally speaking, we don't know which parts of the tree a user might want to expand. So I am thinking we should never compute the entire tree by default.
If that's true, we don't need the lazy_init
argument and can just change the behaviour under the hood. I am putting a PR together.
I merged main into this PR. The product of the tested parameters gets quite high, running the full test suite show 11227 test for the packets module alone. We might want to consider reducing this
I think we should not have the lazy_init
argument and make computation on request the default. That way this PR does not add extra tests.
We could change the default value of lazy_init
to True. Then users could decide to opt in to eager initialization.
But then we have to keep all of the old eager code. I don't see why we would do that. It just adds extra complexity.
Wait, let's not duplicate work. @felixblanke, are you doing this already?
okay I am doing it.
Ah, wait. I am on it :D
Okay I am done and running the tests.
It looks like we can just remove the old recursive code without too much of a hassle.
Turns out it works in most cases:
FAILED tests/test_packets.py::test_partial_expansion_1d[zero-haar] - assert False
FAILED tests/test_packets.py::test_partial_expansion_1d[zero-db4] - assert False
FAILED tests/test_packets.py::test_partial_expansion_1d[reflect-haar] - assert False
FAILED tests/test_packets.py::test_partial_expansion_1d[reflect-db4] - assert False
FAILED tests/test_packets.py::test_partial_expansion_1d[constant-haar] - assert False
FAILED tests/test_packets.py::test_partial_expansion_1d[constant-db4] - assert False
FAILED tests/test_packets.py::test_partial_expansion_1d[boundary-haar] - assert False
FAILED tests/test_packets.py::test_partial_expansion_1d[boundary-db4] - assert False
FAILED tests/test_packets.py::test_partial_expansion_2d[zero-haar] - assert False
FAILED tests/test_packets.py::test_partial_expansion_2d[zero-db4] - assert False
FAILED tests/test_packets.py::test_partial_expansion_2d[reflect-haar] - assert False
FAILED tests/test_packets.py::test_partial_expansion_2d[reflect-db4] - assert False
FAILED tests/test_packets.py::test_partial_expansion_2d[constant-haar] - assert False
FAILED tests/test_packets.py::test_partial_expansion_2d[constant-db4] - assert False
FAILED tests/test_packets.py::test_partial_expansion_2d[boundary-haar] - assert False
FAILED tests/test_packets.py::test_partial_expansion_2d[boundary-db4] - assert False
FAILED tests/test_packets.py::test_inverse_boundary_packet_1d - KeyError: 'Key da not found'
FAILED tests/test_packets.py::test_inverse_boundary_packet_2d - KeyError: 'Key aa not found'
failed with the current code.
I am leaving for today, but am happy to look at this again tomorrow.
I added the function initialize
to the packet objects to initialize all coefficients as described by a set of keys. This feels less clumsy than using a list comprehension (and is possibly more memory efficient)
I am convinced this works. Lets merge.
Adds lazy initialization to wavelet packet objects and addresses #91.
Adds the option to lazy initialize a wavelet packet object by passing
lazy_init=True
to__init__
ortransform
. In the case, we avoid doing a expansion of the full packet tree. If the user tries to access access a key not yet contained in the dict, we calculate the missing coeffs on the fly.This allows for siginificant speedups if we are not interested in the full tree but only a subset of the nodes
The example of issue #69 is presented below:
which outputs