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
import matplotlib.pyplot as plt | |
import numpy as np | |
import matplotlib.collections as mcoll | |
def matrix_2d_effect(transfo_matrix, vectorsCol=["#FFD800", "#00CD79"]): | |
""" | |
Modify the unit circle and basis vector by applying a matrix. | |
Visualize the effect of the matrix in 2D. |
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
# choose figure size | |
plt.figure(figsize=(6, 6)) | |
# Assure that ticks are displayed with a step equal to 1 | |
ax = plt.gca() | |
ax.xaxis.set_major_locator(ticker.MultipleLocator(1)) | |
ax.yaxis.set_major_locator(ticker.MultipleLocator(1)) | |
# draw axes | |
plt.axhline(0, c='#A9A9A9', zorder=0) |
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
plotImage(X[12, :]) | |
plotImage(X_ZCA_rescaled[12, :]) |
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
X_ZCA_rescaled = (X_ZCA - X_ZCA.min()) / (X_ZCA.max() - X_ZCA.min()) | |
print 'min:', X_ZCA_rescaled.min() | |
print 'max:', X_ZCA_rescaled.max() |
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
epsilon = 0.1 | |
X_ZCA = U.dot(np.diag(1.0/np.sqrt(S + epsilon))).dot(U.T).dot(X_norm) | |
plotImage(X[12, :]) | |
plotImage(X_ZCA[12, :]) |
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
print np.diag(S) | |
print '\nshape:', np.diag(S).shape |
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
print U.shape, S.shape |
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
U,S,V = np.linalg.svd(cov) |
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
cov = np.cov(X_norm, rowvar=True) |
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
X_norm.mean(axis=0) |
NewerOlder