Skip to content

Instantly share code, notes, and snippets.

@mhlr

mhlr/zipf.R

Last active Jan 10, 2017
Embed
What would you like to do?
generate Zipf distributed data as described in http://arxiv.org/abs/1407.7135
# gnerate Zipf distributed data as described in
# http://arxiv.org/abs/1407.7135
# 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