pancerZH / PCA_with_mnist

使用PCA和2DPCA对mnist中的数据进行降维
30 stars 4 forks source link

There is a problem with your code #1

Open zt823793279 opened 3 years ago

zt823793279 commented 3 years ago

There is a problem with your code

imgs 是三维的图像矩阵,第一维是图像的个数 ''' def TwoDPCA(imgs, dim): a,b,c = imgs.shape average = np.zeros((b,c)) for i in range(a): average += imgs[i,:,:]/(a1.0) G_t = np.zeros((c,c)) for j in range(a): img = imgs[j,:,:] temp = img-average G_t = G_t + np.dot(temp.T,temp)/(a1.0) w,v = np.linalg.eigh(G_t)

print('v_shape:{}'.format(v.shape))

**w = w[::-1]
v = v[::-1]**
'''
for k in range(c):
    # alpha = sum(w[:k])*1.0/sum(w)
    alpha = 0
    if alpha >= p:
        u = v[:,:k]
        break
'''
print('alpha={}'.format(sum(w[:dim]*1.0/sum(w))))
u = v[:,:dim]
print('u_shape:{}'.format(u.shape))
return u  # u是投影矩阵
pancerZH commented 3 years ago

Hi,

Thank you for pointing it out and I apology for the mistake. This is a toy project for one of my courses in university years ago, and I have left the area. So I am afraid I am not able to solve it...

If you would like to pull a request to fix this mistake, I’d thank you greatly for that and accept it. Or I’ll leave this issue open and make a note in the readme file to prevent future confusion.