print('Before PCA transforMation, data is:\n', Mat) print('\nMethod 1: PCA by original algorithm:') p,n = np.shape(Mat) # shape of Mat t = np.mean(Mat, 0) # mean of each column # substract the mean of each column for i in range(p): for j in range(n): Mat[i,j] =...
print('Before PCA transforMation, data is:\n', Mat) print('\nMethod 1: PCA by original algorithm:') p,n=np.shape(Mat) # shape of Mat t= np.mean(Mat,0) # mean of each column # substract the mean of each columnforiinrange(p):forjinrange(n): Mat[i,j]=float(Mat[i,j]-t[...
# a implementation of 2D^2 PCA algorithm import numpy as np from PIL import Image def PCA2D_2D(samples, row_top, col_top): '''samples are 2d matrices''' size = samples[0].shape # m*n matrix mean = np.zeros(size) for s in samples: mean = mean + s # get the mean of all ...
print('Before PCA transforMation, data is:\n', Mat) print('\nMethod 1: PCA by original algorithm:') p,n = np.shape(Mat) # shape of Mat t = np.mean(Mat, 0) # mean of each column # substract the mean of each column for i in range(p): for j in range(n): Mat[i,j] =...
# PCA by original algorithm # eigvalues and eigenvectors of covariance Matrix with eigvalues descending U,V = np.linalg.eigh(cov_Mat) # Rearrange the eigenvectors and eigenvalues U = U[::-1] for i in range(n): V[i,:] = V[i,:][::-1] ...
(U) for i in range(1, len(U)+1)]) sys.exit(0) # data transformation T1 = np.dot(Mat, v) # print the transformed data print('We choose %d main factors.'%Index) print('After PCA transformation, data becomes:\n',T1) # PCA by original algorithm using SVD print('\nMethod 2: ...
#PCAbyoriginal algorithm using SVDprint('\nMethod 2:PCAbyoriginal algorithm using SVD:') #u: Unitarymatrix, eigenvectorsincolumns #d:listof the singular values, sortedindescendingorderu,d,v = np.linalg.svd(cov_Mat) Index = index_lst(d, rate=0.95) # choose how many main factors ...
Input: 无序化的点云,维度k Output:点云对应的kd-tree Algorithm: 1、初始化分割轴:对每个维度的数据进行方差的计算,取最大方差的维度作为分割轴,标记为r; 2、确定节点:对当前数据按分割轴维度进行检索,找到中位数数据,并将其放入到当前节点上; 3、划分双支: 划分左支:在当前分割轴维度,所有小于中位数的...
二、PCA的人脸识别算法(基于Python实现) 一、数据集的说明及相关函数的实现 我们使用的是ORL官方数据集,可以从一下网址下载到ORL下载链接 下载后的数据集是这个样子的: 该数据集表示的是一共有40个人的人脸图像,其中每一个人有10张人脸图像。相应的PGM文件为说明。
dataprint('We choose %d main factors.'%Index)print('After PCA transformation, data becomes:\n',T1)# PCA by original algorithm using SVDprint('\nMethod 2: PCA by original algorithm using SVD:')# u: Unitary matrix, eigenvectors in columns# d: list of the singular values, sorted in desce...