Skip to content

Instantly share code, notes, and snippets.

@alexpghayes
Created April 6, 2023 19:27
Show Gist options
  • Save alexpghayes/de458376763a9ae0128082874c7b26b8 to your computer and use it in GitHub Desktop.
Save alexpghayes/de458376763a9ae0128082874c7b26b8 to your computer and use it in GitHub Desktop.
# rotate Y to align it to X
mypro <- function(X, Y) {
XY <- crossprod(X, Y)
s <- svd(XY)
rotation <- s$v %*% t(s$u)
Yrot <- Y %*% rotation
diff <- X - Yrot
colwise_loss <- Matrix::colSums(diff^2)
two_infty_loss <- max(sqrt(Matrix::rowSums(diff^2)))
list(
rotation = rotation,
Yrot = Yrot,
colwise_loss = colwise_loss,
two_infty_loss = two_infty_loss,
sum_squared_error = sum(colwise_loss)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment