Skip to content

Add use_dual to renyi_entropy and log_determinant - #244

Open
AnnaWegmann wants to merge 3 commits into
mainfrom
claude/kernel-use-dual-flag
Open

Add use_dual to renyi_entropy and log_determinant#244
AnnaWegmann wants to merge 3 commits into
mainfrom
claude/kernel-use-dual-flag

Conversation

@AnnaWegmann

Copy link
Copy Markdown
Collaborator

Adds a use_dual flag (default True) to renyi_entropy and log_determinant, with the same semantics as the existing flag on vendi_score:

  • use_dual=True: the cosine kernel is built through the d×d dual matrix X'ᵀ X' whenever it is smaller than the n×n Gram matrix X' X'ᵀ. The two share their nonzero eigenvalues, trace, and Frobenius norm — everything the measures consume — so values agree with the full construction up to floating point, while an n=100k input needs a ~1 MB matrix instead of an 80 GB one (which previously OOM'd). For log_determinant, the rank-deficient kernel's n − d structural zero eigenvalues enter log det(K + εI) in closed form (each contributes log ε).
  • use_dual=False: the full n×n construction, unchanged from before.

At n=100k, d=384 (M1 Pro): renyi_entropy 0.32 s, log_determinant 0.16 s with the default; both out-of-memory before.

Tests run each measure both ways on the same data and require agreement to 1e-10 (both orientations, n>d and n<d), plus a speed check that the dual route wins for n ≫ d. The log_determinant comparison uses eps=1e-2: at small ε, the full path's structural zero eigenvalues surface as ~1e-15 floating-point noise that log(λ+ε) amplifies by 1/ε (≈3e-9 at the default ε=1e-6), while the dual path carries them exactly — the larger ε removes that amplification so the 1e-10 bound is meaningful.

🤖 Generated with Claude Code

With use_dual=True (the default) the cosine kernel is built through the
d x d dual matrix X'^T X' whenever it is smaller than the n x n Gram
matrix X' X'^T. The two share the eigenvalue spectrum the measures are
computed from, so results agree up to floating point while large inputs
never materialize an n x n matrix; log_determinant adds the structural
zero eigenvalues' log(eps) contribution in closed form. use_dual=False
keeps the full n x n construction, and the test compares the two paths
on the same data. vendi_score already has the same flag with the same
semantics.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 8, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@AnnaWegmann
AnnaWegmann requested review from CantaoSu and Copilot July 8, 2026 15:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Successfully merging this pull request may close these issues.

2 participants