Skip to content

Fraction Scan

puma.fraction_scan.get_fx_values #

Source code in puma/fraction_scan.py
 6
 7
 8
 9
10
def get_fx_values(resolution=100):
    return np.concatenate((
        np.logspace(-3, -1, resolution // 2),
        np.linspace(0.1, 1.0, resolution // 2),
    ))

puma.fraction_scan.get_efficiency #

Source code in puma/fraction_scan.py
13
14
def get_efficiency(scores, fx):
    return np.sum(scores > fx) / len(scores)

puma.fraction_scan.get_optimal_fraction_value #

After calculating a fraction scan, find the optimal fraction value.

Parameters:

Name Type Description Default
fraction_scan numpy.ndarray

2D array of efficiency (or rejection) scores for each fraction value.

required
fraction_space numpy.ndarray

1D array of fraction values.

required
rej bool

If True, find the maximum rejection values else find the minimum efficiency values, by default False.

False
Source code in puma/fraction_scan.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def get_optimal_fraction_value(
    fraction_scan: np.ndarray,
    fraction_space: np.ndarray,
    rej: bool = False,
):
    """After calculating a fraction scan, find the optimal fraction value.


    Parameters
    ----------
    fraction_scan : np.ndarray
        2D array of efficiency (or rejection) scores for each fraction value.
    fraction_space : np.ndarray
        1D array of fraction values.
    rej : bool, optional
        If True, find the maximum rejection values else find the minimum efficiency values, by
        default False.
    """
    # normalise x- and y-axes
    xs, ys = fraction_scan[:, 0], fraction_scan[:, 1]
    xs = xs / max(xs)
    ys = ys / max(ys)

    # if rej=True get maximum distance to origin
    opt_idx = np.argmax(xs**2 + ys**2) if rej else np.argmin(xs**2 + ys**2)

    return opt_idx, fraction_space[opt_idx]