fix: normalize Jensen-Shannon distance to unit range - #2631
fix: normalize Jensen-Shannon distance to unit range#2631Rana Singh (ranadeepsingh) wants to merge 4 commits into
Conversation
|
Hey Rana Singh (@ranadeepsingh) 👋! We use semantic commit messages to streamline the release process. Examples of commit messages with semantic prefixes:
To test your commit locally, please follow our guild on building from source. |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR corrects the Jensen–Shannon (JS) distance implementation in SynapseML’s core “distribution balance” metrics to match the documented normalized range [0, 1] by converting JS divergence from natural-log units to base-2 units, while keeping KL divergence and other metrics in their existing natural-log semantics.
Changes:
- Normalize JS distance by dividing JS divergence by
ln(2)(i.e., base-2 relative entropy) and clamp small negative roundoff beforesqrt. - Expand and update Scala regression tests to validate normalized endpoints, symmetry, and numerical stability.
- Update Responsible AI docs and quickstart notebook expected values/text to reflect the normalized JS distance scale.
Show a summary per file
| File | Description |
|---|---|
| docs/Explore Algorithms/Responsible AI/Quickstart - Data Balance Analysis.ipynb | Updates narrative and expected JS distance values shown in the quickstart. |
| docs/Explore Algorithms/Responsible AI/Data Balance Analysis.md | Updates JS distance definition/interpretation in documentation. |
| core/src/test/scala/com/microsoft/azure/synapse/ml/exploratory/DistributionBalanceMeasureSuite.scala | Adds/updates JS distance-focused regression coverage and updates expected values. |
| core/src/test/scala/com/microsoft/azure/synapse/ml/exploratory/DataBalanceTestBase.scala | Updates the local (test) JS distance calculator to match base-2 normalization and clamp negative roundoff. |
| core/src/main/scala/com/microsoft/azure/synapse/ml/exploratory/DistributionBalanceMeasure.scala | Implements normalized JS distance in the production metric computation. |
Review details
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 5/5 changed files
- Comments generated: 4
- Review effort level: Lite
## Summary Normalize only Jensen-Shannon distance to base-2 units so its documented endpoints are exact: identical distributions produce 0 and disjoint distributions produce 1. Preserve natural-log KL divergence and every public API, add cancellation protection near zero, expand numerical regression coverage, and refresh the data-balance documentation and sample values. ## Prompting Intent Own GitHub issue microsoft#2006 end-to-end with an isolated numerical correction. Trace formulas, documentation, and tests; preserve unrelated relative-entropy metrics and API behavior; test endpoints, symmetric intermediate cases, symmetry, bounds, zero handling, and unchanged metrics; validate with JDK 11 guarded SBT commands and project code review; address PR checks and review comments. ## Linked Sources - GitHub issue: microsoft#2006 - Pull request review: microsoft#2631 - Data Balance Analysis docs: docs/Explore Algorithms/Responsible AI/Data Balance Analysis.md - Sample notebook: docs/Explore Algorithms/Responsible AI/Quickstart - Data Balance Analysis.ipynb - Independent code review: no significant findings ## Rationale Divide Jensen-Shannon divergence by ln(2) at the JS call site rather than changing the shared natural-log entropy helper. This is mathematically equivalent to base-2 relative entropy while explicitly preventing changes to KL divergence and other metrics. Clamp only tiny negative JS divergence caused by floating-point cancellation before the square root, preserving valid values and avoiding NaN near the lower bound. Keep endpoint tolerances tight enough to verify the mathematical result without relying on cross-platform bitwise floating-point equality. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
186ed8a to
fb81306
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
## Summary Normalize only Jensen-Shannon distance to base-2 units so its documented endpoints are exact: identical distributions produce 0 and disjoint distributions produce 1. Preserve natural-log KL divergence and every public API, add cancellation protection near zero, expand numerical regression coverage, and refresh the data-balance documentation and sample values. ## Prompting Intent Own GitHub issue microsoft#2006 end-to-end with an isolated numerical correction. Trace formulas, documentation, and tests; preserve unrelated relative-entropy metrics and API behavior; test endpoints, symmetric intermediate cases, symmetry, bounds, zero handling, and unchanged metrics; validate with JDK 11 guarded SBT commands and project code review; address PR checks and review comments. ## Linked Sources - GitHub issue: microsoft#2006 - Pull request review: microsoft#2631 - Data Balance Analysis docs: docs/Explore Algorithms/Responsible AI/Data Balance Analysis.md - Sample notebook: docs/Explore Algorithms/Responsible AI/Quickstart - Data Balance Analysis.ipynb - Independent code review: no significant findings ## Rationale Divide Jensen-Shannon divergence by ln(2) at the JS call site rather than changing the shared natural-log entropy helper. This is mathematically equivalent to base-2 relative entropy while explicitly preventing changes to KL divergence and other metrics. Clamp only tiny negative JS divergence caused by floating-point cancellation before the square root, preserving valid values and avoiding NaN near the lower bound. Keep endpoint tolerances tight enough to verify the mathematical result without relying on cross-platform bitwise floating-point equality. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
## Summary Strengthen Jensen-Shannon distance verification with exact-value, symmetry, normalization, cancellation, zero-support, bounds, schema, and end-to-end assertions. Clarify the mathematical domain and smoothing semantics in the docs, and remove a stale chart whose embedded values used the old natural-log scale. ## Prompting Intent Independently make GitHub PR microsoft#2631 merge-ready by auditing its full mathematical and runtime behavior, API compatibility, edge cases, related PR microsoft#2630 interactions, review feedback, checks, generated bindings, Spark compatibility, and downstream documentation. Fix every valid issue without bundling the separate reference-support implementation. ## Linked Sources - GitHub issue microsoft#2006: microsoft#2006 - Pull request microsoft#2631: microsoft#2631 - Related reference-support pull request microsoft#2630: microsoft#2630 - Copilot review feedback: microsoft#2631 (review) - Jensen-Shannon definition: https://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence ## Rationale Keep the production correction narrowly scoped to dividing Jensen-Shannon divergence by ln(2), preserving natural-log KL divergence and all public APIs. Use independently calculated constants and tolerant assertions to validate semantics across Spark/JVM versions. Document that the unit bound assumes valid probability distributions and that midpoint mixing, not additive smoothing, handles zero support. Leave reference-only category materialization and custom-distribution validation to microsoft#2630 to avoid duplicating unrelated work. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fb81306 to
5d91a61
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
## Summary Address the latest automated review by using explicit unused count values in the JS-distance expression fixture and rewriting the sample interpretation relative to the uniform reference distribution with corrected wording. ## Prompting Intent Resolve every valid active review comment on GitHub PR microsoft#2631, preserve the strong normalized-distance coverage, and keep the documentation mathematically consistent before rerunning required checks. ## Linked Sources - Pull request microsoft#2631: microsoft#2631 - Count-fixture review comment: microsoft#2631 (comment) - Notebook wording review comment: microsoft#2631 (comment) ## Rationale Counts are not read by the private JS-distance expression, so explicit zero placeholders communicate that fact without pretending probabilities are counts. The notebook now compares observed data directly with the configured uniform reference rather than using ambiguous balance terminology. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
docs/Explore Algorithms/Responsible AI/Data Balance Analysis.md:166
- This JS Distance table row contains a large run of whitespace padding inside the table cell (between the sentence ending and the next
|). It doesn’t affect rendering, but it makes the markdown noisier to edit and can create unnecessary diffs.
| JS Distance | Square root of the average base-2 KL divergence from each distribution to their midpoint mixture. The mixture handles zero-probability support without additive smoothing. | For finite, non-negative distributions with unit sum, the range is [0, 1]. 0 means identical distributions; 1 means disjoint support. | [Link](https://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence) |
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
## Summary Compact the JS Distance markdown row so the corrected mathematical description remains easy to review and edit without large whitespace-only spans. ## Prompting Intent Audit and address suppressed as well as active review feedback on GitHub PR microsoft#2631 before declaring the change ready. ## Linked Sources - Pull request microsoft#2631: microsoft#2631 - Final Copilot review with suppressed feedback: microsoft#2631 (review) ## Rationale Markdown tables do not require visual source alignment. Removing cell padding preserves rendered output while preventing noisy future diffs and directly addresses the suppressed review finding. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Addressed the final suppressed review feedback in 54e4cea by compacting the JS Distance markdown row without changing rendered content. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Brendan Walsh (@BrendanWalsh) final review requested: head |
|
Final verification for
The only remaining repository-rule gate is the requested non-author/last-push approval from Brendan Walsh (@BrendanWalsh). |
Related Issues/PRs
Fixes #2006
Related: #2630 independently fixes reference-only category support and custom-reference validation. This PR deliberately does not bundle that work. After #2631 merges, #2630 should rebase and update its two explicit natural-log JS expectations to the normalized scale.
What changes are proposed in this pull request?
Normalize Jensen-Shannon distance to its documented
[0, 1]range by converting only its divergence from natural-log units to base-2 units:JS distance = sqrt((KL(P || M) + KL(Q || M)) / (2 * ln(2)))The shared relative-entropy helper remains natural-log based, so KL divergence and all other distribution-balance metrics keep their existing semantics and public API. A lower-bound guard clamps negative floating-point cancellation before
sqrt.Coverage now verifies:
0; disjoint distributions =10.999998765189656[0, 1]bounds with cross-runtime tolerancetransformSchemaparity end-to-endDocs now state the finite/non-negative/unit-sum domain, midpoint-mixture semantics, no additive smoothing, normalized sample values, and remove the stale static chart that displayed the old scale.
How is this patch tested?
core/compile scalastyle test:scalastyle codegen core/testOnly ...DistributionBalanceMeasureSuite— passedtest:compilepassed on Java 17 / Scala 2.13code-reviewchecklist — no remaining concrete findingsCompatibility
js_distnumerical scale changes.Final validated revisions
f7a1dc50d09d400d279d08bf69a1fac32289674854e4cead22567f11765f4f51fb85880e8e420dd3