LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generation of random values

Solved!
Go to solution

There is a bug in the Continuous Random.vi for generation of random values from a Chi-squared and Chi-squared Non-Central distributions? When I plot successively the histogram with high resolution (many bins) the h(x) does not vary around the theoretical value as expected for some values of x.

0 Kudos
Message 1 of 18
(5,103 Views)

When you want to have confirmed a feature/bug you should always provide a VI showing your described behaviour…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 18
(5,086 Views)

I am using LabVIEW 2014 version 14.0 (32 bits).

The vi is attached.

Thank you.

0 Kudos
Message 3 of 18
(5,036 Views)

I agree that there is something really fishy, especially since the resulting distribution is not smooth, but has fixed peaks with a clear pattern in the noise (Even after I set "reset" to false).

 

If I substitute my own box-muller transform to generate the random values inside the function, the distribution is completely smooth with the given default values (as it should be!).

 

Somebody needs to look into this....

 

 

Message 4 of 18
(5,011 Views)

Thank you for your help. How we can warn the NI to correct this problem?

0 Kudos
Message 5 of 18
(4,985 Views)
Solution
Accepted by topic author Ricardo_Luis

I posted a bug note over there.

 

Here is a comparison between using the NI tools vs. my own normal random generator (based on Box Muller). As you can see, NI has significantly more noise with peaks that are always in the same place. That noise is NOT random!

 

 

Message 6 of 18
(4,934 Views)

In LV13SP1 it is fine, but the Gaussian White Noise vi is labelled as obsolete with loud warning to replace it with a new version.

 

In LV14 they went ahead and replaced the "obsolete" version and you see what we have now.

 

For some reason they made the default value of 'Initialize' on the new Gaussian White Noise VI True so when it is called in a loop you are constantly resetting the random number generator state.  Just set it to False, or wire a false constant to it.

 

I feel a Math VI rant coming on, I had better stop while I am ahead....

0 Kudos
Message 7 of 18
(4,915 Views)
Solution
Accepted by topic author Ricardo_Luis

No, the problem persists even if you wire a false. Certain values are significantly more probable than others. Look at the noise difference!
I am currently posting by phone, but if you look up box muller on wikipedia, it lists two "more efficient" algorithms, the most efficient using some lookup table. Maybe they switched to that and there is some quantization due to the implementation detail (cannot tell because it calls a DLL)..
My last example above uses Gaussian white noise (SIG generation palette) vs. my Box Muller and it shows the same problem. I try to post the VI later.

0 Kudos
Message 8 of 18
(4,903 Views)

@altenbach wrote:

No, the problem persists even if you wire a false. Certain values are significantly more probable than others. Look at the noise difference!


I will stick with what my own lying eyes tell me versus your phone posts in this instance, even if you are yelling at your phone.  Here is the noise difference I am looking at between the LV generated values in LV14 when I wire a false constant and a true constant to the Initialize Input of the Gaussian White Noise VI inside Normal Random.vi.  (Same effect as setting default value to False).  Solid line is calculated Chi-Square distribution:

 

ChiSquareDistBug.png

 

Not sure which problem you say persists.  Besides, diffing LV13 and LV14 versions point directly at this being the culprit as well.

 

Edit:  Picture showed up, then disappeared.  What is shows is a quite nice chi-squared distribution when I wired a true constant and the spikey output when I wired a true constant (or removed the constant and used the default value).

0 Kudos
Message 9 of 18
(4,887 Views)

Yes, I reproduces this too, now that I sit at the computer. 😄 However, "initialize?" is also TRUE in all older versions I tested (2012, 2013sp1). (I think it should be false). EDIT: actually, if initialize=true, and seed=-1 (the default!) it will pick a random seed with each call, so this looks OK.

 

I agree that setting initialize=false in the gaussian random signal generation fixes the problem.

 

I did not test this, because it had no effect in the original VI. If you set initialize to FALSE in the original code using the chis-quared instance of "Continuous Random VI", the problem persists. Somehow something gets reset internally anyway, but I cannot tell where...

 

 

0 Kudos
Message 10 of 18
(4,868 Views)