Generating 4-coin tosses
Generating 4-coin tosses
Big question up front
Big question up front
Hey Wolfram Community,
I want to generate >10^10 4-coin tosses. E.g. 10B to 1T of these:
I want to generate >10^10 4-coin tosses. E.g. 10B to 1T of these:
In[]:=
Tuples[{0,1},4]
Out[]=
{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},{0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},{1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},{1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}}
Is there any information difference between these two methods?
1) generate tosses using a 4x1 array of 1s & 0s
RandomInteger[1,{numberOfTosses,4}]
2) generate tosses using a random integer, 1 thru 16, each representing on of the 16 possible outcomes of a 4-coin toss
RandomInteger[{1,16},numberOfTosses]
Method #2 is much faster and my old 2013 MBP can generate 1-2 orders of magnitude more data before choking.
Would love your thoughts on this or you can just point me to some useful articles/docs if you're too busy to explain.
Thanks,
David
Thanks,
David
Background
Background
Between the two methods above, #2 is materially faster
In[]:=
numberOfTosses=10000000;AbsoluteTiming[RandomInteger[1,{numberOfTosses,4}];]AbsoluteTiming[RandomInteger[{1,16},numberOfTosses];]
Out[]=
{0.233657,Null}
Out[]=
{0.062318,Null}
I am concerned that #2 encodes less information than #1, but I am out of my depth here and would love to know if that's actually true or if they can be used interchangeably.
a) are they equivalent from an information perspective?
b) if not, is #2 "good enough" for to answer this quiz, but this method shouldn't be used for other inquiries? (i.e. #2 contains the info needed for this quiz but not necessarily other mathy problems)
c) what analyses can I do to figure this out myself?
a) are they equivalent from an information perspective?
b) if not, is #2 "good enough" for to answer this quiz, but this method shouldn't be used for other inquiries? (i.e. #2 contains the info needed for this quiz but not necessarily other mathy problems)
c) what analyses can I do to figure this out myself?
Solving the quiz
Solving the quiz
For anyone that is interested, here is how I solved the quiz (using data generated via method #1)
Generate Data
In[]:=
cointosses=1000000;dataset=RandomInteger[1,{cointosses,4}];
Count the outcomes, filter out the desired outcomes (HHHH vs HHTT), and find the ratio
In[]:=
First[#]/Last[#]&@Values[KeyTake[Counts[dataset],{{0,0,0,0},{0,0,1,1}}]]//N
Out[]=
0.998604
To save on memory/compute time I manually repeat the above until my old Mac chokes on generating dataset and/or the Counts function.