hoytak / pyksvd

A highly optimized, parallel implementation of the Batch-OMP version of the KSVD learning algorithm.
BSD 2-Clause "Simplified" License
78 stars 27 forks source link

Gamma, D mixed up?' #1

Open sorona opened 10 years ago

sorona commented 10 years ago

Hi @hoytak , nice implementation, nice work !!!

I used the ksvd implementation, but apparently when i use D_init = "random" the output D and Gamma is mixed up D is with the dimensions of Gamma and is not sparse Gamma is with the dimensions of D and is sparse (as in the target_sparsity)

also there is dimensions mismatch error when i try to initialize with D_init that is an array of my own (i tried over complete DCT) and it's look like Gamma and D are mixed up in the arrays initialization..

Traceback (most recent call last): File "./ksvd_demo.py", line 95, in ,enable_eigen_threading = False, enable_threading = True, enable_32bit_initialization = True, max_initial_32bit_iterations = 0) File "ksvd_wrapper.pyx", line 143, in ksvd.ksvd_wrapper.KSVD (ksvd/ksvd_wrapper.cpp:2059) ValueError: could not broadcast input array from shape (16,100) into shape (100,16384)

glemaitre commented 9 years ago

HI @sorona ,

I think there is a misunderstanding. In sparse coding, the dictionary D is not sparse. In the contrary, the vector Gamma has to be.

Let assume that $y$ is your original signal (not sparse), the sparse coding can be represented as: y = D Gamma

KSVD allows to find D. D can be computed by minimizing the l2 norm of the difference between the observed signal y and the reconstructed signal (D*Gamma) and imposing the sparsity constraint such that Gamma should have a given sparsity level.

Regarding the mismatch, I cannot give more information since that I did not try.

Cheer,