OBD talk:BINA/PAR3: Difference between revisions

From OniGalore
Jump to navigation Jump to search
m (oh boy... *now* it seems correct)
m (f##k)
Line 81: Line 81:


[[User:Neo|Neo]]
[[User:Neo|Neo]]
:The term "inverse normal" is apparently not conventional, and also rather confusing because it can be mistaken as referring to either the [[wikipedia:Normal-inverse_Gaussian_distribution|normal-inverse Gaussian distribution]] or the [[wikipedia:http://en.wikipedia.org/wiki/Inverse_Gaussian_distribution|inverse Gaussian distribution]], both of which are rather exotic and irrelevant here.
:The term "inverse normal" is apparently not conventional, and also rather confusing because it can be mistaken as referring to either the [[wikipedia:Normal-inverse_Gaussian_distribution|normal-inverse Gaussian distribution]] or the [[wikipedia:Inverse_Gaussian_distribution|inverse Gaussian distribution]], both of which are rather exotic and irrelevant here.
:What we have here is the inverse of the [[wikipedia:Error_function|error function]] or rather that of [[wikipedia:Normal_distribution#Standard_deviation_and_confidence_intervals|erfc(x/sqrt(2))]]. If you have Java installed, [http://onlinestatbook.com/analysis_lab/inverse_normal_dist.html HERE] is a nice applet that you can toy around with to see just what the table in your PDF link corresponds to.
:What we have here is the inverse of the [[wikipedia:Error_function|error function]] or rather that of [[wikipedia:Normal_distribution#Standard_deviation_and_confidence_intervals|erfc(x/sqrt(2))]]. If you have Java installed, [http://onlinestatbook.com/analysis_lab/inverse_normal_dist.html HERE] is a nice applet that you can toy around with to see just what the table in your PDF link corresponds to.
:As further pointed out [[wikipedia|Normal_distribution#Generating_values_for_normal_random_variables|HERE]], inverting the [[wikipedia:Normal_distribution#Cumulative_distribution_function|standard normal cdf]] gives you a way to generate ''normally'' distributed random variables from a ''uniformly'' distributed random variable, which is exactly what Oni does (see Neo's code sample above).
:As further pointed out [[wikipedia:Normal_distribution#Generating_values_for_normal_random_variables|HERE]], inverting the [[wikipedia:Normal_distribution#Cumulative_distribution_function|standard normal cdf]] gives you a way to generate ''normally'' distributed random variables from a ''uniformly'' distributed random variable, which is exactly what Oni does (see Neo's code sample above).
:The float r is a ''uniformly'' distributed random variable in (-1.0,1.0) (@ Neo: please check). Same for x except the interval is now [0.0,10.0). z is a first approximation of erfc(0.0998 * x / sqrt(2)), interpolated linearly between erfc(0.0998 * floorf(x) / sqrt(2)) and erfc(0.0998 * (floorf(x) + 1) / sqrt(2)). The table is thus sampled uniformly.
:The float r is a ''uniformly'' distributed random variable in (-1.0,1.0) (@ Neo: please check). Same for x except the interval is now [0.0,10.0). z is a first approximation of erfc(0.0998 * x / sqrt(2)), interpolated linearly between erfc(0.0998 * floorf(x) / sqrt(2)) and erfc(0.0998 * (floorf(x) + 1) / sqrt(2)). The table is thus sampled uniformly.
:The result ( v1 + z * v2 ) is, to a good approximation, a ''normally'' distributed random variable, centered at v1 and with standard mean deviation v2. Apart from the approximation arising from the linear interpolation, the distribution is cut off at 99.8% of expectancy, so all the values will be within 3.09023*v2 of v1.
:The result ( v1 + z * v2 ) is, to a good approximation, a ''normally'' distributed random variable, centered at v1 and with standard mean deviation v2. Apart from the approximation arising from the linear interpolation, the distribution is cut off at 99.8% of expectancy, so all the values will be within 3.09023*v2 of v1.
::[[User:Geyser|geyser]] 03:12, 7 December 2007 (CET)
::[[User:Geyser|geyser]] 03:12, 7 December 2007 (CET)

Revision as of 02:17, 7 December 2007

To value types:

What the both values of the normal distribution stand for?

First value μ (mean) and second value σ (standard deviation)?

Ssg 23:13, 5 December 2007 (CET)

No as far as I can tell. The value is interpolated from an "InverseNormalTable" (0, 0.125, 0.2533, 0.3850, 0.5244, 0.6745, 0.8416, 1.0364, 1.2816, 1.6449, 3.0902, 1.6449, 1.2816, ...). The resulting value is multiplied with the second value and the first value is added to the result, so those 2 value are more like "offset" and "scale". I don't know why the table is called "InverseNormal", maybe this is actually normal inverse distribution but it does not look like so.

Neo

Thanks for your answer.

I've googled a (long) bit for that "InverseNormalTable". It seems to be okay. This table is also called "inverse standardized normal distribution" (see http://files.hanser.de/hanser/docs/20040419_24419112747-75_3-446-21594-8Anhang2.pdf)

The equation for the inverse normal distribution is: x = σ * z + μ

with:

x = result
z = looked up in the z-table (the z-table here is the InverseNormalTable)
μ = mean
σ = standard deviation

Unfortunately I've no idea what's the basis for Oni's interpolation (IMO Oni needs an entry point for the table), so I haven't got a clue what the result is for.

Ssg 20:26, 6 December 2007 (CET)

The interpolation is easy: it picks a random number between -9.99 and 9.99 and it uses it to interpolate the table (linear interpolation).

And I don't know if you noticed, the WMDD for values says "Bell Curve" :)

Neo

A quick note: I messed up the table, it's (-3.0902, ..., -0.2533, -0.125, 0, 0.125, 0.2533, 0.3850, 0.5244, 0.6745, 0.8416, 1.0364, 1.2816, 1.6449, 3.0902).

Neo

>>it picks a random number between -9.99 and 9.99 and it uses it to interpolate the table (linear interpolation).

I don't get that. Can you give an example, please? Let's say Oni picks up the value 9. How does the interpolation work?

Like this:

-3.0902 = -9.99
-1.6449 = -8.99
...
-0.125 = -0.99
0 = 0
...
3.0902 = 9.99?

>>And I don't know if you noticed, the WMDD for values says "Bell Curve" :)

Yes, I've noticed that. Do you think the first value is not the mean?

>>I messed up the table

No problem. Now it fits much better to the pdf file above. ;-)

Ssg 22:32, 6 December 2007 (CET)

This should clear up everything:

float InverseNormalTable[] = { 0.0f, 0.125f, 0.2533f, 0.3853f, 0.5244f, 0.6745f, 0.8416f, 1.0364f, 1.2816f, 1.6449f, 3.0902f };

float InverseNormalRandom(float v1, float v2)
{
    float r = frnd(); // generates a random number in [-0.999, 0.999]
    float x = fabsf(r) * 10.0f;
    int i = floorf(x);
    float z = InverseNormalTable[i] + (x - i) * (InverseNormalTable[i + 1] - InverseNormalTable[i]);

    if (r < 0.0f)
        z = -z;

    return v1 + z * v2;
}

Neo

The term "inverse normal" is apparently not conventional, and also rather confusing because it can be mistaken as referring to either the normal-inverse Gaussian distribution or the inverse Gaussian distribution, both of which are rather exotic and irrelevant here.
What we have here is the inverse of the error function or rather that of erfc(x/sqrt(2)). If you have Java installed, HERE is a nice applet that you can toy around with to see just what the table in your PDF link corresponds to.
As further pointed out HERE, inverting the standard normal cdf gives you a way to generate normally distributed random variables from a uniformly distributed random variable, which is exactly what Oni does (see Neo's code sample above).
The float r is a uniformly distributed random variable in (-1.0,1.0) (@ Neo: please check). Same for x except the interval is now [0.0,10.0). z is a first approximation of erfc(0.0998 * x / sqrt(2)), interpolated linearly between erfc(0.0998 * floorf(x) / sqrt(2)) and erfc(0.0998 * (floorf(x) + 1) / sqrt(2)). The table is thus sampled uniformly.
The result ( v1 + z * v2 ) is, to a good approximation, a normally distributed random variable, centered at v1 and with standard mean deviation v2. Apart from the approximation arising from the linear interpolation, the distribution is cut off at 99.8% of expectancy, so all the values will be within 3.09023*v2 of v1.
geyser 03:12, 7 December 2007 (CET)