Description Usage Arguments Value References Examples
For manifold-valued data, Fréchet mean is the solution of following cost function,
\textrm{min}_x ∑_{i=1}^n ρ^2 (x, x_i),\quad x\in\mathcal{M}
for a given data \{x_i\}_{i=1}^n and ρ(x,y) is the geodesic distance between two points on manifold \mathcal{M}. It uses a gradient descent method with a backtracking search rule for updating. In the Stiefel manifold case, analytic formula is not known so we use numerical approximation scheme.
1 |
x |
either an array of size (p\times r\times n) or a list of length n whose elements are (p\times r) matrix on Stiefel manifold. |
type |
type of distance, either |
eps |
stopping criterion for the norm of gradient. |
parallel |
a flag for enabling parallel computation with OpenMP. |
a named list containing
an estimated mean matrix of size (p\times r).
Fréchet variation with the estimated mean.
bhattacharya_nonparametric_2012RiemStiefel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #-------------------------------------------------------------------
# Average Projection with 'iris' dataset
#-------------------------------------------------------------------
# For PCA, take half of data from 'iris' data and repeat it 10 times.
# We will compare naive PCA, intrinsic, and extrinsic mean.
data(iris)
label = iris$Species # label information
idata = as.matrix(iris[,1:4]) # numeric data
ndata = nrow(idata)
# define a function for extracting pca projection
pcaproj <- function(X, p){
return(eigen(stats::cov(X))$vectors[,1:p])
}
# extract embedding for random samples
proj10 = list()
for (i in 1:10){
# index for random subsample
rand.now = base::sample(1:ndata, round(ndata/2))
# PCA via personal tool
proj10[[i]] = pcaproj(idata[rand.now,], p=2)
}
# compute intrinsic and extrinsic mean of projection matrices
mean.int = st.mean(proj10, type='intrinsic')$mu
mean.ext = st.mean(proj10, type='extrinsic')$mu
# compute 2-dimensional embeddings
fproj = pcaproj(idata, p=2)
f2 = idata%*%fproj # PCA with full data
i2 = idata%*%mean.int # projection with intrinsic mean
e2 = idata%*%mean.ext # projection with extrinsic mean
# visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3))
plot(f2, cex=0.5, pch=19, col=label, main='full PCA')
plot(i2, cex=0.5, pch=19, col=label, main='intrinsic projection')
plot(e2, cex=0.5, pch=19, col=label, main='extrinsic projection')
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.