Skip to content

Instantly share code, notes, and snippets.



Last active Jan 10, 2017
What would you like to do?
generate Zipf distributed data as described in
# gnerate Zipf distributed data as described in
# Zipf's law arises naturally in structured, high-dimensional data
# Laurence Aitchison, Nicola Corradi, Peter E. Latham
n <- 2**22
k <- 20
b <- rnorm(k, 1, 0.2)
data <- replicate(n, {z <- runif(1)
p <- (z^b) / (z^b + (1-z)^b)
sum((runif(k) < p) * (2**(0:(k-1)))) })
tbl <- sort(table(data), decreasing=TRUE)
plot(log2(1:length(tbl)), log2(tbl))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment