Newer
Older
filename = importlib_resources.files("dtuimldmtools").joinpath("data/zipdata.mat")
# Digits to include in analysis (to include all, n = range(10) )
n = [1]
# Number of digits to generate from normal distributions
ngen = 10
# Load Matlab data file to python dict structure
# and extract variables of interest
traindata = loadmat(filename)["traindata"]
X = traindata[:, 1:]
y = traindata[:, 0]
N, M = np.shape(X) # or X.shape
C = len(n)
# Remove digits that are not to be inspected
class_mask = np.zeros(N).astype(bool)
for v in n:
mu = X.mean(axis=0)
s = X.std(ddof=1, axis=0)
S = np.cov(X, rowvar=0, ddof=1)
# Generate 10 samples from 1-D normal distribution
plt.imshow(I, cmap=plt.cm.gray_r)
plt.xticks([])
plt.yticks([])
# Generate 10 samples from multivariate normal distribution
Xmvgen = np.random.multivariate_normal(mu, S, ngen)
# Note if you are investigating a single class, then you may get:
# """RuntimeWarning: covariance is not positive-semidefinite."""
# Which in general is troublesome, but here is due to numerical imprecission
# Plot images
plt.imshow(I, cmap=plt.cm.gray_r)
plt.xticks([])
plt.yticks([])