# function below extracts co-activation patterns (assemblies)
'''
INPUTS
actmat: activity matrix - numpy array (neurons, time bins)
nullhyp: defines how to generate statistical threshold for assembly detection.
'bin' - bin shuffling, will shuffle time bins of each neuron independently
'circ' - circular shuffling, will shift time bins of each neuron independently
obs: mantains (virtually) autocorrelations
'mp' - Marcenko-Pastur distribution - analytical threshold
nshu: defines how many shuffling controls will be done (n/a if nullhyp is 'mp')
percentile: defines which percentile to be used use when shuffling methods are employed.
(n/a if nullhyp is 'mp')
tracywidow: determines if Tracy-Widom is used. See Peyrache et al 2010.
(n/a if nullhyp is NOT 'mp')
OUTPUTS
patterns: co-activation patterns (assemblies) - numpy array (assemblies, neurons)
significance: object containing general information about significance tests
zactmat: returns z-scored actmat
'''
# using Marcenko-Pastur function as null distribution
t0 = time.time()
patterns,significance,zactmat = assembly.runPatterns(actmat,nullhyp='mp')
tf = np.round(1000*(time.time()-t0))/1000
plt.figure(figsize=(15,5))
for (pi,pattern) in enumerate(patterns):
plt.subplot(1,len(patterns),1+pi)
plt.stem(pattern)
plt.xlabel('neuron #')
plt.ylabel('weight')
plt.suptitle('Using MP distribution, elapsed time: '+str(tf)+' seconds')
# using simple bin shuffling for computing null distribution
nshu = 1000 # defines number of controls to run (i.e., number of elements in null hypothesis distribution)
percentile = 99.5 # defines which percentile of control distribution will be used as significance threshold
t0 = time.time()
patterns,significance,zactmat = assembly.runPatterns(actmat,nullhyp='bin',nshu=nshu,percentile=percentile)
tf = np.round(1000*(time.time()-t0))/1000
plt.figure(figsize=(15,5))
for (pi,pattern) in enumerate(patterns):
plt.subplot(1,len(patterns),1+pi)
plt.stem(pattern)
plt.xlabel('neuron #')
plt.ylabel('weight')
plt.suptitle('Using bin shuffling, elapsed time: '+str(tf)+' seconds')
# using circular shuffling for computing null distribution (MUST USE IT IF YOU HAVE STRONG AUTOCORRELATIONS)
nshu = 1000 # defines number of controls to run (i.e., number of elements in null hypothesis distribution)
percentile = 99.5 # defines which percentile of control distribution will be used as significance threshold
t0 = time.time()
patterns,significance,zactmat = assembly.runPatterns(actmat,nullhyp='circ',nshu=nshu,percentile=percentile)
tf = np.round(1000*(time.time()-t0))/1000
plt.figure(figsize=(15,5))
for (pi,pattern) in enumerate(patterns):
plt.subplot(1,len(patterns),1+pi)
plt.stem(pattern)
plt.xlabel('neuron #')
plt.ylabel('weight')
plt.suptitle('Using circular shuffling, elapsed time: '+str(tf)+' seconds')