def averageOnTimePerTimestep(vectors, numSamples=None):
 if (vectors.ndim == 1):
  vectors.shape = ((-1), 1)
 numTimeSteps = len(vectors)
 numElements = len(vectors[0])
 if (numSamples is not None):
  import pdb
  pdb.set_trace()
  countOn = numpy.random.randint(0, numElements, numSamples)
  vectors = vectors[:, countOn]
 durations = numpy.zeros(vectors.shape, dtype='int32')
 for col in xrange(vectors.shape[1]):
  _fillInOnTimes(vectors[:, col], durations[:, col])
 sums = vectors.sum(axis=1)
 sums.clip(min=1, max=numpy.inf, out=sums)
 avgDurations = (durations.sum(axis=1, dtype='float64') / sums)
 avgOnTime = (avgDurations.sum() / (avgDurations > 0).sum())
 freqCounts = _accumulateFrequencyCounts(avgDurations)
 return (avgOnTime, freqCounts)

def averageOnTimePerTimestep ( vectors , numSamples = None ) : if ( vectors . ndim == 1 ) : vectors . shape = ( ( - 1 ) , 1 ) numTimeSteps = len ( vectors ) numElements = len ( vectors [ 0 ] ) if ( numSamples is not None ) : import pdb pdb . set_trace ( ) countOn = numpy . random . randint ( 0 , numElements , numSamples ) vectors = vectors [ : , countOn ] durations = numpy . zeros ( vectors . shape , dtype = 'int32' ) for col in xrange ( vectors . shape [ 1 ] ) : _fillInOnTimes ( vectors [ : , col ] , durations [ : , col ] ) sums = vectors . sum ( axis = 1 ) sums . clip ( min = 1 , max = numpy . inf , out = sums ) avgDurations = ( durations . sum ( axis = 1 , dtype = 'float64' ) / sums ) avgOnTime = ( avgDurations . sum ( ) / ( avgDurations > 0 ) . sum ( ) ) freqCounts = _accumulateFrequencyCounts ( avgDurations ) return ( avgOnTime , freqCounts )
computes the average on-time of the outputs that are on at each time step .