def test_?_w(self):
""" ?_w = [A][A^T]. See p. 533.
DESCRIPTION: Since A is a free parameter, t will not necessarily recover
the original A. ?_w is what really describes the covariance
between cluster means (see p. 533), so that is what you want
to test - it is 'closer' to the data.
"""
n_experiments = int(np.log10(1000000) / 2)
n_list = [100 ** x for x in range(1, n_experiments + 1)]
n_list = np.array(n_list).astype(float)
n_dims = self.n_dims
n_classes = 30 #self.n_classes
?_w_L1_errors = []
for n in n_list:
A, ?, model = self.experiment(int(n), n_dims, n_classes)
?_w = np.matmul(A, A.T)
?_w_model = np.matmul(model.A, model.A.T)
L1_error = np.abs(?_w - ?_w_model).mean()
abs_? = (np.abs(?_w).mean() + np.abs(?_w_model).mean()) * .5
percent_error = L1_error / abs_? * 100
print('Testing ?_w with {} samples: {} percent error'.format(n,
percent_error))
?_w_L1_errors.append(percent_error)
Y = ?_w_L1_errors
X = [x for x in range(len(?_w_L1_errors))]
slope_of_error_vs_N = linregress(X, Y)[0]
self.assertTrue(slope_of_error_vs_N < 0)
评论列表
文章目录