guilgautier / DPPy

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

error: Probabilities do not sum to 1 #70

Closed NamitaBajpai closed 1 year ago

NamitaBajpai commented 1 year ago

I am trying to use sample_exact_k_dpp sampling function to select k elements. I am getting error probability do not sum to 1. I am using with Gram-Schmidt mode and likelihood kernel. However, I encountered the following error:

~/anaconda3/envs/gpu-torch/lib/python3.9/site-packages/dppy/exact_sampling.py in proj_dpp_sampler_eig_GS(eig_vecs, size, random_state) 489 for it in range(size): 490 # Pick an item \propto this squred distance --> 491 j = rng.choice(ground_set[avail], 492 p=np.abs(norms_2[avail]) / (rank - it)) 493 sampl[it] = j

mtrand.pyx in numpy.random.mtrand.RandomState.choice()

ValueError: probabilities do not sum to 1

I have checked the kernel property it satisfies positive semi definite and also the rank of the matrix is larger than the k value. How do I solve this randomstate.choice error? Any guess would be appreciated.
Thank you

guilgautier commented 1 year ago

Hi @NamitaBajpai,

It is difficult to address your issue as is, mainly because I can't reproduce it (templates where suggested when raising this issue) Could you share

One reason might be that the kernel is very ill-conditioned or many eigenvalues are very small which results in some imprecision/instability when evaluating the elementary symmetric polynomials, but that's just a guess. You could also try to call a different sampling method than "GS".

Best,

NamitaBajpai commented 1 year ago

Thank you for your reply. I am using dppy_0.3.2. The radial basis function is used to compute the kernel, the rank of the kernel is 600, and the size of the kernel matrix is 1000*1000. The value of k is 100.

guilgautier commented 1 year ago

Could you provide a minimal working example so that I can reproduce your issue ?

NamitaBajpai commented 1 year ago

Hi @guilgautier I could fix the issue. Thanks

guilgautier commented 1 year ago

Sounds good ! Could you give more details on how you fixed it ? It may be beneficial to other users :)