st.mean: Fréchet Mean on Stiefel Manifold

Description Usage Arguments Value References Examples

View source: R/st_mean.R

Description

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.

Usage

1
st.mean(x, type = c("intrinsic", "extrinsic"), eps = 1e-06, parallel = FALSE)

Arguments

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 "intrinsic" or "extrinsic".

eps

stopping criterion for the norm of gradient.

parallel

a flag for enabling parallel computation with OpenMP.

Value

a named list containing

mu

an estimated mean matrix of size (p\times r).

variation

Fréchet variation with the estimated mean.

References

\insertRef

bhattacharya_nonparametric_2012RiemStiefel

Examples

 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)

RiemStiefel documentation built on March 26, 2020, 7:48 p.m.