<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Using NMF to Factorize Face Images
In this notebook, we try to reproduce the result in Lee & Seung (1999) using the standard NMF algorithm.
Step1:  The dataset we used here is the Face Data, the same as the one used in Lee & Seung (1999). The function CBCL_faces.get_CBCL_faces() will download and load data into a 2D matrix, in which each row is all pixel from one image. All 2429 face images in training set have been read by PIL and converted into Numpy Array. Here are some examples
Step2:  In this example we didn't scale the greyscale intensites to mean and std 0.25, as Lee & Seung did in their paper. Here we only normalized them to [0,1].
After 12000 iterations, we get
<ASSISTANT_TASK:>
Python Code:
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
import sys
sys.path.append('/home/Repos/pyMF3/')
import pymf3
from pymf3.datasets import CBCL_faces
from matplotlib import rcParams
rcParams['font.family'] = 'DejaVu Sans'
faces = CBCL_faces.get_CBCL_faces(scale_images=True)
Explanation: Using NMF to Factorize Face Images
In this notebook, we try to reproduce the result in Lee & Seung (1999) using the standard NMF algorithm.
End of explanation
rand_imgs = np.random.randint(0, faces.shape[0], size=7)
fig, ax = plt.subplots(1, len(rand_imgs), figsize=(14, 2))
for i, img in enumerate(rand_imgs):
    ax[i].imshow(faces[img].reshape(19,19))
    ax[i].axes.get_xaxis().set_visible(False)
    ax[i].axes.get_yaxis().set_visible(False)
Explanation: The dataset we used here is the Face Data, the same as the one used in Lee & Seung (1999). The function CBCL_faces.get_CBCL_faces() will download and load data into a 2D matrix, in which each row is all pixel from one image. All 2429 face images in training set have been read by PIL and converted into Numpy Array. Here are some examples:
End of explanation
nmf = pymf3.NMF(data=faces, num_bases=49)
nmf.factorize(niter=12000, show_progress=False)
nmf.plot_modules(module_ndims=(19,19), num_per_row=7)
nmf.plot_cost()
Explanation: In this example we didn't scale the greyscale intensites to mean and std 0.25, as Lee & Seung did in their paper. Here we only normalized them to [0,1].
After 12000 iterations, we get:
End of explanation
<END_TASK>