Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Conduct a cumulative sum-based randomness test that creates a test statistic from the maximum value that a cumulative sums random walk achieves
| ResourceFunction["CUSUMMaxRandomnessTest"][sequence] conducts a cumulative sum-based randomness test on sequence. | |
| ResourceFunction["CUSUMMaxRandomnessTest"][sequence,"properties"] conducts a cumulative sum-based randomness test on sequence and returns the associated property. | 
| "TestStatistic" | returns the test statistic | 
| "PValue" | returns the p-value associated with the test | 
Generate a sequence of random integers:
| In[1]:= | ![sequence = RandomInteger[{0, 1}, 1000];](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/16d34acf5453d611.png) | 
Visualize the sequence:
| In[2]:= | ![ArrayPlot[Partition[sequence, 16]\[Transpose], Sequence[
 ImageSize -> Large, ColorFunction -> "CandyColors"]]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/3d43042660b930db.png) | 
| Out[2]= |  | 
Apply a cumulative sums test:
| In[3]:= | ![ResourceFunction["CUSUMMaxRandomnessTest"][sequence, "TestStatistic"]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/273f52987af08084.png) | 
| Out[3]= |  | 
| In[4]:= | ![ResourceFunction["CUSUMMaxRandomnessTest"][sequence, "PValue"]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/548ccc1090a57128.png) | 
| Out[4]= |  | 
Generate a sequence of integers from a random subsequence:
| In[5]:= | ![subsequence = RandomInteger[{0, 1}, 40];](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/1786c1ae9e918054.png) | 
| In[6]:= | ![sequence = Flatten@Table[subsequence, 20];](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/71c79eac1c3c18f2.png) | 
Visualize the sequence:
| In[7]:= | ![ArrayPlot[Partition[sequence, 16]\[Transpose], Sequence[
 ImageSize -> Large, ColorFunction -> "CandyColors"]]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/05d6eeb44b86011d.png) | 
| Out[7]= |  | 
Apply a cumulative sums test. The small p-value indicates that the sequence is non-random and hence should be rejected:
| In[8]:= | ![ResourceFunction["CUSUMMaxRandomnessTest"][sequence, "TestStatistic"]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/34370dce6ff98834.png) | 
| Out[8]= |  | 
| In[9]:= | ![ResourceFunction["CUSUMMaxRandomnessTest"][sequence, "PValue"]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/5561381a8e40cf02.png) | 
| Out[9]= |  | 
Define and plot rule 30:
| In[10]:= | ![rule30seq = CellularAutomaton[30, {{1}, 0}, {100000, 0}]\[Transpose][[1]];](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/713449a6fa6be66a.png) | 
| In[11]:= | ![ArrayPlot[Partition[Take[rule30seq, 1000], 16]\[Transpose], Sequence[
 ColorFunction -> "CandyColors", ImageSize -> Large]]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/33757192e40307a5.png) | 
| Out[11]= |  | 
Test whether rule 30 is random:
| In[12]:= | ![ResourceFunction["CUSUMMaxRandomnessTest"][rule30seq]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/32c11ad8ed00975a.png) | 
| Out[12]= |  | 
CUSUMMaxRandomnessTest requires sequences of length 100 or more:
| In[13]:= | ![ResourceFunction["CUSUMMaxRandomnessTest"][RandomInteger[{0, 1}, 50]]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/30d6f9d5106c256f.png) | 
Visualize the sampling distribution of the test statistic:
| In[14]:= | ![samp = Table[
   ResourceFunction["CUSUMMaxRandomnessTest"][
    RandomInteger[{0, 1}, 1000], "TestStatistic"], 1000];](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/3d7fc9461a076130.png) | 
| In[15]:= | ![Histogram[samp, Automatic, "PDF"]](https://www.wolframcloud.com/obj/resourcesystem/images/38f/38f4db36-2e67-469e-b81d-26237ea597f5/64374b647f73bfa9.png) | 
| Out[15]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License