Dev - #5
Open
balaji1810 wants to merge 2 commits into
Open
Dev#5balaji1810 wants to merge 2 commits into
balaji1810 wants to merge 2 commits into
Conversation
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.
Closed-form LCD approximation for even-dimensional Gaussians
1. The objective
With samples$s_1 \dots s_L$ , weights $w_i$ , $W = \sum_i w_i$ , and writing $c_i = | s_i |^2$ and $T_{ij} = | s_i - s_j |^2$ , the distance splits into
The even -$N$ restriction is what makes $D_2$ integrable in closed form: with $N = 2k$ the fractional power $(\cdot)^{N/2}$ becomes the integer power $(\cdot)^k$ , and the integral collapses to a finite binomial sum.
2. The closed forms
All in$U = 1 + 2b^2$ , $e_U = \exp(-c/(2U))$ , $e_0 = \exp(-c/2)$ , and $\Delta E = \text{Ei}(-c/(2U)) - \text{Ei}(-c/2)$ .
lib/gm_to_dirac_even/lcd_even_closed_form.h. Throughout,lcd_a_n(N, b)- theValid for all$N$ , odd and even.
lcd_c_repulsion(b, c)- the per-pairwith$C(b,0) = b^2/2$ .
lcd_delta_bkk(k, b, c)andlcd_delta_bkk1(k, b, c)- the per-samplelcd_delta_bkkislcd_delta_bkk1isThe recursion terminates at$d = 2$ because the coefficient carries a factor $(d-2)$ . In the code this is $I_d / 4$ ; $q = k$ or $q = k+1$ , so both functions share one implementation.
lcd_delta_b0, which returnslcd_delta_bkk_closedwalks the binomial sum with theshiftparameter selectinglcd_delta_bkk_zero(k, b)- theThis is$O(b^2)$ by construction, it is the constant that gets pulled out of the objective.
lcd_delta_bkk_reduced(k, b, c)- the cancellation-free attraction termComputed with$I_0$ term so the $O(b^2)$ piece $2^{-k}U/4$ is never formed in floating point; $O(\ln U)$ part.
expm1in the leadinglcd_delta_bkk_zero_minus_leadingremoves the remaininglcd_reported_offset(N, b, W)- the constant that restores the true distancecollecting, in order, the$D_1$ term, the per-sample attraction constant and the per-pair repulsion constant. Each piece is $O(b^2)$ , but the leading parts combine to $\frac{1}{2}(1-W)^2 b^2$ , which vanishes for normalised weights.
For$N=2$ the branch is algebraically rearranged so that cancellation is exact rather than asymptotic:
3. How they are assembled
Objective ($O(b^2)$ constant has been removed analytically:
calculateD2+calculateD3, both in the.tpp). The optimizer minimises a reduced objective in which everyThe first sum is$\frac{b^2}{2}\text{expm1}(z) + \frac{c}{8}\text{Ei}(z)$ , so coincident and self-pairs ($T_{ij}=0$ ) contribute exactly zero instead of $b^2/2$ each.
lcd_delta_bkk_reduced; the second is written inline asGradient. Since$c_q = | s_q |^2$ and $\partial B_{k,k} / \partial c = -\frac{1}{2} B_{k,k+1}$ :
The$D_3$ part is unusually clean because the three pieces of $\partial C / \partial c$ collapse to $\frac{1}{8}\text{Ei}(z)$ , so one
Eievaluation per pair serves both objective and gradient.Reported distance.$K$ once in its constructor, and
GMToDiracEvenOptimizationParamscomputesmodified_van_mises_distance_sqalways reports this trueincludeD1InObjective = true) - sinceApproximateOptions::ftolRel(default1e-10) meaningful instead of firing against a large constant. This follows the pattern of #4, already onmain.