<jupyter_start><jupyter_text>Execute this code by loading a .npy square adjacency matrix. Make sure you have the sCSC.py file in the same directory.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
% matplotlib inline

# The following was written using SciPy Version 0.19.1
import scipy.linalg
from scipy.cluster.hierarchy import average, linkage, fcluster
from scipy.spatial.distance import pdist
from sCSC import *
# Load adjacency matrix
adjacency_matrix = np.load('../data/protein_g_adjmat.npy')
assert len(adjacency_matrix.shape) == 2
size = adjacency_matrix.shape[0]
assert size == adjacency_matrix.shape[1]
print('Adjacency matrix is {} x {}.'.format(size,size))

# Select number of eigenvectors to include in dendrogram analysis
numeigvecs = 7
# Obtain eigenvectors for clustering and graph Laplacian
evec, L = get_eigenvectors_for_dendrogram(adjacency_matrix, numeigvecs)

# Get binary codes for each orthogonal process
binary = get_binary_codes(evec, numeigvecs)

# Initialize dendrogram matrices
groupdist, plotcoordsx, plotcoordsy, index_dict = initialize_dendrogram_matrices(numeigvecs)

# Loop through eigenvectors, from largest to last one included in analysis
for split in np.arange(numeigvecs):
    # Output current dendrogram level
    print("Split %i of %i" % (split+1, numeigvecs))
    
    # Initialize level of dendrogram
    row = 0
    
    # Loop through binary codes
    for combos in np.arange(0, 2**(split+1), 2):
        g1label, g2label, Z1count, Z2count, Z1, Z2, index_dict = get_subgroup_similarity(
                                                evec, L, binary, combos, split, index_dict)
        
        # Record dissimilarity metric for group 1
        groupdist[row, split] = Z1
    
        # Record dissimilarity metric for group 2
        groupdist[row+1, split] = Z2
        
        # Plot this level of the dendrogram
        plotcoordsx, plotcoordsy = plot_next_dendrogram_split(
                                   plotcoordsx, plotcoordsy, row, split, adjacency_matrix,
                                   g1label, g2label, Z1count, Z2count, Z1, Z2)
    
        # Advance dendrogram level counter
        row = row + 2

# Optionally add plot specifications
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
plt.tight_layout()

# Optionally save figure
#plt.savefig('dendrogram.pdf')

# Optionally export sCSC Dendrogram distance matrix
# np.save('groupdist.npy', groupdist)

# Optionally save dictionary of member indices
# import pickle
# with open('index_dict.pkl', 'wb') as f:
#     pickle.dump(index_dict, f)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07955418908531899, 'fraction_numerical': 0.013835511145272867, 'mean_word_length': 3.4495726495726498, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '334128', 'license': 'MIT', 'n_tokens_mistral': 871, 'n_tokens_neox': 814, 'n_words': 245, 'path': 'notebooks/sCSC_dendrogram_creation.ipynb', 'repo_name': 'Mopolino8/sCSC', 'size': '2602'}