<jupyter_start><jupyter_text>Appendix C - Considerations about noise<jupyter_code>import networkx as nx
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Plot eigenvalues with increasing noise<jupyter_code># Generate adjacency matrix
n_nodes = 100
W = np.zeros((n_nodes, n_nodes))
W[0:30, 0:30] = 1
W[30:80, 30:80] = 1
W[80:, 80:] = 1
eval1 = []
eval2 = []
eval3 = []
eval4 = []

# Keep adding noise
while(np.any(W == 0)):
    # Compute the laplacian
    D = np.diag(np.sum(W, axis=0))
    laplacian = D - W

    # Compute eigenvalues and eigenvectors
    evals, evects = np.linalg.eigh(laplacian)
    eval1.append(evals[0])
    eval2.append(evals[1])
    eval3.append(evals[2])
    eval4.append(evals[3])
    
    # Add randomly one edge
    idxs_y, idxs_x = np.nonzero(W == 0)
    idx = np.random.randint(len(idxs_y))
    
    # Add edge in the picked position
    W[idxs_y[idx], idxs_x[idx]] = 1
    W[idxs_x[idx], idxs_y[idx]] = 1
plt.plot(eval1, label='Eigenvalue 1')
plt.plot(eval2, label='Eigenvalue 2')
plt.plot(eval3, label='Eigenvalue 3')
plt.plot(eval4, label='Eigenvalue 4')
plt.xlabel('Edges added')
plt.ylabel('Intensity')
plt.legend()
plt.savefig(f'../figures/adding-noise.eps')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15179968701095461, 'fraction_numerical': 0.03834115805946792, 'mean_word_length': 4.373949579831932, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '355089', 'license': 'CC0-1.0', 'n_tokens_mistral': 565, 'n_tokens_neox': 510, 'n_words': 106, 'path': 'appendices/section-4.ipynb', 'repo_name': 'Davide95/practical_spectral_clustering', 'size': '1278'}