Skip to content

Instantly share code, notes, and snippets.

@bmander
Created May 9, 2012 00:51
Show Gist options
  • Save bmander/2640802 to your computer and use it in GitHub Desktop.
Save bmander/2640802 to your computer and use it in GitHub Desktop.
print probability density function and a samples of the exponential distribution
float sc;
float tau;
void setup(){
size(500,500);
smooth();
strokeWeight(1);
background(255);
sc = height*10;
tau = 0.02;
for(int i=0; i<width; i++){
line(i,height-sc*exp_pdf(i,tau),i+1,height-sc*exp_pdf(i+1,tau));
}
strokeWeight(0.01);
}
float exp_pdf(float x, float tau){
return tau*exp(-tau*x);
}
float exp_sample(float tau){
return -log(random(0,1))/tau;
}
void draw(){
float x = exp_sample(tau);
line(x,0,x,height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment