Created
March 18, 2021 16:49
-
-
Save alexpghayes/e71fc4cf8110c72af012dc795228732f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
set.seed(27) | |
n <- 100 | |
k <- 5 | |
A <- matrix(rnorm(n * n), nrow = n, ncol = n) | |
s <- svd(A, k, k) | |
# generate two n x k orthonormal bases | |
u <- s$u | |
v <- s$v | |
# following vu and lei (2013) -- inefficient in space | |
frob_norm_sq1 <- norm(tcrossprod(u) - tcrossprod(v), type = "F")^2 / 2 | |
# following rohe, chatterjee and yu (2011) -- efficient in space | |
s2 <- svd(crossprod(u, v)) | |
frob_norm_sq2 <- k - sum(s2$d^2) | |
frob_norm_sq1 | |
#> [1] 4.845742 | |
frob_norm_sq2 | |
#> [1] 4.845742 | |
``` | |
<sup>Created on 2021-03-18 by the [reprex package](https://reprex.tidyverse.org) (v1.0.0.9000)</sup> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment