<jupyter_start><jupyter_text>Lab 06 : Laplacian Eigenmaps - demo<jupyter_code># Load libraries

# Math
import numpy as np

# Import data
import scipy.io

# Visualization 
%matplotlib notebook 
import matplotlib.pyplot as plt
plt.rcParams.update({'figure.max_open_warning': 0})
import time

# Import functions in lib folder
import sys
sys.path.insert(0, 'lib/')

# Import helper functions
%load_ext autoreload
%autoreload 2
from lib.utils import compute_pca
from lib.utils import construct_knn_graph
from lib.utils import nldr_visualization
from lib.utils import construct_kernel

# Import
import scipy.sparse.linalg
import time
import scipy.ndimage

# 3D visualization
import pylab
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot

# Remove warnings
import warnings
warnings.filterwarnings("ignore")
# Run LDR = Standard PCA
mat = scipy.io.loadmat('../../data/graph/MNIST_data.mat')
X = mat['X']
n = X.shape[0]
d = X.shape[1]
Cgt = mat['C'].squeeze()
print(n,d)

nb_pca = 3
[PC,PD,EnPD] = compute_pca(X,nb_pca)
Xldr = PC[:,0]
Yldr = PC[:,1]
Zldr = PC[:,2]
# 3D Plot
fig = pylab.figure(2)
ax = Axes3D(fig)
size_vertex_plot = 1
ax.scatter(Xldr, Yldr, Zldr, s=size_vertex_plot*np.ones(n), c=Cgt)
ax.view_init(24,-105)
ax.axis('off')
plt.title('3D Visualization with PCA') 
pyplot.show()
mat = scipy.io.loadmat('../../data/graph/MNIST.mat')
W = mat['W']
n = W.shape[0]
Cgt = mat['C'].squeeze()
print(n)

# Run NLDR = Laplacian Eigenmaps
Xnldr_lapeigmap,Ynldr_lapeigmap,Znldr_lapeigmap = nldr_visualization(W)
# 3D Plot
fig = pylab.figure(1)
ax = Axes3D(fig)
size_vertex_plot = 1
ax.scatter(Xnldr_lapeigmap, Ynldr_lapeigmap, Znldr_lapeigmap, s=size_vertex_plot*np.ones(n), c=Cgt)
ax.view_init(24,-105)
ax.axis('off')
plt.title('3D Visualization with LapEigMaps') 
pyplot.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13439385628085573, 'fraction_numerical': 0.019199122325836534, 'mean_word_length': 5.632727272727273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '40485', 'license': 'MIT', 'n_tokens_mistral': 793, 'n_tokens_neox': 757, 'n_words': 163, 'path': 'codes/labs_lecture17/lab06_lap_eigenmaps/lap_eigenmaps_demo.ipynb', 'repo_name': 'sanjaysaha1311/Deep_Learning_CS7454_2018_NTU', 'size': '1823'}