Combinations and memory uses

v = uint16([1 10 11 12 13 14 16 18 21 22 23 24 26 32 35 36 37 39 41 42 44 46 56 57 58 59 62 66 68 69 71 72 73 77 80]);
C = nchoosek(v,uint16(22))
I try this code for combination but use memory in matlab is very huge and take time
Can you help me?

 Risposta accettata

John D'Errico
John D'Errico il 21 Set 2015
Why do people never think about what they wish to do? Computers are not infinite in size, nor are they all powerful except on tv.
v = [1 10 11 12 13 14 16 18 21 22 23 24 26 32 35 36 37 39 41 42 44 46 56 57 58 59 62 66 68 69 71 72 73 77 80];
numel(v)
ans =
35
nchoosek(35,22)
ans =
1.4763e+09
So your call to nchoosek will tell MATLAB to create an array of size: 1.5e9 by 22.
Even as uint16, that matrix will require 2 bytes per element.
1.5e9*22*2
ans =
6.6e+10
So 66 gigabytes of RAM, just to create that matrix. It might take some time to do, even if you have close to that much RAM. Most likely, your disk started swapping like mad.
Computers do have finite capabilities.

2 Commenti

akyanus
akyanus il 21 Set 2015
Thank you John :)
Using the duration functionality we can also tell how long it would take to operate on that data at a rate of one combination processed per second.
years(seconds(nchoosek(35, 22)))
The SECONDS call creates a duration representing a number of seconds, and the YEARS call converts that duration into the equivalent number of exact years.
At a little over 46 3/4 years you might want to rethink your approach, see if you can parallelize your operation, or wait a little while and see if Moore's law continues to hold.

Accedi per commentare.

Più risposte (1)

Jan
Jan il 21 Set 2015
Modificato: Jan il 21 Set 2015

0 voti

If the values of your vector are smaller than 256, you can convert them in the type uint8 and use FEX: vchookek.mex . Matlabs nchoosek used double values, at least in older Matlab versions. Reducing the tapy of the data as far as possible might allow to squeeze the data into your RAM.
There are many other useful submissions in the FileExchange, e.g. FEX:a-fast-nchoosek-alternative-for-engineers-who-like-fast-nchoosek-alternatives

2 Commenti

akyanus
akyanus il 28 Set 2015
I couldn't use this code, because I don't know how call this function Jan
Jan
Jan il 29 Set 2015
See "help vchoosek" for detailed instructions. Either compile the code or download the precomiled file from the provided link. Then call this function exactly as you would call Matlab's nchoosek.

Accedi per commentare.

Categorie

Richiesto:

il 21 Set 2015

Commentato:

Jan
il 29 Set 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by