<jupyter_start><jupyter_text>Full PSD of size 7x7<jupyter_code># Compute PSD factorization
# Alternatively, if you've computed a factorization previously, go down to load the factors

psd_rank = 7 # Rank parameter
np.random.seed(626) 
nIterates = 500
X = psdfactorization.compute_psd_factorization(imgmat,psd_rank,nIterates = nIterates) # We can use more iterations if needed
# Save to disk
filedir = 'learned_factors/'
fname = 'totaldampedinvscale_face_rank' + str(psd_rank) + '_' + str(nIterates) + '.pickle'
with open(filedir+fname, 'wb') as handle:
    pickle.dump(X, handle, protocol=pickle.HIGHEST_PROTOCOL)
# This is what A (uu^T) where u is a random vector looks like
# These images are basic atoms that constitute a face

# Generate random rank-one matrix
def genrandomrankone(q):
    v = np.random.randn(q)
    v *= 1.0/np.linalg.norm(v)
    V = np.outer(v,v)
    return V

r = 7
V = genrandomrankone(r)
AA_flat = np.reshape(X['A'],(361,r*r))
V_flat = np.reshape(V,(r*r,1))
Img_flat = AA_flat @ V_flat
Img_square = np.reshape(Img_flat,(HEIGHT,WIDTH))
plt.imshow(Img_square,cmap='gray')<jupyter_output><empty_output><jupyter_text>Block 2x2, 9 copies<jupyter_code># Compute PSD factorization
# Alternatively, if you've computed a factorization previously, go down to load the factors

psd_rank = [2,2,2,2,2,2,2,2,2] # Rank parameter
np.random.seed(626) 
nIterates = 500
X = psdfactorization.compute_block2psd_factorization(imgmat,psd_rank,nIterates = nIterates) # We can use more iterations if needed
# Save to disk
filedir = 'learned_factors/'
fname = 'block222222222_' + str(nIterates) + '.pickle'
with open(filedir+fname, 'wb') as handle:
    pickle.dump(X, handle, protocol=pickle.HIGHEST_PROTOCOL)
# This is what A (uu^T) where u is a random vector looks like
# These images are basic atoms that constitute a face

# Generate random rank-one matrix
def standardrankone(q,r):
    v = np.zeros(q)
    v[r,] = 1.0
    V = np.outer(v,v)
    return V

r = 18
V = standardrankone(18,0)
AA_flat = np.reshape(X['A'],(361,r*r))
V_flat = np.reshape(V,(r*r,1))
Img_flat = AA_flat @ V_flat
Img_square = np.reshape(Img_flat,(HEIGHT,WIDTH))
plt.imshow(Img_square,cmap='gray')<jupyter_output><empty_output><jupyter_text>NMF<jupyter_code># Compute PSD factorization
# Alternatively, if you've computed a factorization previously, go down to load the factors

psd_rank = [1 for i in range(27)] # Rank parameter
np.random.seed(626) 
nIterates = 500
X = psdfactorization.compute_block2psd_factorization(imgmat,psd_rank,nIterates = nIterates) # We can use more iterations if needed
# Save to disk
filedir = 'learned_factors/'
fname = 'block1x27_' + str(nIterates) + '.pickle'
with open(filedir+fname, 'wb') as handle:
    pickle.dump(X, handle, protocol=pickle.HIGHEST_PROTOCOL)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11924312745448054, 'fraction_numerical': 0.024277043912888253, 'mean_word_length': 5.624113475177305, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '41433', 'license': 'MIT', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1036, 'n_words': 263, 'path': 'ComputeBlockFactorizations.ipynb', 'repo_name': 'yssoh/PSD_MM', 'size': '2801'}