Compute the bidirectional idealized arc curve (IAC). This is based on a beta distribution that is scaled with a width that is identical to the length of the matrix profile index. The height of the idealized parabolic curve is assumed to be exactly half the width. If `bidirectio
(
width, bidirectional=True, n_iter=1000, n_samples=1000, seed=0
)
| 48 | |
| 49 | |
| 50 | def _iac( |
| 51 | width, bidirectional=True, n_iter=1000, n_samples=1000, seed=0 |
| 52 | ): # pragma: no cover |
| 53 | """ |
| 54 | Compute the bidirectional idealized arc curve (IAC). This is based |
| 55 | on a beta distribution that is scaled with a width that is identical |
| 56 | to the length of the matrix profile index. The height of the idealized |
| 57 | parabolic curve is assumed to be exactly half the width. |
| 58 | |
| 59 | If `bidirectional=False` then the 1-dimensional IAC is computed instead. |
| 60 | |
| 61 | Parameters |
| 62 | ---------- |
| 63 | width : int |
| 64 | The width of the bidirectional idealized arc curve. This is equal |
| 65 | to the length of the matrix profile index. |
| 66 | |
| 67 | bidirectional : bool, default True |
| 68 | Flag for computing a bidirectional (`True`) or 1-dimensional (`False`) |
| 69 | idealized arc curve |
| 70 | |
| 71 | n_iter : int, default 1000 |
| 72 | Number of iterations to average over when determining the parameters for |
| 73 | beta distribution |
| 74 | |
| 75 | n_samples : int, default 1000 |
| 76 | Number of distribution samples to draw during each iteration |
| 77 | |
| 78 | seed : int, default 0 |
| 79 | NumPy random seed used in sampling the beta distribution. Set this to your |
| 80 | desired value for reproducibility purposes. The default value is set to `0`. |
| 81 | |
| 82 | Returns |
| 83 | ------- |
| 84 | IAC : numpy.ndarray |
| 85 | Idealized arc curve (IAC) |
| 86 | """ |
| 87 | np.random.seed(seed) |
| 88 | |
| 89 | I = np.random.randint(0, width, size=width, dtype=np.int64) |
| 90 | if bidirectional is False: # Idealized 1-dimensional matrix profile index |
| 91 | I[:-1] = width |
| 92 | for i in range(width - 1): |
| 93 | I[i] = np.random.randint(i + 1, width, dtype=np.int64) |
| 94 | |
| 95 | target_AC = _nnmark(I) |
| 96 | |
| 97 | params = np.empty((n_iter, 2), dtype=np.float64) |
| 98 | for i in range(n_iter): |
| 99 | hist_dist = scipy.stats.rv_histogram( |
| 100 | (target_AC, np.append(np.arange(width), width)) |
| 101 | ) |
| 102 | data = hist_dist.rvs(size=n_samples) |
| 103 | a, b, c, d = scipy.stats.beta.fit(data, floc=0, fscale=width) |
| 104 | |
| 105 | params[i, 0] = a |
| 106 | params[i, 1] = b |
| 107 |