-
-
Save Tom4c3/78cfd6790be297feb753f1945f9c3869 to your computer and use it in GitHub Desktop.
melonpan-like visualization of "curse of dimensionality"
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
if( require("ggplot2") == FALSE ) install.packages("ggplot2"); library(ggplot2) | |
dimensions <- 1:700 | |
crisp_height <- .01 | |
crisp_area <- rep(NA, length(dimensions)) | |
#plot(1,1,type="n", xlim=c(min(dimensions),max(dimensions)), ylim=c(0,1)) | |
#abline(h = 1, lty="dashed") | |
for( D in dimensions ){ | |
#points(D, 1 - (1 - crisp_height)^D, pch="." ) | |
crisp_area[D] <- 1 - (1 - crisp_height)^D | |
} | |
theme_set( theme_bw() ) | |
i_dimensions <- c(3, 30, 100, 500) | |
setwd("~/dev/R/scribble/melon") | |
for( i_dim in i_dimensions ){ | |
melonpan_plot <- | |
ggplot() + | |
geom_rect(aes(xmin = 0, xmax=1, ymin=0, ymax=1-crisp_area[i_dim], fill="chewy")) + | |
geom_rect(aes(xmin = 0, xmax=1, ymax=1, ymin=1-crisp_area[i_dim], fill="crisp")) + | |
coord_polar() + | |
# labs(x=paste0(""i_dim)) + | |
theme( axis.text.x = element_blank(), | |
axis.text.y = element_blank(), | |
axis.ticks = element_blank(), | |
legend.position = "none") + | |
scale_fill_manual(values=c("#FFF0B9","#B75500")) + | |
labs(title=paste("MELONPAN IN ",i_dim, " DIMENSIONS\n", | |
"( represented in 2 dimensions )")) + | |
theme( title = element_text(family="Copperplate Gothic Bold")) | |
current_point <- data.frame(x=dimensions[i_dim], y=crisp_area[i_dim]) | |
curve_plot <- | |
ggplot(data.frame(x=dimensions, y=crisp_area)) + | |
geom_line(aes(x=x,y=y)) + | |
geom_point(data = current_point, | |
size=4, | |
aes(x=x,y=y)) + | |
geom_text(data = current_point, | |
family="HiraKakuProN-W3", | |
size=4, | |
aes(x=x+100,y=y-.03,label=paste0(round(y*100,1),"%がサクサク"))) + | |
labs(x="Number of Dimensions", y="Ratio of Crisp Area") + | |
coord_cartesian(xlim=c(1,700)) + | |
theme( axis.text = element_text(family="Copperplate Gothic Bold"), | |
axis.title= element_text(family="Copperplate Gothic Bold", size=14) | |
) | |
library(gridExtra) | |
png(paste0("melonpan_in_", i_dim, ".png"), width=900, height=400) | |
grid.arrange(melonpan_plot, curve_plot, ncol=2,nrow=1) | |
dev.off() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment