Learn R Programming

softwareRisk (version 0.1.0)

risk_eval_fun: Evaluate node risk under sampled parameters

Description

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.

Usage

risk_eval_fun(
  cyclo_sc,
  indeg_sc,
  btw_sc,
  sample_matrix,
  risk_form = c("additive", "power_mean"),
  eps = 1e-12
)

Value

A numeric vector of risk values, one per row of sample_matrix.

Arguments

cyclo_sc, indeg_sc, btw_sc

Numeric scalars. Scaled node metrics (typically in \([0,1]\)) for cyclomatic complexity, in-degree, and betweenness.

sample_matrix

Numeric matrix or data.frame containing sampled parameters. Must include alpha, beta, gamma. If risk_form = "power_mean", must also include p.

risk_form

Character. One of "additive" or "power_mean".

eps

Numeric. Small positive constant \(\epsilon\) used to avoid \(\log(0)\) in the \(p \to 0\) case. Default 1e-12.

Details

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)\,.$$