Created
May 9, 2012 00:51
-
-
Save bmander/2640802 to your computer and use it in GitHub Desktop.
print probability density function and a samples of the exponential distribution
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
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