From 8740b35f053251c1b171a9647d5b50e96d73c6e0 Mon Sep 17 00:00:00 2001 From: fjosw Date: Mon, 10 Jan 2022 14:19:33 +0000 Subject: [PATCH] Documentation updated --- docs/pyerrors/fits.html | 110 +++++++++++++++++++++++++++++++++++++++- docs/search.js | 2 +- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/docs/pyerrors/fits.html b/docs/pyerrors/fits.html index a0d51384..af7c33b8 100644 --- a/docs/pyerrors/fits.html +++ b/docs/pyerrors/fits.html @@ -89,6 +89,9 @@
  • error_band
  • +
  • + ks_test +
  • @@ -108,7 +111,8 @@
    View Source -
    from collections.abc import Sequence
    +            
    import gc
    +from collections.abc import Sequence
     import warnings
     import numpy as np
     import autograd.numpy as anp
    @@ -855,6 +859,46 @@
         err = np.array(err)
     
         return err
    +
    +
    +def ks_test(objects=None):
    +    """Performs a Kolmogorov–Smirnov test for the p-values of all fit object.
    +
    +    Parameters
    +    ----------
    +    objects : list
    +        List of fit results to include in the analysis (optional).
    +    """
    +
    +    if objects is None:
    +        obs_list = []
    +        for obj in gc.get_objects():
    +            if isinstance(obj, Fit_result):
    +                obs_list.append(obj)
    +    else:
    +        obs_list = objects
    +
    +    p_values = [o.p_value for o in obs_list]
    +
    +    bins = len(p_values)
    +    x = np.arange(0, 1.001, 0.001)
    +    plt.plot(x, x, 'k', zorder=1)
    +    plt.xlim(0, 1)
    +    plt.ylim(0, 1)
    +    plt.xlabel('p-value')
    +    plt.ylabel('Cumulative probability')
    +    plt.title(str(bins) + ' p-values')
    +
    +    n = np.arange(1, bins + 1) / np.float64(bins)
    +    Xs = np.sort(p_values)
    +    plt.step(Xs, n)
    +    diffs = n - Xs
    +    loc_max_diff = np.argmax(np.abs(diffs))
    +    loc = Xs[loc_max_diff]
    +    plt.annotate('', xy=(loc, loc), xytext=(loc, loc + diffs[loc_max_diff]), arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0))
    +    plt.draw()
    +
    +    print(scipy.stats.kstest(p_values, 'uniform'))
     
    @@ -1620,6 +1664,70 @@ check if the residuals of the fit are gaussian distributed.

    + +
    +
    #   + + + def + ks_test(objects=None): +
    + +
    + View Source +
    def ks_test(objects=None):
    +    """Performs a Kolmogorov–Smirnov test for the p-values of all fit object.
    +
    +    Parameters
    +    ----------
    +    objects : list
    +        List of fit results to include in the analysis (optional).
    +    """
    +
    +    if objects is None:
    +        obs_list = []
    +        for obj in gc.get_objects():
    +            if isinstance(obj, Fit_result):
    +                obs_list.append(obj)
    +    else:
    +        obs_list = objects
    +
    +    p_values = [o.p_value for o in obs_list]
    +
    +    bins = len(p_values)
    +    x = np.arange(0, 1.001, 0.001)
    +    plt.plot(x, x, 'k', zorder=1)
    +    plt.xlim(0, 1)
    +    plt.ylim(0, 1)
    +    plt.xlabel('p-value')
    +    plt.ylabel('Cumulative probability')
    +    plt.title(str(bins) + ' p-values')
    +
    +    n = np.arange(1, bins + 1) / np.float64(bins)
    +    Xs = np.sort(p_values)
    +    plt.step(Xs, n)
    +    diffs = n - Xs
    +    loc_max_diff = np.argmax(np.abs(diffs))
    +    loc = Xs[loc_max_diff]
    +    plt.annotate('', xy=(loc, loc), xytext=(loc, loc + diffs[loc_max_diff]), arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0))
    +    plt.draw()
    +
    +    print(scipy.stats.kstest(p_values, 'uniform'))
    +
    + +
    + +

    Performs a Kolmogorov–Smirnov test for the p-values of all fit object.

    + +
    Parameters
    + +
      +
    • objects (list): +List of fit results to include in the analysis (optional).
    • +
    +
    + +