Fixes fixes fixes
This commit is contained in:
+131
-57
@@ -286,20 +286,32 @@ Direct integration is not tractable, but the integral is well-approximated by av
|
||||
\mathcal{L}_{\text{ROLL-AOC}} = \frac{1}{99}\sum_{i=1}^{99}\mathcal{L}_{\text{ROLL-TPR@FPR}}\!\left(\frac{i}{100}\right)
|
||||
\label{eq:roll-aoc}
|
||||
\end{equation}
|
||||
Since $\operatorname{TPR}(\alpha)$ is monotone in $\alpha$ along the ROC curve,
|
||||
$g(\alpha) := 1-\operatorname{TPR}(\alpha)$ is monotone and bounded in $[0,1]$, so
|
||||
\eqref{eq:roll-aoc} approximates $\int_0^1 g(\alpha)\,d\alpha$ to within
|
||||
$1/99 \approx 0.01$ by a standard Darboux-sum argument, assuming each per-threshold
|
||||
term is evaluated exactly. This bound covers only the quadrature step: it does not
|
||||
extend to the gradient \eqref{eq:roll-aoc-gradient}, nor does it account for the gap
|
||||
between the KDE-fitted rates and the raw empirical scores (\Cref{sec:roll-instantiations})
|
||||
or any residual numerical error in the per-threshold bisection for $\tau_k$.
|
||||
|
||||
The gradient follows by linearity of the sum:
|
||||
\begin{equation}
|
||||
\frac{\partial \mathcal{L}_{\text{ROLL-AOC}}(f_\theta(\mathbf{X}))}
|
||||
{\partial f_\theta(\mathbf{x}_i)} = \frac{1}{99}\sum_{i=1}^{99}\frac{\partial \mathcal{L}_{\text{ROLL-TPR@FPR}}\!\left(f_\theta(\mathbf{X}) ; \frac{i}{100}\right)}
|
||||
{\partial f_\theta(\mathbf{x}_i)} = \frac{1}{99}\sum_{r=1}^{99}\frac{\partial \mathcal{L}_{\text{ROLL-TPR@FPR}}\!\left(f_\theta(\mathbf{X}) ; \frac{r}{100}\right)}
|
||||
{\partial f_\theta(\mathbf{x}_i)}
|
||||
\label{eq:roll-aoc-gradient}
|
||||
\end{equation}
|
||||
(the summation index $r$ ranges over the $99$ thresholds; $i$, fixed throughout the sum,
|
||||
indexes the sample being differentiated — distinct roles that \eqref{eq:roll-aoc} does
|
||||
not need to distinguish, since it has no outer per-sample index to collide with.)
|
||||
The concrete per-threshold gradient for the KDE instantiation is derived in
|
||||
\Cref{sec:roll-instantiations}; gradients for the parametric cases are in
|
||||
\Cref{appendix:gauss-grad,appendix:beta-roll}.
|
||||
|
||||
\Cref{fig:roll-aoc-roc} gives a geometric view of this objective.
|
||||
|
||||
\begin{figure}[H]
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=0.62\textwidth]{content/method/figures/roll_aoc_roc.pdf}
|
||||
\caption{Geometric interpretation of ROLL-AOC. The ROC curve (orange) maps
|
||||
@@ -312,7 +324,8 @@ The concrete per-threshold gradient for the KDE instantiation is derived in
|
||||
segments show the per-threshold loss contribution
|
||||
$1 - \operatorname{TPR}(\alpha_i) = \mathcal{L}_{\text{ROLL-TPR@FPR}}(\alpha_i)$
|
||||
at each point. Averaging these contributions (99 in practice, 10 shown
|
||||
for clarity) gives the value of \eqref{eq:roll-aoc}.}
|
||||
for clarity) approximates the continuous integral, giving the value of
|
||||
\eqref{eq:roll-aoc}.}
|
||||
\label{fig:roll-aoc-roc}
|
||||
\end{figure}
|
||||
|
||||
@@ -335,15 +348,16 @@ Parametric families, however, impose distributional assumptions on the score out
|
||||
no trained model can be guaranteed to satisfy. The primary instantiation in this thesis
|
||||
is therefore non-parametric: Kernel Density Estimation (KDE) places no assumption on the
|
||||
shape of the score distribution and adapts to whatever the model produces at each training
|
||||
step. The cost is a numerical CDF inversion and a custom backward pass; the gain is a
|
||||
faithful surrogate for the ROC curve regardless of how scores evolve during training.
|
||||
step. The cost is a numerical CDF inversion and a custom backward pass. The gain is a
|
||||
surrogate that adapts to the score distribution's shape as it evolves during training,
|
||||
without committing to a parametric assumption that may not hold.
|
||||
|
||||
\subsection{KDE ROLL}
|
||||
\label{sec:roll-kde}
|
||||
|
||||
KDE estimates the score distribution directly from the observed batch scores, placing no
|
||||
assumption on their shape. It is the primary instantiation of ROLL used throughout this
|
||||
thesis: its non-parametric flexibility makes it the most faithful surrogate for the ROC
|
||||
thesis: its non-parametric flexibility makes it the most adaptable surrogate for the ROC
|
||||
curve when score distributions are unknown, at the cost of a numerical CDF inversion and
|
||||
a custom backward pass evaluated 99 times per training step under ROLL-AOC.
|
||||
|
||||
@@ -437,13 +451,11 @@ Appendix~\ref{appendix:bandwidth-freeze} shows by counterexample.
|
||||
% guarantees ROLL provides and under what assumptions they hold.
|
||||
% NOTE - these properties are auto-generated, consider suggestions.
|
||||
|
||||
A structural consequence of the ROLL formulation is that gradient mass is automatically
|
||||
balanced between the two classes, regardless of their relative sizes in the batch.
|
||||
This stands in contrast to standard losses such as cross-entropy, where the total gradient
|
||||
contribution from each class is proportional to its count, making heavy class imbalance
|
||||
a direct source of biased updates. Therefore, instead of needing to compensate for this
|
||||
with loss-weighting per-class, fitting updates are made based equally off the results
|
||||
of both classes.
|
||||
A structural consequence of the ROLL formulation is that the total signed
|
||||
gradient contribution from each class cancels exactly, regardless of their relative
|
||||
sizes in the batch. This stands in contrast to standard losses such as cross-entropy,
|
||||
where the total gradient contribution from each class is proportional to its count,
|
||||
making heavy class imbalance a direct source of biased updates.
|
||||
|
||||
\begin{proposition}[Gradient balance]
|
||||
\label{prop:gradient-balance}
|
||||
@@ -471,9 +483,15 @@ as well as the KDE-based distribution, but not for the Beta distribution.
|
||||
For Gaussian MLE, a uniform shift in scores moves $\mu_k$ by the same amount while
|
||||
leaving $\sigma_k$ unchanged, which translates $\hat{F}_k$; for KDE, each kernel term is
|
||||
evaluated at $\tau - f_\theta(\mathbf{x}_j)$, so a uniform shift in the $f_\theta(\mathbf{x}_j)$
|
||||
is equivalent to an equal shift in $\tau$. The condition is necessary: without it, a uniform
|
||||
score shift need not produce a rigid translation of $\hat{F}_k$, so the shift argument in the
|
||||
proof breaks down and the gradient sums need not be equal.
|
||||
is equivalent to an equal shift in $\tau$. The condition is sufficient, not necessary: it is
|
||||
what the proof uses to guarantee a rigid translation of $\hat{F}_k$, but the balance identity
|
||||
can hold without it. For example, $\hat{F}_k(t;\mathbf{s}) = \Phi(t - 2\bar{s})$ (with
|
||||
$\bar{s}$ the class mean) does not satisfy $\hat{F}_k(t;\mathbf{s}+\delta) = \hat{F}_k(t-\delta;\mathbf{s})$
|
||||
— shifting the scores by $\delta$ shifts $\hat{F}_k$ by $2\delta$, not $\delta$ — yet applying
|
||||
this same construction to both classes still yields $\sum_{\mathcal{B}_1}\partial L/\partial f_i
|
||||
= -\sum_{\mathcal{B}_0}\partial L/\partial f_i$ exactly, since the extra factor of $2$ enters
|
||||
both classes' gradients identically and cancels in the same shift argument. Translation
|
||||
invariance is a convenient sufficient condition, not the weakest one that would do.
|
||||
|
||||
The Beta distribution only accepts values in the interval $[0, 1]$. Since it
|
||||
is mapped only over an interval, the translation-invariance assumption does not hold
|
||||
@@ -486,6 +504,19 @@ average of 99 per-threshold objectives each satisfying \eqref{eq:grad-balance},
|
||||
is preserved by linearity of summation.
|
||||
\end{corollary}
|
||||
|
||||
The identity \eqref{eq:grad-balance} constrains only the signed sum per class. It
|
||||
does not by itself say that each class contributes equal gradient mass,
|
||||
$\sum_i |\partial\mathcal{L}/\partial f_\theta(\mathbf{x}_i)|$. Equal gradient-mass is satisfied
|
||||
when every sample within a class shares the same gradient sign, so that the signed and
|
||||
absolute sums are equal in magnitude. For KDE-ROLL,
|
||||
this extra property does hold (\Cref{obs:gradient-sign-correctness} below), so the
|
||||
signed identity does translate into balanced gradient mass for the method used
|
||||
throughout this thesis. However, notably, this does not hold true for the Gaussian formulation.
|
||||
|
||||
Additionally, \Cref{prop:gradient-balance} is a statement about the per-sample loss
|
||||
gradients $\partial\mathcal{L}/\partial f_\theta(\mathbf{x}_i)$ at the model's output. It
|
||||
does not extend to the resulting parameter gradients $\partial\mathcal{L}/\partial\theta$,
|
||||
as this depends on the model's structure.
|
||||
\paragraph{Gradient sign correctness.}
|
||||
\label{para:gradient-sign-correctness}
|
||||
|
||||
@@ -518,28 +549,42 @@ the fully adaptive gradient violates this sign guarantee.
|
||||
\label{para:gradient-locality}
|
||||
|
||||
A second structural consequence of the ROLL-KDE formulation, when optimizing at a
|
||||
single operating threshold, is that gradient mass is \emph{concentrated near that
|
||||
threshold $\tau$}. Samples whose scores lie close to $\tau$ receive larger gradient
|
||||
updates, while samples already far on the correct side contribute very little.
|
||||
single operating threshold, is that gradient magnitude concentrates near $\tau$, but
|
||||
the mechanism differs between the two classes, and so does how literally the claim
|
||||
holds.
|
||||
|
||||
This follows directly from \Cref{eq:kde-grad-combined}. For the positive class ($y_i = 1$),
|
||||
the gradient magnitude is
|
||||
This follows from \Cref{eq:kde-grad-combined}. For the positive class ($y_i = 1$), the
|
||||
gradient magnitude is an absolute, unnormalised function of the sample's own
|
||||
distance to $\tau$:
|
||||
\[
|
||||
\left|\frac{\partial \mathcal{L}}{\partial f_\theta(\mathbf{x}_i)}\right|
|
||||
= \frac{1}{|\mathcal{B}_1|}\,\sigma_1'(f_\theta(\mathbf{x}_i) - \tau),
|
||||
\]
|
||||
which is a bell-shaped kernel PDF that peaks when $f_\theta(\mathbf{x}_i) = \tau$ and
|
||||
decays to zero as the score moves away from the threshold in either direction.
|
||||
For the negative class ($y_i = 0$), the gradient is proportional to
|
||||
$\sigma_0'(\tau - f_\theta(\mathbf{x}_i))$ (normalized over $\mathcal{B}_0$), which is
|
||||
again bell-shaped and centred on $\tau$.
|
||||
a bell-shaped kernel PDF that peaks when $f_\theta(\mathbf{x}_i) = \tau$ and decays to
|
||||
exactly $0$ as $|f_\theta(\mathbf{x}_i)-\tau|\to\infty$, regardless of where any other
|
||||
sample lies. For this class, "far from $\tau$ implies negligible gradient" holds without
|
||||
qualification.
|
||||
|
||||
The effect is that each gradient step focuses the model's attention on the region that
|
||||
directly determines the operating-point performance: samples that could plausibly be
|
||||
re-ranked relative to the threshold at the current step. Samples classified with strong
|
||||
confidence relative to the threshold, with scores far enough away from said threshold,
|
||||
receive small gradient updates, since a small change to the score of these samples will not
|
||||
bring any change to the placement of the threshold itself, or the performance at said threshold.
|
||||
For the negative class ($y_i = 0$), the gradient is instead a \emph{normalised share} of
|
||||
the class's total kernel mass, $\sigma_0'(\tau-f_\theta(\mathbf{x}_i)) \big/
|
||||
\sum_j \sigma_0'(\tau-f_\theta(\mathbf{x}_j))$, and this ratio doesn't vanish just
|
||||
because $f_\theta(\mathbf{x}_i)$ is far from $\tau$: what determines
|
||||
sample $i$'s share of the gradient mass is its position relative to the rest of $\mathcal{B}_0$,
|
||||
not its absolute distance to $\tau$. If the whole negative class drifts far from $\tau$
|
||||
together, every individual $\sigma_0'$ value shrinks, but so does their sum, and the
|
||||
ratio can converge to a nonzero constant no matter how far the class has drifted.
|
||||
Concretely, for two negative samples at $\tau+M$ and $\tau+M+1$ (a fixed unit
|
||||
separation), the closer sample's normalised weight converges, as $M\to\infty$, to
|
||||
$1/(1+e^{-v_0})$, $\approx 0.731$ at $v_0=1$, not to $0$.
|
||||
However, if a single score drifts far from $\tau$ while the rest of it's class scores,
|
||||
stay close, its individual score will converge to zero.
|
||||
|
||||
The effect, for both classes, is that each gradient step focuses the model's attention
|
||||
on the samples whose re-ranking relative to $\tau$ would most change the operating-point
|
||||
performance. For the positive class this is an absolute statement about each sample's
|
||||
own distance to $\tau$, and for the negative class, it is a statement about each sample's
|
||||
distance relative to its classmates. Typically, but not necessarily, this correlates
|
||||
with its absolute distance to $\tau$.
|
||||
|
||||
This stands in contrast to standard losses such as cross-entropy, where the per-sample
|
||||
gradient is determined by the predicted probability, with no direct dependence on an
|
||||
@@ -547,27 +592,36 @@ operating threshold.
|
||||
|
||||
\begin{observation}[Gradient locality, single-threshold]
|
||||
\label{obs:gradient-locality}
|
||||
For KDE-ROLL at a single operating threshold, the gradient magnitude of sample
|
||||
$\mathbf{x}_i$ is proportional to the kernel PDF evaluated at the distance between
|
||||
$f_\theta(\mathbf{x}_i)$ and $\tau$. Samples nearest to $\tau$ receive the largest
|
||||
updates; samples far from $\tau$ in either direction contribute negligible gradient.
|
||||
For KDE-ROLL at a single operating threshold: (a) a positive-class sample's gradient
|
||||
magnitude is the kernel PDF evaluated at its own distance to $\tau$, and vanishes as
|
||||
that distance grows, independent of the rest of the batch. (b) a negative-class
|
||||
sample's gradient magnitude is its kernel-PDF value \emph{relative to the sum over
|
||||
$\mathcal{B}_0$} — samples near $\tau$ receive a larger share than those far from it
|
||||
\emph{within the same batch}, but this relative weighting does not by itself vanish
|
||||
for an individual sample merely because the whole class is far from $\tau$.
|
||||
\end{observation}
|
||||
|
||||
\Cref{fig:threshold-locality} illustrates this for a simulated two-class setting. The
|
||||
\Cref{fig:threshold-locality} illustrates this for a simulated two-class setting in
|
||||
which both classes are broadly spread around $\tau$ — the typical case, and the one in
|
||||
which the negative class's relative weighting (\Cref{obs:gradient-locality}b) and the
|
||||
positive class's absolute decay (\Cref{obs:gradient-locality}a) happen to agree. The
|
||||
upper panel shows the score distributions and the operating threshold; the lower panel
|
||||
shows the gradient magnitude of each sample. Both classes exhibit a clear bell-shaped
|
||||
concentration of gradient mass around $\tau$, with smooth decay on either side.
|
||||
shows the gradient magnitude of each sample, with a clear bell-shaped concentration
|
||||
around $\tau$ for both classes in this regime.
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=0.82\textwidth]{content/method/figures/threshold_weighting.pdf}
|
||||
\caption{Gradient locality in KDE-ROLL. \textit{Upper}: score distributions for the
|
||||
negative (blue, $y=0$) and positive (orange, $y=1$) classes; dashed line marks the
|
||||
operating threshold $\tau$ at FPR $= \alpha$. \textit{Lower}: gradient magnitude
|
||||
\caption{Gradient locality in KDE-ROLL, for a batch where both classes are spread
|
||||
broadly around $\tau$. \textit{Upper}: score distributions for the negative (blue,
|
||||
$y=0$) and positive (orange, $y=1$) classes; dashed line marks the operating
|
||||
threshold $\tau$ at FPR $= \alpha$. \textit{Lower}: gradient magnitude
|
||||
$|\partial\mathcal{L}/\partial f_\theta(\mathbf{x})|$ for each sample. Both classes
|
||||
show a bell-shaped concentration of gradient mass near $\tau$, with samples far from
|
||||
the threshold contributing negligible updates. Smooth curves are the kernel PDFs scaled
|
||||
for reference.}
|
||||
show a bell-shaped concentration of gradient mass near $\tau$ here; for the negative
|
||||
class this reflects relative weighting within $\mathcal{B}_0$
|
||||
(\Cref{obs:gradient-locality}b), which need not track absolute distance to $\tau$ if
|
||||
the whole class is displaced together. Smooth curves are the kernel PDFs scaled for
|
||||
reference.}
|
||||
\label{fig:threshold-locality}
|
||||
\end{figure}
|
||||
|
||||
@@ -596,19 +650,39 @@ deviation:
|
||||
\qquad
|
||||
\hat\sigma_{\mathcal{B}} = \sqrt{\operatorname{Var}(f_\theta(\mathbf{x}_i) : (\mathbf{x}_i, y_i) \in \mathcal{B})}.
|
||||
\]
|
||||
This keeps the values given to the sigmoid kernel ($v(\tau - \tilde{s}_j)$)
|
||||
near unit scale, preventing floating-point overflow and underflow in the exponential
|
||||
evaluations.
|
||||
This keeps the values given to the sigmoid kernel at a consistent scale. Why that
|
||||
matters depends entirely on which bandwidth estimator is in play.
|
||||
|
||||
The scaling has no effect on the loss value itself or derived gradients.
|
||||
Silverman's rule derives the bandwidth proportionally to the data standard deviation,
|
||||
$h \propto \hat\sigma \cdot n^{-1/5}$, so dividing all scores by $\hat\sigma_\mathcal{B}$
|
||||
causes the bandwidth to scale by the same factor.
|
||||
The product $v \cdot (\tau - s_j)$ (the only quantity entering the sigmoid) is
|
||||
therefore invariant under the rescaling.
|
||||
In the backward pass, gradients with respect to the normalised scores are multiplied
|
||||
by $1/\hat\sigma_\mathcal{B}$ to apply the chain rule, providing gradients mathematically
|
||||
identical to those that would have been obtained without normalisation.
|
||||
\begin{proposition}[Normalisation invariance under scale-equivariant bandwidth]
|
||||
\label{prop:normalization-invariance}
|
||||
Let $\hat{h}$ be any bandwidth estimator satisfying $\hat{h}(a\cdot x) = a\cdot\hat{h}(x)$
|
||||
for all $a>0$ (e.g.\ Silverman's rule, $h \propto \hat\sigma \cdot n^{-1/5}$). Under the
|
||||
frozen-bandwidth convention of \Cref{sec:roll-kde-backward} and a frozen normalisation
|
||||
constant $\hat\sigma_\mathcal{B}$, the loss value and every per-sample gradient
|
||||
$\partial \mathcal{L}_{\text{ROLL-TPR@FPR}}/\partial f_\theta(\mathbf{x}_i)$ computed from
|
||||
the normalised scores $\tilde{s}$ are exactly equal to those computed directly from the
|
||||
raw scores $s$.
|
||||
\end{proposition}
|
||||
\begin{proof}
|
||||
See Appendix~\ref{appendix:score-normalization}.
|
||||
\end{proof}
|
||||
|
||||
For Silverman's rule, normalisation is therefore a pure floating-point reparametrisation:
|
||||
it changes neither the loss nor the gradient used for training, so it cannot be what
|
||||
prevents overflow for that estimator — there is nothing left for it to change.
|
||||
ISJ, the primary bandwidth estimator (\Cref{sec:kde-bandwidth}), does \emph{not} satisfy
|
||||
the proposition's hypothesis (Appendix~\ref{appendix:score-normalization} measures its
|
||||
scale-dependence directly). For ISJ, both the loss value and the gradient genuinely
|
||||
depend on whether the scores are normalised, so normalisation is doing real work: it
|
||||
pins ISJ's input to the one scale regime it behaves consistently in, rather than leaving
|
||||
it to drift with the model's raw output scale over training.
|
||||
|
||||
As with the bandwidths $v_0,v_1$, the normalisation constant $\hat\sigma_\mathcal{B}$ is
|
||||
treated as frozen (stop-gradient) in the backward pass: gradients with respect to the
|
||||
normalised scores are simply multiplied by $1/\hat\sigma_\mathcal{B}$. Differentiating
|
||||
fully through $\hat\sigma_\mathcal{B}$ instead introduces a further correction term that,
|
||||
like the bandwidth correction of \Cref{sec:roll-kde-backward}, can violate
|
||||
\Cref{obs:gradient-sign-correctness} (Appendix~\ref{appendix:score-normalization}).
|
||||
|
||||
\subsection{Bandwidth Estimation for KDE}
|
||||
\label{sec:kde-bandwidth}
|
||||
|
||||
Reference in New Issue
Block a user