Skip to content

Instantly share code, notes, and snippets.

@dmarx
Created January 30, 2017 01:37
Show Gist options
  • Select an option

  • Save dmarx/c072c304ba312bf8bb487b17fbcdfbb7 to your computer and use it in GitHub Desktop.

Select an option

Save dmarx/c072c304ba312bf8bb487b17fbcdfbb7 to your computer and use it in GitHub Desktop.
Simulate null hypothesis distribution for Serrano's disparity filter
generate_distances = function(k){
u_k = c(0,sort(runif(k-1)),1)
u_k[-1] - u_k[-(k+1)]
}
iters=1e4
d = c(replicate(iters, generate_distances(2)))
plot(density(d), ylim=c(0,5))
#abline(v=mean(d), lty=2)
for(k in 3:6){
d = c(replicate(iters, generate_distances(k)))
lines(density(d), col=k)
#abline(v=mean(d), col=k, lty=2)
}
legend("topright", col=c(1,3:6), lty=1, title="degree", legend=2:6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment