def buildTrainingSet(numSequences = <NUM_LIT:2>,<EOL>sequenceLength = <NUM_LIT:100>,<EOL>pctShared = <NUM_LIT>,<EOL>seqGenMode = '<STR_LIT>',<EOL>subsequenceStartPos = <NUM_LIT:10>,<EOL>numCols = <NUM_LIT:100>,<EOL>minOnes=<NUM_LIT>,<EOL>maxOnes = <NUM_LIT>,<EOL>disjointConsecutive =True):
<EOL>colSet = set(range(numCols))<EOL>if '<STR_LIT>' in seqGenMode:<EOL><INDENT>assert '<STR_LIT>' in seqGenMode and '<STR_LIT>' not in seqGenMode<EOL><DEDENT>if '<STR_LIT>' in seqGenMode or numSequences == <NUM_LIT:1>:<EOL><INDENT>pctShared = <NUM_LIT:0.0><EOL><DEDENT>if '<STR_LIT>' not in seqGenMode and '<STR_LIT>' not in seqGenMode:<EOL><INDENT>sharedSequenceLength = int(pctShared*sequenceLength)<EOL><DEDENT>elif '<STR_LIT>' in seqGenMode:<EOL><INDENT>sharedSequenceLength = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>sharedSequenceLength = <NUM_LIT:0><EOL><DEDENT>assert sharedSequenceLength + subsequenceStartPos < sequenceLength<EOL>sharedSequence = []<EOL>for i in range(sharedSequenceLength):<EOL><INDENT>if disjointConsecutive and i > <NUM_LIT:0>:<EOL><INDENT>x = generatePattern(numCols, minOnes, maxOnes, colSet,<EOL>sharedSequence[i-<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>x = generatePattern(numCols, minOnes, maxOnes, colSet)<EOL><DEDENT>sharedSequence.append(x)<EOL><DEDENT>trainingSequences = []<EOL>if '<STR_LIT>' not in seqGenMode:<EOL><INDENT>trailingLength = sequenceLength - sharedSequenceLength - subsequenceStartPos<EOL><DEDENT>else:<EOL><INDENT>trailingLength = sequenceLength - sharedSequenceLength<EOL><DEDENT>for k,s in enumerate(range(numSequences)):<EOL><INDENT>if len(trainingSequences) > <NUM_LIT:0> and '<STR_LIT>' in seqGenMode:<EOL><INDENT>r = list(range(subsequenceStartPos))+ list(range(subsequenceStartPos + sharedSequenceLength, sequenceLength))<EOL>rgen.shuffle(r)<EOL>r = r[:subsequenceStartPos]+ list(range(subsequenceStartPos, subsequenceStartPos + sharedSequenceLength))+ r[subsequenceStartPos:]<EOL>sequence = [trainingSequences[k-<NUM_LIT:1>][j] for j in r]<EOL><DEDENT>else:<EOL><INDENT>sequence = []<EOL>if '<STR_LIT>' not in seqGenMode:<EOL><INDENT>for i in range(subsequenceStartPos):<EOL><INDENT>if disjointConsecutive and i > <NUM_LIT:0>:<EOL><INDENT>x = generatePattern(numCols, minOnes, maxOnes, colSet, sequence[i-<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>x = generatePattern(numCols, minOnes, maxOnes, colSet)<EOL><DEDENT>sequence.append(x)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in seqGenMode and '<STR_LIT>' not in seqGenMode:<EOL><INDENT>sequence.extend(sharedSequence)<EOL><DEDENT>for i in range(trailingLength):<EOL><INDENT>if disjointConsecutive and i > <NUM_LIT:0>:<EOL><INDENT>x = generatePattern(numCols, minOnes, maxOnes, colSet, sequence[i-<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>x = generatePattern(numCols, minOnes, maxOnes, colSet)<EOL><DEDENT>sequence.append(x)<EOL><DEDENT><DEDENT>assert len(sequence) == sequenceLength<EOL>trainingSequences.append(sequence)<EOL><DEDENT>assert len(trainingSequences) == numSequences<EOL>if VERBOSITY >= <NUM_LIT:2>:<EOL><INDENT>print("<STR_LIT>")<EOL>pprint.pprint(trainingSequences)<EOL><DEDENT>if sharedSequenceLength > <NUM_LIT:0>:<EOL><INDENT>return (trainingSequences, subsequenceStartPos + sharedSequenceLength)<EOL><DEDENT>else:<EOL><INDENT>return (trainingSequences, -<NUM_LIT:1>)<EOL><DEDENT>
Build random high order test sequences.

    Parameters:
    --------------------------------------------
    numSequences:           The number of sequences created.
    sequenceLength:         The length of each sequence.
    pctShared:              The percentage of sequenceLength that is shared across
                            every sequence. If sequenceLength is 100 and pctShared
                            is 0.2, then a subsequence consisting of 20 patterns
                            will be in every sequence. Can also be the keyword
                            'one pattern', in which case a single time step is
                            shared.
    seqGenMode:             What kind of sequence to generate. If contains 'shared'
                            generates shared subsequence. If contains 'no shared',
                            does not generate any shared subsequence. If contains
                            'shuffle', will use common patterns shuffle among the
                            different sequences. If contains 'beginning', will
                            place shared subsequence at the beginning.
    subsequenceStartPos:    The position where the shared subsequence starts
    numCols:                Number of columns in each pattern.
    minOnes:                The minimum number of 1's in each pattern.
    maxOnes:                The maximum number of 1's in each pattern.
    disjointConsecutive:    Whether to generate disjoint consecutive patterns or not.