Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
np.place(sum_mtm, sum_mtm == 0, 1)
X_mtm /= sum_mtm[:, :, None]
X_mtf = _markov_transition_field(
X_binned, X_mtm, n_samples, n_timestamps, self.n_bins
)
window_size, remainder = divmod(n_timestamps, image_size)
if remainder == 0:
X_amtf = np.reshape(
X_mtf, (n_samples, image_size, window_size,
image_size, window_size)
).mean(axis=(2, 4))
else:
window_size += 1
start, end, _ = segmentation(
n_timestamps, window_size, self.overlapping, image_size
)
X_amtf = _aggregated_markov_transition_field(
X_mtf, n_samples, image_size, start, end
)
if self.flatten:
return X_amtf.reshape(n_samples, -1)
return X_amtf
----------
X : array-like, shape = (n_samples, n_timestamps)
Returns
-------
X_new : array, shape = (n_samples, n_timestamps_new)
"""
X = check_array(X)
n_samples, n_timestamps = X.shape
window_size, output_size = self._check_params(n_timestamps)
if window_size == 1:
return X
else:
start, end, n_timestamps_new = segmentation(
n_timestamps, window_size, self.overlapping, output_size
)
X_paa = _paa(X, n_samples, n_timestamps,
start, end, n_timestamps_new)
return X_paa
Transformed data.
"""
# Check input data
X = check_array(X)
# Shape parameters
n_samples, n_features = X.shape
# Check parameters and compute window_size if output_size is given
window_size = self._check_params(n_samples, n_features)
if window_size == 1:
return X
else:
start, end, size = segmentation(n_features, window_size,
self.overlapping, self.output_size)
return np.apply_along_axis(self._paa, 1, X, start, end, size)
# Compute Markov Transition Field
MTF = np.zeros((ts_size, ts_size))
for i in range(non_zero_rows.size):
for j in range(non_zero_rows.size):
MTF[np.meshgrid(list_values[i], list_values[j])] = MTM[i, j]
# Compute Aggregated Markov Transition Field
if remainder == 0:
return np.reshape(MTF,
(image_size, window_size,
image_size, window_size)
).mean(axis=(1, 3))
else:
window_size += 1
start, end, _ = segmentation(ts_size, window_size, overlapping)
AMTF = np.zeros((image_size, image_size))
for i in range(image_size):
for j in range(image_size):
AMTF[i, j] = MTF[start[i]:end[i], start[j]:end[j]].mean()
return AMTF