Skip to content

Commit

Permalink
Extract the coord shrinking from scaled_pca.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmelville committed Dec 23, 2018
1 parent 7013d94 commit 7eea40c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,15 @@ rand_init_lv <- function(n, ndim, verbose = FALSE) {
scaled_pca <- function(X, ndim = 2, verbose = FALSE) {
tsmessage("Initializing from scaled PCA")
scores <- pca_scores(X, ncol = ndim, verbose = verbose)
scale(scores, scale = apply(scores, 2, stats::sd) / 1e-4)
shrink_coords(scores)
}

# Rescale embedding so that the standard deviation is the specified value.
# Default gives initialization like t-SNE, but not random. Large initial
# distances lead to small gradients, and hence small updates, so should be
# avoided
shrink_coords <- function(X, sdev = 1e-4) {
scale(X, scale = apply(X, 2, stats::sd) / sdev)
}

# PCA
Expand Down

0 comments on commit 7eea40c

Please sign in to comment.