guilgautier / DPPy

Python toolbox for sampling Determinantal Point Processes
https://dppy.readthedocs.io
MIT License
219 stars 52 forks source link

DPP for diverse pixel sampling #74

Closed tk-rusch closed 1 week ago

tk-rusch commented 1 month ago

Thanks for your great work on DPPy. I am new to DPPs and this framework and was wondering what would be the correct way of using it for a simple problem setup: Given is a 32 x 32 pixel image. I now want to sample pixels from this image such that they are as diverse as possible (I presume here diversity could be measured in terms of discrepancy when projected back onto the unit square). What would be the correct DPP to use here? I presume I have to use a k-DPP, since I only want subsets of cardinality 2 (i.e., pixel locations)? I am currently using the following approach:

r, N = 2, 32
Phi = np.random.randn(r, N)
DPP = FiniteDPP('likelihood', **{'L': Phi.T.dot(Phi)})
for i in range(nsamples):
    DPP.sample_exact_k_dpp(size=2)

Unfortunately, this does not cover all pixels even when sampling more than 5000 samples (in contrast to uniform sampling of the pixels). In particular, it seems like it does not sample pixels of form (k,k) for any k=0,...,31 (i.e., on the diagonal of the image). I presume I'm doing something wrong here? Thanks for your help already in advance.

guilgautier commented 1 week ago

Hi @tk-rusch,

Thanks for your question.

When using DPPs, it is the very question to select a good kernel / the right kernel for the task at hand.

In your example, you considered a random, unstructured likelihood kernel L with rank 2. Samples from 2-DPP(L) will be made of exactly 2 pixels The likelihood of the samples is given here. You can compute this likelihood for some or even all possible pairs including a diagonal pixel to see whether you just ran out of luck in your 5000 samples or your kernel indeed will never yield diagonal pixels.

You can also consider more structured kernels, see Determinantal Point Processes for Image Processing, Launay et al.. If you wish to sample from complex kernels, you can use this branch https://github.com/guilgautier/DPPy/tree/v1-dev.

More generally, you may get in touch with Ayoub Belhadji who is currently a postdoc at MIT and worked on DPPs.

Cheers