Commit e24620ba authored by Corson N. Areshenkoff's avatar Corson N. Areshenkoff

Add stein distance

parent 6402edd5
......@@ -10,7 +10,7 @@ Imports: expm, huge, nlshrink, kernlab, lattice
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
RoxygenNote: 6.1.0
Suggests: knitr,
rmarkdown
VignetteBuilder: knitr
......@@ -16,3 +16,8 @@ spd.dist.riemannian <- function(x,y,...){
z <- x.inv.sqrt %*% y %*% x.inv.sqrt
return(norm(logm2(x.inv.sqrt %*% y %*% x.inv.sqrt), type = 'F'))
}
spd.dist.stein <- function(x,y,...){
d <- log(det( (x+y)/2 )) -.5 * log(det(x%*%y))
return(sqrt(d))
}
......@@ -12,6 +12,7 @@
#' \item{"cholesky": }{The Frobenius norm of the difference between the cholesky factors
#' of \code{x} and \code{y}. Not affinely invariant.}
#' \item{"riemannian": }{The Riemmanian distance proposed by Barachant, et al. (2013)}
#' \item{"stein": }{The square root of Jensen;Bregman Log determinant divergence}
#' }
spd.dist <- function(x, y, method = 'euclidean', ...){
......@@ -21,7 +22,7 @@ spd.dist <- function(x, y, method = 'euclidean', ...){
}
if (!method %in% c('euclidean', 'logeuclidean', 'cholesky',
'riemannian', 'kl')){
'riemannian', 'stein')){
stop('Unrecognized method')
}
......@@ -30,6 +31,7 @@ spd.dist <- function(x, y, method = 'euclidean', ...){
euclidean = spd.dist.euclidean(x, y, ...),
logeuclidean = spd.dist.logeuclidean(x, y, ...),
cholesky = spd.dist.cholesky(x, y, ...),
riemannian = spd.dist.riemannian(x, y, ...))
riemannian = spd.dist.riemannian(x, y, ...),
stein = spd.dist.stein(x, y, ...))
return(d)
}
......@@ -23,6 +23,6 @@ Allowable distance measures are
\item{"cholesky": }{The Frobenius norm of the difference between the cholesky factors
of \code{x} and \code{y}. Not affinely invariant.}
\item{"riemannian": }{The Riemmanian distance proposed by Barachant, et al. (2013)}
\item{"kl": }{The symmetric KL divergence between \code{x} and \code{y}}
\item{"stein": }{The square root of Jensen;Bregman Log determinant divergence}
}
}
......@@ -4,7 +4,7 @@
\alias{spd.pca}
\title{Kernel pca for SPD matrices}
\usage{
spd.pca(x, method = "logeuclidean", sigma = 1, ...)
spd.pca(x, method = "euclidean", sigma = 1, ...)
}
\arguments{
\item{x}{A list of symmetric, positive-definite matrices}
......
......@@ -10,6 +10,7 @@ test_that("All distance methods run without error", {
expect_error(spd.dist(x, y, method = 'logeuclidean'), NA)
expect_error(spd.dist(x, y, method = 'cholesky'), NA)
expect_error(spd.dist(x, y, method = 'riemannian'), NA)
expect_error(spd.dist(x, y, method = 'stein'), NA)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment