|
7 | 7 | import numpy as np |
8 | 8 | import scipy.stats |
9 | 9 |
|
10 | | -from . import config, core |
| 10 | +from . import config, core, rng |
11 | 11 |
|
12 | 12 |
|
13 | 13 | def _nnmark(I): |
@@ -84,34 +84,36 @@ def _iac( |
84 | 84 | IAC : numpy.ndarray |
85 | 85 | Idealized arc curve (IAC) |
86 | 86 | """ |
87 | | - np.random.seed(seed) |
| 87 | + with rng.fix_seed(seed): |
| 88 | + I = rng.RNG.randint(0, width, size=width, dtype=np.int64) |
| 89 | + if bidirectional is False: # Idealized 1-dimensional matrix profile index |
| 90 | + I[:-1] = width |
| 91 | + for i in range(width - 1): |
| 92 | + I[i] = rng.RNG.randint(i + 1, width, dtype=np.int64) |
| 93 | + |
| 94 | + target_AC = _nnmark(I) |
| 95 | + |
| 96 | + params = np.empty((n_iter, 2), dtype=np.float64) |
| 97 | + for i in range(n_iter): |
| 98 | + hist_dist = scipy.stats.rv_histogram( |
| 99 | + (target_AC, np.append(np.arange(width), width)) |
| 100 | + ) |
| 101 | + hist_dist.random_state = rng.RNG |
| 102 | + data = hist_dist.rvs(size=n_samples) |
| 103 | + a, b, c, d = scipy.stats.beta.fit(data, floc=0, fscale=width) |
88 | 104 |
|
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) |
| 105 | + params[i, 0] = a |
| 106 | + params[i, 1] = b |
94 | 107 |
|
95 | | - target_AC = _nnmark(I) |
| 108 | + a_mean = np.round(np.mean(params[:, 0]), 2) |
| 109 | + b_mean = np.round(np.mean(params[:, 1]), 2) |
96 | 110 |
|
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)) |
| 111 | + IAC = scipy.stats.beta.pdf(np.arange(width), a_mean, b_mean, loc=0, scale=width) |
| 112 | + slope, _, _, _ = np.linalg.lstsq( |
| 113 | + np.expand_dims(IAC, axis=1), target_AC, rcond=None |
101 | 114 | ) |
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 | | - |
108 | | - a_mean = np.round(np.mean(params[:, 0]), 2) |
109 | | - b_mean = np.round(np.mean(params[:, 1]), 2) |
110 | | - |
111 | | - IAC = scipy.stats.beta.pdf(np.arange(width), a_mean, b_mean, loc=0, scale=width) |
112 | | - slope, _, _, _ = np.linalg.lstsq(np.expand_dims(IAC, axis=1), target_AC, rcond=None) |
113 | 115 |
|
114 | | - IAC *= slope |
| 116 | + IAC *= slope |
115 | 117 |
|
116 | 118 | return IAC |
117 | 119 |
|
|
0 commit comments