-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Math.random in mode:gpu #498
Comments
Do you have a link to that function? It was super difficult to find any insight when implementing. |
Hi Robert, I am quite new to gpu.js and zero-knowledge of WebGL, shaders ... so I think to be quite hopeless in finding a solution. To be totally honest I just had the intuition that the problem was in the choice of n4rand. In https://www.shadertoy.com/view/4t2SDh, you can find the file generating the noise with the 4 different functions. One can see that nrand produce a uniform histogram, while the others n1rand, n2rand, n3rand and n4 rand produces triangle and bell shaped histograms. In your plugin triangle-noise.js, you make a functionReplace of Math.random() with n4rand(vTexCoord). If I interpreted correctly your code, the right function should be nrand. My script for testing the statistical properties of the random numbers is attached here (as I said, I run it with node and one can alternatively select "cpu" or "gpu" in line 10). If you take the data saved in the txt file and plot the histogram you will immediately see the bell shaped curve for the data generated with the "gpu" mode. |
Fantastic! Ty for not attacking this, it was quite the thing to figure out. I'll review asap, and get it corrected. Again TY! |
Thanks to you and the gpu team for the fantastic job you are doing with gpu.js! |
ty for trying it! |
Hi Robert, did you succeed in changing algorithm?
Ottieni Outlook per Android<https://aka.ms/ghei36>
…________________________________
From: Marcello Esposito
Sent: Friday, September 20, 2019 3:05:51 PM
To: gpujs/gpu.js <reply@reply.github.com>; gpujs/gpu.js <gpu.js@noreply.github.com>
Cc: Author <author@noreply.github.com>
Subject: Re: [gpujs/gpu.js] Math.random in mode:gpu (#498)
Hi Robert, i forgot to tell you if you can send me an email when you have solved the problem.
Yours, Marcello
Ottieni Outlook per Android<https://aka.ms/ghei36>
________________________________
From: Robert Plummer <notifications@github.com>
Sent: Thursday, September 19, 2019 12:12:36 AM
To: gpujs/gpu.js <gpu.js@noreply.github.com>
Cc: marcelloexp386 <exp386@hotmail.com>; Author <author@noreply.github.com>
Subject: Re: [gpujs/gpu.js] Math.random in mode:gpu (#498)
ty for trying it!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2Fgpujs%2Fgpu.js%2Fissues%2F498%3Femail_source%3Dnotifications%26email_token%3DAHWOONHEUWCK73QIJUWBI5TQKKRVJA5CNFSM4IYC6IRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7BTNZI%23issuecomment-532887269&data=02%7C01%7C%7Ca5e95f3c2df54069dd0708d73c85505c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637044415578917651&sdata=11d4KAi%2B8JOsX0nH2zXcxJ1uAdbylAvD%2Bt%2Fb9T2scEc%3D&reserved=0>, or mute the thread<https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.luolix.top%2Fnotifications%2Funsubscribe-auth%2FAHWOONCHVJLXLQJVUX7Y5NDQKKRVJANCNFSM4IYC6IRA&data=02%7C01%7C%7Ca5e95f3c2df54069dd0708d73c85505c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637044415578927656&sdata=QjhDRip0rRKy3KmeJyOfILzSbNiZZUcYz%2BfOfmVqOic%3D&reserved=0>.
|
Hi Robert, did you succeed in changing algorithm?> I tried some changes out this morning on this branch: https://github.com/gpujs/gpu.js/tree/498-uniformly-distributed |
FYI: https://github.com/gpujs/gpu.js/tree/498-uniformly-distributed will be merged soon, and addresses the issue brought up here. |
Hi Robert, tremendous improvement! I run a "pi" test (i.e. estimation of the pi value) and now the results do not show anymore the systematic bias. Still, the GPU method produces worse estimates (in the sense of higher stdev) than the CPU method, but this was expected. If, somewhere in your blog, you can mention RandomPower for having contributed to your project, it would be very much appreciated. RandomPower is a university spin-off where we use a quantistic effect of the light in order to generate True Random Numbers . |
Do you have a link to RandomPower? |
Can you get me more details on the contribution? |
? In reality, my contribution was just about "testing" your random number generator algorithm. So, I would simply mention randompower.eu among the contributors to the gpujs project. |
Awesome! Is there any sort of qualification that our random generates that we can make mention of? |
We can analyze their statistical properties but it will take a bit of time because at the moment we are working on the hardware of our project. As soon as we have a couple of days free, we can come back with some stats. |
I'll just put a shout out to RandomPower in the readme if that is ok. That way everyone sees it. Also, I very much look forward to those test results! |
What is wrong?
The random number distribution is Normal instead of Uniform[0,1]
Where does it happen?
Ex. In GPU.js when I run Math.random inside a gpu.createKernel(function() in Node.js on my pc windows 10 and Nvidia GPU
NB If mode is set to cpu, all else equal, the numbers are Unifom
How do we replicate the issue?
const { GPU } = require('gpu.js');
const gpu = new GPU({ mode: 'gpu' });
const nobs=10000;
const kernel = gpu.createKernel(function() {
const y=Math.random();
return y;
}, { output: [nobs] });
const data = kernel();
How important is this (1-5)?
5
Expected behavior (i.e. solution)
the data should be uniform
Other Comments
Probably, in the plugin you should have chosen nrandom instead of n4random.
The text was updated successfully, but these errors were encountered: