Kuiper's test of uniform distribution. Parameters ---------- data : ndarray, shape (n_sources,) | (n_sources, n_times) Empirical distribution. dtype : str | obj The data type to be used. Returns ------- ks : ndarray Kuiper's statistic. pk
(data, dtype=np.float64)
| 80 | |
| 81 | |
| 82 | def kuiper(data, dtype=np.float64): # noqa: D401 |
| 83 | """Kuiper's test of uniform distribution. |
| 84 | |
| 85 | Parameters |
| 86 | ---------- |
| 87 | data : ndarray, shape (n_sources,) | (n_sources, n_times) |
| 88 | Empirical distribution. |
| 89 | dtype : str | obj |
| 90 | The data type to be used. |
| 91 | |
| 92 | Returns |
| 93 | ------- |
| 94 | ks : ndarray |
| 95 | Kuiper's statistic. |
| 96 | pk : ndarray |
| 97 | Normalized probability of Kuiper's statistic [0, 1]. |
| 98 | """ |
| 99 | # if data not numpy array, implicitly convert and make to use copied data |
| 100 | # ! sort data array along first axis ! |
| 101 | data = np.sort(data, axis=0).astype(dtype) |
| 102 | shape = data.shape |
| 103 | n_dim = len(shape) |
| 104 | n_trials = shape[0] |
| 105 | |
| 106 | # create uniform cdf |
| 107 | j1 = (np.arange(n_trials, dtype=dtype) + 1.0) / float(n_trials) |
| 108 | j2 = np.arange(n_trials, dtype=dtype) / float(n_trials) |
| 109 | if n_dim > 1: # single phase vector (n_trials) |
| 110 | j1 = j1[:, np.newaxis] |
| 111 | j2 = j2[:, np.newaxis] |
| 112 | d1 = (j1 - data).max(axis=0) |
| 113 | d2 = (data - j2).max(axis=0) |
| 114 | n_eff = n_trials |
| 115 | |
| 116 | d = d1 + d2 # Kuiper's statistic [n_time_slices] |
| 117 | |
| 118 | return d, _prob_kuiper(d, n_eff, dtype=dtype) |
| 119 | |
| 120 | |
| 121 | def _prob_kuiper(d, n_eff, dtype="f8"): |