n = 10 p = 2 N = 15 print(f'Example 1: {N} points on Gr({p}, {m}) embedded in Gr({p}, {n})\n') sig = 0.1 gr_low = Grassmann(m, p, N) gr = Grassmann(n, p, N) gr_map = Grassmann(n, m) X_low = gr_low.rand() # N x m x p A = gr_map.rand() # n x m #B = np.random.normal(0, 0.1, (n, p)) # n x p B = np.zeros((n,p)) AAT = np.matmul(A, A.T) IAATB = np.matmul(np.eye(n) - AAT, B) X = np.array([np.linalg.qr(np.matmul(A, X_low[i]) + IAATB)[0] for i in range(N)]) # N x n x p X = gr.exp(X, sig * gr.randvec(X)) # perturb the emdedded X scores = PNG(X, log = True) print('\n') print('PCA of the scores\n') n_c = 5 pca = PCA(n_components = n_c) pca.fit(scores) print(f'The ratios of expressed variance first {n_c} PCs.') print(pca.explained_variance_ratio_.round(2)) print(f'The cumulative ratios of expressed variance first {n_c} PCs.') print(np.cumsum(pca.explained_variance_ratio_).round(2))