Fix TSNE gradient computation - #421
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to correct the mathematical implementation of the t-SNE gradient computation so that optimization steps better align with the intended KL divergence objective.
Changes:
- Update the low-dimensional Student-t kernel to use squared distances and adjust Q normalization to exclude the diagonal.
- Add a targeted unit test for the
gradient()calculation. - Document the fix in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Transformers/TSNE.php |
Fixes kernel/normalization pieces used in gradient computation. |
tests/Transformers/TSNETest.php |
Adds a regression test for gradient behavior (and helper to invoke it). |
CHANGELOG.md |
Records the fix under a new 2.5.3 entry. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
apphp
approved these changes
Aug 16, 2026
|
Very good fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
t-SNE gradient is mathematically wrong — src/Transformers/TSNE.php:523-543 The q-kernel uses raw (non-squared) Euclidean distances (Euclidean::compute() returns sqrt(Σ(a−b)²)), the gradient weight is raw d instead of (1 + d²/ν)^⁻¹, and Q is normalized by sum()×2 including the diagonal (all 1.0). The embedding does not minimize the documented KL divergence; wrong output is produced silently.