Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support complex-valued kernels #78

Open
kevinsung opened this issue Nov 3, 2024 · 2 comments
Open

Support complex-valued kernels #78

kevinsung opened this issue Nov 3, 2024 · 2 comments

Comments

@kevinsung
Copy link

kevinsung commented Nov 3, 2024

Is your feature request related to a problem? Please describe.
The documentation says that the correlation kernel can be a complex Hermitian matrix with eigenvalues between 0 and 1. However, if you pass such a complex-valued matrix, it complains that the array is not symmetric:

import numpy as np
from dppy.finite_dpps import FiniteDPP

rng = np.random.default_rng(12345)
dim = 5
mat = rng.standard_normal((dim, dim)) + 1j * rng.standard_normal((dim, dim))
mat @= mat.T.conj()
mat /= np.trace(mat)
assert np.allclose(mat, mat.T.conj())
eigs, vecs = np.linalg.eigh(mat)
assert all(0 <= e <= 1 for e in eigs)
dpp = FiniteDPP("correlation", K=mat)
Traceback (most recent call last):
  File "/home/kjs/projects/ffsim/scratch/repro.py", line 12, in <module>
    dpp = FiniteDPP("correlation", K=mat)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kjs/.pyenv/versions/ffsim/lib/python3.12/site-packages/dppy/finite_dpps.py", line 121, in __init__
    self.K = is_symmetric(params.get('K', None))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kjs/.pyenv/versions/ffsim/lib/python3.12/site-packages/dppy/utils.py", line 133, in is_symmetric
    raise ValueError('array not symmetric: M.T != M')
ValueError: array not symmetric: M.T != M

The same issue exists for the likelihood kernel,

dpp = FiniteDPP("likelihood", L=mat)

Describe the solution you'd like
Complex-valued kernels should be supported.

Describe alternatives you've considered
N/A

Additional context
Complex-valued kernels arise when using DPPs to sample from fermionic systems.

@guilgautier
Copy link
Owner

Hi @kevinsung,
Thanks for reaching out.

The documentation is indeed misleading, one the one hand most of the explanation cover the complex hermitian case, but the underlying implementation does not.

Note however that the documentation of the dppy.finite_dpps.FiniteDPP class mentions

Caution
For now we only consider real valued matrices 𝐊,𝐋,𝐴,Φ,𝐗𝑑𝑎𝑡𝑎.


Anyway, the complex kernels are currently available in the v1-dev branch in the following way

# !pip install -U git+https://github.com/guilgautier/dppy.git@v1-dev
from dppy.finite.dpp import FiniteDPP

dpp = FiniteDPP(
    kernel_type="correlation",
    projection=False,
    hermitian=True,  # HERMITIAN = True for complex hermitian kernels
    K=mat,
    # K_eig_dec=(eigs, vecs)
)
dpp.sample_exact(method="spectral")   # "sequential", "spectral", "intermediate", "projection"

@kevinsung
Copy link
Author

Anyway, the complex kernels are currently available in the v1-dev branch in the following way

Awesome, thanks! I noticed that the last commit to that branch occurred two years ago. Do you plan to merge this functionality into main and cut a release at some point?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants