Commit 71bef5c5 authored by Corson N. Areshenkoff's avatar Corson N. Areshenkoff

Fix Riemannian interp

parent 39f82046
# For fractional powers...
mat.frac.pow <- function(x, p){
d <- eigen(x)
return(d$vectors %*% diag(d$values^p) %*% t(d$vectors))
return(d$vectors %*% diag(d$values^p) %*% solve(d$vectors))
}
# Interpolation functions
spd.interpolate.euclidean <- function(x, y, t, ...){
return((t-1)*x + t*y)
return((1-t)*x + t*y)
}
spd.interpolate.logeuclidean <- function(x, y, t, ...){
......@@ -8,7 +8,7 @@ spd.interpolate.logeuclidean <- function(x, y, t, ...){
}
spd.interpolate.riemannian <- function(x, y, t, ...){
x.inv.sqrt <- sqrtm(solve(x))
x.inv.sqrt <- solve(sqrtm(x))
x.sqrt <- sqrtm(x)
return(x.sqrt * mat.frac.pow(x.inv.sqrt %*% y %*% x.inv.sqrt, t) %*% x.sqrt)
return(x.sqrt %*% mat.frac.pow(x.inv.sqrt %*% y %*% x.inv.sqrt, t) %*% x.sqrt)
}
......@@ -7,12 +7,12 @@
#' @param unwhiten Logical. If TRUE, reverses a previously applied whitening transform.
#' @return A symmetric, positive-definite matrix.
to <- cov(matrix(rnorm(30), ncol = 3))
from <- cov(matrix(rnorm(30), ncol = 3))
x <- cov(matrix(rnorm(30), ncol = 3))
x <- spd.logmap(x, from)
# to <- cov(matrix(rnorm(30), ncol = 3))
# from <- cov(matrix(rnorm(30), ncol = 3))
# x <- cov(matrix(rnorm(30), ncol = 3))
# x <- spd.logmap(x, from)
spd.transport <- function(x, to, from){
spd.transport <- function(x, to, from, nsteps = 10){
if (!'s.mat' %in% input.type(x)){
stop('x must be a positive definite matrix')
......@@ -24,6 +24,11 @@ spd.transport <- function(x, to, from){
stop('from must be a positive definite matrix')
}
return(x)
geod <- lapply(seq(0, 1, length.out = nsteps), function(i) {
spd.interpolate(from, to, t = i, method = 'riemannian')
})
return(NULL)
}
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