Skip to content

Instantly share code, notes, and snippets.

@alexpghayes
Created June 27, 2022 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpghayes/6fa2d111508d2a0c774eb29092ed0f63 to your computer and use it in GitHub Desktop.
Save alexpghayes/6fa2d111508d2a0c774eb29092ed0f63 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
sum_squared_error <- sum(diff^2)
list(
s = s,
rotation = rotation,
Yrot = Yrot,
diff = diff,
sum_squared_error = sum_squared_error
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment