def analyze_signatures()

in bayesmark/signatures.py [0:0]


def analyze_signatures(signatures):
    """Analyze function signatures from the experiment.

    Parameters
    ----------
    signatures : dict(str, list(list(float)))
        The signatures should all be the same length, so it should be 2D array
        like.

    Returns
    -------
    sig_errs : :class:`pandas:pandas.DataFrame`
        rows are test cases, columns are test points.
    signatures_median : dict(str, list(float))
        Median signature across all repetition per test case.
    """
    sig_errs = {}
    signatures_median = {}
    for test_case, signature_y in signatures.items():
        assert len(signature_y) > 0, "signature with no cases found"
        assert np.all(np.isfinite(signature_y)), "non-finite values found in signature for function"

        minval = np.min(signature_y, axis=0)
        maxval = np.max(signature_y, axis=0)

        if not np.allclose(minval, maxval):
            # Arguably, the util should not raise the warning, and these should
            # be raised on the outside, but let's do this for simplicity.
            warnings.warn(
                "Signature diverged on %s betwen %s and %s" % (test_case, str(minval), str(maxval)), RuntimeWarning
            )
        sig_errs[test_case] = maxval - minval
        # ensure serializable using tolist
        signatures_median[test_case] = np.median(signature_y, axis=0).tolist()

    # Convert to pandas so easy to append margins with max, better for disp.
    # If we let the user convert to pandas then we don't need dep on pandas.
    sig_errs = pd.DataFrame(sig_errs).T
    sig_errs.loc["max", :] = sig_errs.max(axis=0)
    sig_errs.loc[:, "max"] = sig_errs.max(axis=1)

    return sig_errs, signatures_median