Created
January 2, 2021 07:19
-
-
Save suhaskv/d8b1e80d0f2a9a1ae79534c9c7526a4f to your computer and use it in GitHub Desktop.
VSB Power Line Blog - SVD Entropy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _embed(x, order=3, delay=1): | |
N = len(x) | |
# In our case, N-(order-1)*delay = 800000 - (3-1)*1 = 799998 | |
# Y.shape = 3x799998 | |
Y = np.zeros((order, N - (order - 1) * delay)) | |
for i in range(order): | |
# Y[0] = x[0:799998], Y[1] = x[1:799999], Y[2] = x[3:800000] | |
Y[i] = x[(i * delay) : (i * delay) + Y.shape[1]].T | |
# Y.T[0] = [x[0],x[1],x[2]], Y.T[1] = [x[1],x[2],x[3]], ... , Y.T[799998] = [x[799998],x[799999],x[800000]] | |
return Y.T | |
def svd_entropy(x, order=3, delay=1, normalize=False): | |
x = np.array(x) | |
mat = _embed(x, order=order, delay=delay) | |
# W is an array containing singular values obtained after computation of SVD | |
W = np.linalg.svd(mat, compute_uv=False) | |
# Normalize the singular values | |
W /= sum(W) | |
svd_e = -np.multiply(W, np.log2(W)).sum() | |
if normalize: | |
svd_e /= np.log2(order) | |
return svd_e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment