Skip to contents

Computes the geodesic distance on \(Gr(n, k)\) between each row of X and the base point p: the square root of the sum of the squared principal angles between the two subspaces. It is evaluated as the norm of log_map_grassmann, which is numerically accurate for nearby subspaces.

Usage

dist_grassmann(X, p, n, k)

Arguments

X

A matrix or data frame of Grassmann data; rows are samples, with n * k columns (see manifold_grassmann).

p

The base point: a vector of length n * k or an n x k matrix with orthonormal columns.

n

Integer: dimension of the ambient space.

k

Integer: dimension of the subspaces, 1 <= k <= n - 1.

Value

Numeric vector of length nrow(X): the Grassmann distance from each row of X to p.

Examples

U0 <- diag(4)[, 1:2]
X <- exp_map_grassmann(matrix(rnorm(40, sd = 0.3), nrow = 10), U0)
dist_grassmann(X, U0, n = 4, k = 2)
#>  [1] 0.6849014 0.7425378 0.3715088 0.8726814 0.4152398 0.8000914 0.7329405
#>  [8] 0.5446988 0.6837500 0.5736249