PDA

View Full Version : Deriving points conforming to bell curve


MichaelEber
Jun21-10, 02:30 PM
I am writing a system that collects values from our devices (CRAH, Generators, etc) compute the trend of the data, and determine if an alarm should be raised.

For testing I have a point generator and I want it to follow fairly realistic norms. Currently I generate a new point as:

p.Y = p'.Y + rand.NextDouble()-.5; | p' is the previous point, and Y is the value being generated (p.X is a point in time)

This is taking the value of the last point and adding a random variant that is +- .5.

The problem is that rand will generate a totally linear grouping of numbers. What I want to do is put that point through a computation so that the next point follows a bell curve. Therefore it is more likely to generate a difference of (say) .09 - -.09 then it is .5 and .5 is closer to a 0 chance of generation than any other point.

I've used google and searched a few math forums but most of the discussion is from data analysis after the fact not during generation of the points.

Any suggestions on a formulae that would produce the desired distribution?

EnumaElish
Jun21-10, 05:42 PM
What I want to do is put that point through a computation so that the next point follows a bell curve.Do you mean to replace p.Y = p'.Y + rand.NextDouble()-.5 with
p.Y = p'.Y + NormallyDistributedRandomVariableWithZeroMean ?

MichaelEber
Jun21-10, 05:45 PM
Well I guess that is what I mean. So what is the formula for that?

CRGreathouse
Jun21-10, 06:50 PM
Well I guess that is what I mean. So what is the formula for that?

The Box–Muller transform (http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) is a good way. But you're going to have to decide what standard deviation to use, and that depends on your application.

EnumaElish
Jun21-10, 07:18 PM
Well I guess that is what I mean. So what is the formula for that?Generally speaking, you need to apply the inverse-normal (inverse Gaussian) transformation to a random variable between 0 and 1; one way is to use the algorithm CRGreathouse suggested.

MichaelEber
Jun21-10, 08:09 PM
Thanks for the input. Looking at the Box Muller transform, it is aimed at creating an x,y point in a two dimensional space. Since I was only interested in generating points along the x-axis I used the s1 part of the transform.

p.Y = p'.Y + (Math.Sqrt( -2 * Math.Log( rand.NextDouble( ) ) ) * Math.Cos( 2 * Math.PI * rand.NextDouble( ) )) - .5;

where each rand.NextDouble() supplies the random x1 and y1 from the evenly distributed range of points between 0 and 1.

plugged it into the formula and will begin testing soon to see how it goes.

Thanks.

CRGreathouse
Jun21-10, 10:40 PM
The s2 is just another random normal variable. You get two for the price of one. If speed is an issue, generate them two at a time; if not, the formula you have works.