Internal helper used by risk_form_variance_share_fun() to evaluate node risk
for a single node (with scaled inputs) across a sampled parameter matrix.
risk_eval_fun(
cyclo_sc,
indeg_sc,
btw_sc,
sample_matrix,
risk_form = c("additive", "power_mean"),
eps = 1e-12
)A numeric vector of risk values, one per row of sample_matrix.
Numeric scalars. Scaled node metrics (typically in \([0,1]\)) for cyclomatic complexity, in-degree, and betweenness.
Numeric matrix or data.frame containing sampled parameters.
Must include alpha, beta, gamma. If risk_form = "power_mean", must also
include p.
Character. One of "additive" or "power_mean".
Numeric. Small positive constant \(\epsilon\) used to avoid
\(\log(0)\) in the \(p \to 0\) case. Default 1e-12.
For risk_form = "additive", risk is computed as a weighted sum:
$$r = \alpha\,\tilde{C} + \beta\,\tilde{d}^{\mathrm{in}} + \gamma\,\tilde{b}\,,$$
where \(\tilde{C}\), \(\tilde{d}^{\mathrm{in}}\), and \(\tilde{b}\) are scaled cyclomatic complexity, in-degree, and betweenness, respectively.
For risk_form = "power_mean", risk is computed as a weighted power mean with
exponent \(p \in [-1, 2]\):
$$r = \left(\alpha\,\tilde{C}^{p} + \beta\,(\tilde{d}^{\mathrm{in}})^{p} + \gamma\,\tilde{b}^{p}\right)^{1/p}\,.$$
In the limit \(p \to 0\), the implementation uses the weighted geometric mean with a small constant \(\epsilon\) to ensure numerical stability:
$$r = \exp\left(\alpha\log(\max(\tilde{C},\epsilon)) + \beta\log(\max(\tilde{d}^{\mathrm{in}},\epsilon)) + \gamma\log(\max(\tilde{b},\epsilon))\right)\,.$$