Created
November 4, 2019 16:26
-
-
Save simon-anders/c72a947184deea8ba2f91a05951c3a79 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
# Swiss roll and Sleepwalk | |
n <- 10000 | |
# Draw random position on a rectangle | |
x0 <- runif( n, 0, 2*pi ) | |
y0 <- runif( n, 0, 6*pi ) | |
# Roll up the rectangle to form a Swiss roll | |
x <- x0 + rnorm( n, 0, .3 ) | |
y <- y0 * cos( y0 ) + rnorm( n, 0, .3 ) | |
z <- y0 * sin( y0 ) + rnorm( n, 0, .3 ) | |
# Plot an x-z cut to show the roll's cross section | |
plot( y, z, asp=1, col=rje::cubeHelix(n*1.2)[rank(y0)] ) | |
# Calculate a dimension-reduced embedding | |
ump <- uwot::umap( cbind( x, y, z ) ) | |
# Plot the UMAP embedding | |
plot(ump, asp=1, col=rje::cubeHelix(n*1.2)[rank(y0)] ) | |
# Visualize the embedding with Sleepwalk | |
sleepwalk::sleepwalk( ump, cbind( x, y, z ) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment