Compare commits

..

2 Commits

Author SHA1 Message Date
aner 342efd836d A lot written. 2026-07-02 15:31:32 +03:00
aner 06687667d5 Small fixes 2026-07-01 08:47:16 +03:00
+154 -6
View File
@@ -231,7 +231,7 @@ This yields two versions of our objective. Substituting the ICDF threshold into
expressions, our estimated TPR at a fixed FPR of $\alpha$ is $1 - \hat{F}_1(\hat{F}_0^{-1}(\alpha))$.
Therefore, to maximise TPR we minimise:
\begin{equation}
\mathcal{L}_{\text{ROLL-TPR@FPR}}(f_{\theta}(\mathbf{X}) ; \alpha) = \hat{F}_1(\hat{F}_0^{-1}(\alpha))
\mathcal{L}_{\text{ROLL-TPR@FPR}}(f_{\theta}(\mathcal{B}) ; \alpha) = \hat{F}_1(\hat{F}_0^{-1}(\alpha))
\label{eq:roll-tpr-at-fpr}
\end{equation}
@@ -250,7 +250,7 @@ As both loss forms are symmetric in structure, it is sufficient to treat the TPR
If $y_i = 1$, then $(\mathbf{x}_i, y_i) \in \mathcal{B}_1$ and $f_\theta(\mathbf{x}_i)$ has no
effect on $\hat{F}_0^{-1}(\alpha)$. Therefore:
\begin{equation}
\left.\frac{\partial \mathcal{L}_{\text{ROLL-TPR@FPR}}(f_\theta(\mathbf{X}) ; \alpha)}
\left.\frac{\partial \mathcal{L}_{\text{ROLL-TPR@FPR}}(f_\theta(\mathcal{B}) ; \alpha)}
{\partial f_\theta(\mathbf{x}_i)}\right|_{y_i = 1}
= \frac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial f_\theta(\mathbf{x}_i)}
\end{equation}
@@ -366,14 +366,11 @@ where TODO EXPLAIN ERF AND IERF. Plugging into the general ROLL framework, the t
$\tau$ achieving FPR $= \alpha$ and the resulting loss are:
\begin{align}
\tau &= \mu_0 + \sigma_0\sqrt{2}\,\text{ierf}(2\alpha - 1) \nonumber \\
\mathcal{L}_{\text{ROLL-TPR@FPR}}^{\text{GAUSSIAN}}(f_{\theta}(\mathbf{X}) ; \alpha)
\mathcal{L}_{\text{ROLL-TPR@FPR}}^{\text{GAUSSIAN}}(f_{\theta}(\mathcal{B}) ; \alpha)
&= \frac{1}{2}\left[1 + \text{erf}\!\left(\frac{\tau - \mu_1}{\sigma_1\sqrt{2}}\right)\right]
\label{eq:roll-tpr-at-fpr-gaussian}
\end{align}
\subsubsection{Gradient Derivation}
\label{sec:roll-gaussian-backward}
@@ -382,6 +379,50 @@ $\tau$ achieving FPR $= \alpha$ and the resulting loss are:
% functions of the scores), and through $\Phi$ and $\Phi^{-1}$, which have
% simple closed-form derivatives.
In order to compute the gradient derivation for the gaussian estimates we must first compute the gradient to each of the parameters.
Firstly, for $y_i = 1$.
\[
\dfrac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial \mu_1} =
\frac{\partial \frac{1}{2}\left[1 + \text{erf}\!\left(\frac{\hat{F}_0^{-1}(\alpha) - \mu_1}{\sigma_1\sqrt{2}}\right)\right]}{\partial \mu_1}
\]
\[
= \frac{1}{\sqrt{2}\sigma_1}\exp\left(\frac{\hat{F}_0^{-1}(\alpha) - \mu_1}{\sqrt{2}\sigma_1}\right)
\]
\[
\frac{\partial \mu_1}{\partial f_{\theta}(\mathbf{x}_i)} = \frac{1}{|\mathcal{B}_1|}
\]
\[
\dfrac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial \sigma_1} =
\frac{\partial \frac{1}{2}\left[1 + \text{erf}\!\left(\frac{\hat{F}_0^{-1}(\alpha) - \mu_1}{\sigma_1\sqrt{2}}\right)\right]}{\partial \sigma_1}
\]
\[
= \frac{\hat{F}_0^{-1}(\alpha)-\mu_1}{\sqrt{2\pi}\sigma_1^2} \exp\left( - {\left( \frac{\hat{F}_0^{-1}(\alpha) - \mu_1}{\sqrt{2}\sigma_1} \right)}^2 \right)
\]
\[
\frac{\partial \sigma_1}{\partial f_{\theta}(\mathbf{x}_i)} = \frac{\mathbf{x}_i - \mu_1}{|\mathcal{B}_1| \sigma_1}
\]
The final derivation, given $y_i = 1$, is given as:
\[
\dfrac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial f_{\theta}(\mathbf{x}_i)} = \dfrac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial \mu_1} \cdot \frac{1}{|\mathcal{B}_1|} +
\dfrac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial \sigma_1} \cdot \frac{\partial \sigma_1}{\partial f_{\theta}(\mathbf{x}_i)} = \frac{\mathbf{x}_i - \mu_1}{|\mathcal{B}_1| \sigma_1}
\]
TODO - above equation is based off of mathexchange derivation. Link and reference properly!
Given $y_i = 0$ we first must derive:
\[
\dfrac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial \hat{F}_0^{-1}(\alpha)} = \frac{1}{\sqrt{2 \pi \sigma_1^2}}\exp\left( -{\left( \frac{\hat{F}_0^{-1}(\alpha) - \mu_1}{2\sigma_1^2}\right)}^2\right)
\]
TODO finish somehow - later!
\subsection{Beta ROLL}
\label{sec:roll-beta}
@@ -413,6 +454,10 @@ $\tau$ achieving FPR $= \alpha$ and the resulting loss are:
% Discuss the trade-off between flexibility and computational cost, and how
% the bandwidth (see \Cref{sec:kde-bandwidth}) controls bias-variance.
Unfortunately, the score output of trained models remains unpredictable. A solution for this is to use a Kernel Density Estimation (KDE) for probability
estimation. This benefits from being far more adaptable to real-world distributions of outputs of our trained models. The tradeoff of course is computational
complexity - computing the gradient derivation in such a case is non-trivial.
\subsubsection{Forward}
\label{sec:roll-kde-forward}
@@ -420,6 +465,55 @@ $\tau$ achieving FPR $= \alpha$ and the resulting loss are:
% kernel CDFs; the ICDF is computed numerically. Derive the loss expression
% explicitly and discuss computational cost relative to the parametric cases.
As before, to calculate the loss, we calculate:
\[
\mathcal{L}_{\text{ROLL-TPR@FPR}}^{\text{KDE}}(f_{\theta}(\mathcal{B}) ; \alpha) = \hat{F}_1(\hat{F}_0^{-1}(\alpha))
\label{eq:roll-tpr-at-fpr}
\]
To calculate this, we first define the kernel function as $\sigma '$, and the CDF of the kernel function as $\sigma$. The approach used here is to define $\sigma$ as a sigmoid function,.
\begin{equation}
\sigma(x ; v) = \left( 1 + \exp(-vx)\right)^{-1} \qquad \sigma'(x ; v) = \frac{v \cdot \exp(-v \cdot x)}{(1 + \exp(-vx))^2}
\end{equation}
Where $v$ is the bandwidth parameter. This affects the calculation. We calculate $v_0$ as the bandwidth for the false population and $v_1$ for the true population. Bandwidth calculation
will be discussed later.
We then denote $\sigma_1(x) = \sigma(x ; v_1), \sigma_0(x) = \sigma(x ; v_0)$ to differentiate between the kernel functions for the true and false population, which only differentiate by bandwidth.
The CDF of the KDE function then becomes:
\[
\hat{F}_{KDE}(\tau ; \mathbf{X}) = \frac{1}{|X|}\sum_i \sigma(\tau - x_i)
\]
While the CDF has a nice formula, the inverse CDF has no known closed formula. It instead must be calculated numerically. Thus, the calculation of the decision threshold $\tau$ must be achevied
using a numerical calculation algorithm. In this work, Newton Raphson is chosen.
Firstly we must calculate $\hat{F}_0^{-1}(\alpha)$ = \tau. We start with our initial guess, $\tau_0$, and for each step, calculate:
\[
\tau_{n+1} = \tau_n - \frac{\hat{F}_0(\tau_n ; \mathcal{X}_0)}{\frac{\partial \hat{F}_0(\tau_n ; \mathcal{X}_0)}{\partial \tau}}
\]
This step is taken until $\hat{F}_0(\tau_n ; \mathcal{B}_0) \approx \alpha$ within some acceptable error (in our case $1e-3$).
Our derivative w.r.t. $\tau$ is
\[ %
\frac{\partial \hat{F}_0(\tau_n ; \mathcal{X}_0)}{\partial \tau} = \frac{1}{\mathcal{X}_0}\sum_i \sigma'(\tau - x_i)
\]
At this point, we have succesfully calculated $\tau$ for which $\tau = \hat{F}_0^{-1}(\alpha ; \mathbf{X}_0)$.
We can now relatively easily calculate $\hat{F}_1(\tau ; \mathbf{X}_1)$ using the formulat for $\hat{F}_{KDE}(\tau ; \mathbf{X})$ above.
Importantly, we must save the calculation of $\tau$ for the backward derivation, as well as the calculated bandwidths $v_1, v_0$.
\subsubsection{Gradient Derivation}
\label{sec:roll-kde-backward}
@@ -428,6 +522,60 @@ $\tau$ achieving FPR $= \alpha$ and the resulting loss are:
% Gradients flow through the kernel evaluations back to the model scores.
% This is the section that connects to \Cref{sec:roll-backward} motivation.
Firstly, for the true population, we calculate the derivatives.
\[
\dfrac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial f_{\theta}(x_i)} =
\frac{\partial \sum_{x_j \in \mathcal{B}_1} (\sigma_1(f_{\theta}(x_j) - \tau))}{\partial f_{\theta}(x_i)}
\]
\[
= \frac{\partial \left(\sum_{x_j \in \mathcal{B}_1 ; j \neq i} \frac{1}{|\mathcal{B}_1|}(\sigma_1(f_{\theta}(x_j) - \tau)) + \frac{1}{|\mathcal{B}_1|}\sigma_1(f_{\theta}(x_i) - \tau)\right)}{\partial f_{\theta}(x_i)}
\]
\[
= \frac{1}{|\mathcal{B}_1|}\sigma_1'(f_{\theta}(x_i) - \tau)
\]
Now, for the false population. As stated in the roll framework equation above (TODO LINK) we must first compute the derivation w.r.t the threshold $\tau = \hat{F}_{0}^{-1}(\alpha)$:
\[
\frac{\partial \hat{F}_1(\hat{F}_0^{-1}(\alpha))}{\partial \hat{F}_0^{-1}(\alpha)} = \frac{\partial \sum_{x_j \in \mathcal{B}_1} (\sigma_1(f_{\theta}(x_j) - \tau))}{\partial \tau}
\]
\[
= -\frac{1}{|\mathcal{B}_1|}\sum_{x_i \in \mathcal{B}_1}\sigma_1'(f_{\theta}(x_i) - \tau)
\]
At this point, we must calculate the derivative of the threshold w.r.t each score from the false population.
Unfortunately for us, this involves calculating the derivative of a calculation we computed numerically.
In order to derive this, we can utilize our earlier computation, along with the inverse derivative rule:
\[
f^{-1}'(x) = \frac{1}{f'(f^{-1}(x))}
\]
We can use this to calculate the derivative we need
\[
\frac{\partial \hat{F}_0^{-1}(\alpha)}{\partial f_\theta(\mathbf{x}_i)}
\]
\[
\frac{\partial \hat{F}_0^{-1}(\alpha ; \mathbf{X}_0)}{\partial f_\theta(\mathbf{x}_i)} = \frac{\partial \tau}{\partial f_{\theta}(x_i)}
\]
\[
= \frac{1}{\frac{\partial\hat{F}_0(\tau ; X_0)}{\partial x_i}}
\]
We must now calculate the derivative $\frac{\partial\hat{F}_0(\tau ; X_0)}{\partial x_i}$.
\[
\frac{\partial\hat{F}_0(\tau ; X_0)}{\partial x_i} = \frac{\frac{1}{|\mathcal{B}_0|}\sum_{x_j \in \mathcal{B}_0}\sigma_0(\tau - x_j)}{\partial x_i}
\]
%------------------------------------------------