-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
function seq = jp_makesequences(digitList, numSequences, sequenceLength, repeatProbability) | ||
%JP_MAKESEQUENCES Make non-repeating numeric sequences, 1 per row. | ||
% | ||
% NB: Setting repeatProbability to 0 does not mean there is a 0% chance of | ||
% a repeat; it simply turns off the function. I.e., if repeatProbability is | ||
% set to 0, each digit is chosen at random from digitList. | ||
|
||
if nargin < 1 || isempty(digitList) | ||
error('Must specify list of digits (e.g., [2 3 4 5].'); | ||
end | ||
|
||
if nargin < 2 || isempty(numSequences) | ||
numSequences = 5; | ||
end | ||
|
||
if nargin < 3 || isempty(sequenceLength) | ||
sequenceLength = 9; | ||
end | ||
|
||
if nargin < 4 || isempty(repeatProbability) | ||
repeatProbability = 0; | ||
end | ||
|
||
|
||
verbose = 1; | ||
|
||
seq = zeros(numSequences, sequenceLength); | ||
|
||
if verbose > 0 | ||
fprintf('\nGenerating sequences\n\n'); | ||
end | ||
|
||
for seqCounter = 1:numSequences | ||
|
||
if verbose > 0; fprintf('Sequence %04i/%04i...', seqCounter, numSequences); end | ||
|
||
alreadyExists = 1; | ||
|
||
while alreadyExists==1 | ||
|
||
thisSeq = zeros(1, sequenceLength); | ||
|
||
% start with a random digit | ||
thisSeq(1) = digitList(round((rand * (length(digitList)-1))) + 1); | ||
|
||
for digitCounter = 2:sequenceLength | ||
if repeatProbability > 0 | ||
if rand < repeatProbability | ||
thisSeq(digitCounter) = thisSeq(digitCounter-1); | ||
else | ||
thisSeq(digitCounter) = digitList(round((rand * (length(digitList)-1))) + 1); | ||
end | ||
else | ||
thisSeq(digitCounter) = digitList(round((rand * (length(digitList)-1))) + 1); | ||
end | ||
end % going through digits in this sequence | ||
|
||
|
||
|
||
if ~ismember(thisSeq, seq, 'rows') | ||
alreadyExists = 0; | ||
end | ||
|
||
end % checking alreadyExists in while loop | ||
|
||
seq(seqCounter,:) = thisSeq; | ||
|
||
if verbose > 0; fprintf('done.\n'); end | ||
|
||
end % going through numSequences |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
% Relies on jp_makesequences from http://github.com/jpeelle/jp_matlab | ||
|
||
|
||
% Make two sets of patterns, "easy" (higher likelihood of repeating numbers) | ||
% and "hard" (each number in the sequence chosen at random. | ||
|
||
|
||
digitList = [2:5]; | ||
numSequences = 500; | ||
sequenceLength = 9; | ||
repeatProbability = .3; | ||
|
||
|
||
easySequences = jp_makesequences(digitList, numSequences, sequenceLength, repeatProbability); | ||
dlmwrite('~/easySequences.tsv', easySequences, '\t'); | ||
|
||
|
||
repeatProbability = []; | ||
|
||
hardSequences = jp_makesequences(digitList, numSequences, sequenceLength, repeatProbability); | ||
dlmwrite('~/hardSequences.tsv', easySequences, '\t'); | ||
|