pyhctsa.operations.entropy.randomize¶
-
pyhctsa.operations.entropy.randomize(y, randomize_how=
'statdist', random_seed=None, num_reps=20)¶ How properties of the series change as it is progressively randomized.
Randomizes a copy of the input (z-scored) series one point at a time, according to a randomization procedure, repeated
2Ntimes for a series of lengthN, and compares statistics of the randomized copy with the original at 21 checkpoints: at the start and after everyN/10steps. The randomization is repeatednum_repstimes from the same series and the statistics at each checkpoint are averaged over the repeats (a single randomization gives a noisy trajectory, and the fitted parameters would mostly reflect that noise). Port of hctsa’sEN_Randomize.The random indices come from the portable generator
bf_random()(two uniform draws per step, as indices uniform on 1..N), so the result is reproducible and, for the same seed, follows the same randomization as hctsa.- Parameters:¶
- y : array-like¶
The input (z-scored) time series.
- randomize_how : {'statdist', 'dyndist', 'permute'}, optional¶
What one step of randomization does:
'statdist': overwrites a random element of the series with a randomly chosen element of the original series,'dyndist': overwrites a random element of the series with another random element of the current, partially randomized, series,'permute': swaps two randomly chosen elements of the series, so that the distribution of values never changes and only the temporal properties do.
Default is
'statdist'.- random_seed : int or {'default', 'none'}, optional¶
The seed of the random choices, as hctsa’s
BF_RandomSeed: a number;'default'(or None) is 0;'none'draws a seed from NumPy’s global stream (the run is then not reproducible). Default is None.- num_reps : int, optional¶
The number of independent randomizations whose statistics are averaged. Default is 20.
- Returns:¶
For each of ten statistics measured at each checkpoint, six or seven fields describing its trajectory over the 21 checkpoints. The statistics are:
’xcn1’, ‘xc1’: the cross-correlation of the original and randomized series at lags -1 and +1,
’d1’: the distance between the original and randomized series,
norm(y - y_rand) / N,’ac1’, ‘ac2’, ‘ac3’, ‘ac4’: the autocorrelation of the randomized series at lags 1 to 4,
’permen3_1’: the normalized permutation entropy of the randomized series, PermEn(3, 1),
’statav5’: StatAv with 5 segments (the standard deviation of the segment means),
’swss5_1’: the standard deviation across 5 non-overlapping windows of the local standard deviation, relative to the full-series standard deviation.
The fields are named by joining a statistic’s name to a suffix. Fits of
a * exp(b * k)(kthe checkpoint number 1..21) for ‘xcn1’, ‘xc1’, ‘ac1’, ‘ac2’, ‘ac3’ and ‘ac4’ have the suffixes ‘fexpa’, ‘fexpb’ (the parameters), ‘fexpr2’ (R^2), ‘fexprmse’ (the standard error of the fit), ‘diff’ and ‘hp’. Fits ofa * exp(b * k) + cfor ‘d1’, ‘permen3_1’, ‘statav5’ and ‘swss5_1’ have the same suffixes plus ‘fexpc’ (the offsetc). In all cases ‘diff’ is the absolute change|s_end - s_start|of the statistic between the first and last checkpoints and ‘hp’ is the number of the first checkpoint at which the statistic passes halfway between its start and end values (NaN if it never does).- Return type:¶
dict
Notes
‘diff’ is an absolute change, not a change relative to the starting value, because the starting value (e.g., the autocorrelation of the original series at lag 2) can be near 0, where a relative change is unstable. The exponential fits are trust-region nonlinear least squares from fixed starting points (
scipy.optimize.least_squares()); a fit that fails gives NaN.