def subSample(spikeTrains, numCells, totalCells, currentTS, timeWindow):
  """
  Obtains a random sample of cells from the whole spike train matrix consisting of numCells cells
  from the start of simulation time up to currentTS
  
  @param spikeTrains (array) array containing the spike trains of cells in the TM
  @param numCells (int) number of cells to be sampled from the matrix of spike trains
  @param totalCells (int) total number of cells in the TM
  @param currentTS (int) time-step upper bound of sample (sample will go from time-step 0 up to currentTS)
  @param timeWindow (int) number of time-steps to sample from the spike trains
  @return subSpikeTrains (array) spike train matrix sampled from the total spike train matrix
  """
  indices = np.random.permutation(np.arange(totalCells))
  if currentTS > 0 and currentTS < timeWindow:
    subSpikeTrains = np.zeros((numCells, currentTS), dtype = "uint32")
    for i in range(numCells):
      subSpikeTrains[i,:] = spikeTrains[indices[i],:]
  elif currentTS > 0 and currentTS >= timeWindow:
    subSpikeTrains = np.zeros((numCells, timeWindow), dtype = "uint32")    
    for i in range(numCells):
      subSpikeTrains[i,:] = spikeTrains[indices[i],(currentTS-timeWindow):currentTS]
  elif currentTS == 0:
    # This option takes the whole spike train history
    totalTS = np.shape(spikeTrains)[1]
    subSpikeTrains = np.zeros((numCells, totalTS), dtype = "uint32")
    for i in range(numCells):
      subSpikeTrains[i,:] = spikeTrains[indices[i],:]
  elif currentTS < 0:
    # This option takes a timestep at random and a time window 
    # specified by the user after the chosen time step
    totalTS = np.shape(spikeTrains)[1]
    subSpikeTrains = np.zeros((numCells, timeWindow), dtype = "uint32")
    rnd = random.randrange(totalTS - timeWindow)
    print "Starting from timestep: " + str(rnd)
    for i in range(numCells):
      subSpikeTrains[i,:] = spikeTrains[indices[i],rnd:(rnd+timeWindow)]
    
  return subSpikeTrains
Obtains a random sample of cells from the whole spike train matrix consisting of numCells cells
  from the start of simulation time up to currentTS
  
  @param spikeTrains (array) array containing the spike trains of cells in the TM
  @param numCells (int) number of cells to be sampled from the matrix of spike trains
  @param totalCells (int) total number of cells in the TM
  @param currentTS (int) time-step upper bound of sample (sample will go from time-step 0 up to currentTS)
  @param timeWindow (int) number of time-steps to sample from the spike trains
  @return subSpikeTrains (array) spike train matrix sampled from the total spike train matrix