generate more random numbers
Show older comments
Hi everyone, when i try to generate more 100 million random sample, I memory issue with matlab.
Is there a way to generate more than 100 million samples?
8 Comments
JL
on 20 Aug 2019
dpb
on 20 Aug 2019
Whether they're random or not has no bearing on the size of array you can hold in memory -- or at least only very marginally based on size of code loaded. You'll have same problem if use zeros or nan or repelem.
If you don't need the full precision of double you could cast to single but you may run into issue that has to generate as double first...not sure if the optional input argument 'single' causes singles to be used internally or just casts the output. For RNG, one would presume it's throughout so you might almost double the size possible. But 10X or more likely ain't agonna happen.
James Tursa
on 20 Aug 2019
What are you doing with these random numbers? Do you really need all of them in memory at the same time?
You could process whatever algorithm you're running in chunks or you could use tall arrays. A 3rd idea would be to generate chunks of random vars, store them in a text file (or multiple text files if needed) and read them in as needed.
dpb
on 20 Aug 2019
"generate chunks of random vars, store them in a text file (or multiple text files if needed) and read them in as needed."
If doing this, don't use a text file, use stream (aka "binary") files.
JL
on 20 Aug 2019
Nice, I wasn't familiar with that method. Thanks, dpb!
dpb
on 21 Aug 2019
For importance sampling you would have to have the translation adjustment for the normalization from the importance-sampled distribution.
Unless it takes multiple samples to actually compute the results, there's nothing preventing doing the accumulation dynamically or from processing output disk file. Would, of course, require binning to a number of bins that is computable but even there the bins could theoretically be maintained in tall array that isn't all in memory at once.
Answers (0)
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!