Loading...
Logo
Processing Forum

Cumulative distribution function

in General Discussion  •  Other  •  8 months ago  
Hello all,
I have a question about math.

So, there is the Probability Density Function (PDF) (or Gaussian function or Bell Curve) for some programming examples. The formula is: [a * e^( ( -( x - b )^2 ) / ( 2 * c^2 ) )], but you can use the link to see it written better.
I have used this function in a Processing programming example, where there is a plane in the 3d space, and various functions are applied to it, additively, producing various morphs. The gaussian function produces Hills... 

There are, though, some other examples I have in mind, for which I need to use the Cumulative Distribution Function (CDF). CDF is related to PDF, and more precisely, CDF is the integral of PDF. So if i have an entity that grows over time and PDF represents its growth over time, then CDF will represent its size over time.
Suppose, for example, that the growth of a tree (or a branch) starts slowly, then maximizes, and then slows down again. This is a phenomenon that can be described (or modelled over time) by the Gaussian Function. The length of the branch, though, can be calculated over time by the Integral of this function, which is the Cumulative Distribution Function.

Well, I am having some trouble in finding a way to programmatically describe the Cumulative Distribution Function, because I cannot find a formula for it that can be expressed within the boundaries of Processing. (It can be done very simply in Matlab)

Any help would be greatly appreciated... 

Replies(4)

This is also known as the 'normal distribution curve' so I have done some research and it appears that the CDF cannot be expressed in terms of simple functions (see here) so there is no solution and I suspect that Matlab was producing a numerical solution.

It should be simple to create a simulator that would provide a reasonably accurate numerical value for the CDF for a given x (where x is the number of standard deviations from the mean).
Hm... you are right about the first part. 
 
1) Have you found any link to an approximation algorithm? (simulation)
2) I am also concerned if such a solution would require alot of coding (I need it to be quite fast)
3) It would also be useful to me if I could find another function that produces a similar graph. (starting from a state, ascending slowly, ascending fast, descending fast, descending slowly, stabilizing to a state). 
Any ideas for such a graph / function? 
It could be a part of a sinusoidal function. For example:
if x < 0                     f(x) = 0
if 0 < x < PI              f(x) = sin(x)
if x > PI                    f(x) = 1

But still wondering if there is another function that produces a similar graph, without condition checks for the value of x.

In answer to 1 and 3 the answer is yes it is called the sigmoid curve whose equation is



S(t) will always be in the range 0.0 to 1.0 same as the CDF.

I have assumed that you want S(t) to be very close to zero when x = 0 and very close to one when x = 1.0 (in all curves of this type the limits are only truly reached when x = + or - infinity)

If this is the case then the function below will do want you want

Copy code
  1. float sigmoid(float x){
  2.   return 1.0/(1.0 + exp(-10.0 * (x - 0.5)));
  3. }

This function gives the result :

sigmoid(0.0) = 0.006692851
sigmoid(1.0) = 0.9933072

HTH
Well, thanks for the tip!
I think this will do the trick