def populationStability(vectors, numSamples=None):
<EOL>numVectors = len(vectors)<EOL>if numSamples is None:<EOL><INDENT>numSamples = numVectors-<NUM_LIT:1><EOL>countOn = list(range(numVectors-<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>countOn = numpy.random.randint(<NUM_LIT:0>, numVectors-<NUM_LIT:1>, numSamples)<EOL><DEDENT>sigmap = <NUM_LIT:0.0><EOL>for i in countOn:<EOL><INDENT>match = checkMatch(vectors[i], vectors[i+<NUM_LIT:1>], sparse=False)<EOL>if match[<NUM_LIT:1>] != <NUM_LIT:0>:<EOL><INDENT>sigmap += float(match[<NUM_LIT:0>])/match[<NUM_LIT:1>]<EOL><DEDENT><DEDENT>return sigmap / numSamples<EOL>
Returns the stability for the population averaged over multiple time steps

Parameters:
-----------------------------------------------
vectors:          the vectors for which the stability is calculated
numSamples        the number of time steps where stability is counted

At each time step, count the fraction of the active elements which are stable
from the previous step
Average all the fraction