-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity_generator.py
105 lines (88 loc) · 3.61 KB
/
activity_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
This script reads the connectivity structure and simulates network activity.
"""
import numpy as np
from network_setup import *
import random
def act_gen(L,m,pext,ps,conn_type,T,R=1):
"""function for simulating network activity.
Parameters
-----------
L : int
lattice size as L*L for the 2D model and as L for the 1D model.
m : float
branching parameter.
ps : float
self-excitation probability
conn_type: string
connectivity structure ('local', 'random', 'random_sp2', 'random_sp3', 'random_sp5', 'random_sp7', 'local_1D')
'local' (2D model) and 'local_1D'(1D model) are the same as Moore neighborhood when R = 1.
'random_spR' is 8 randomly selected neighbors within the radius R.
Connectivity types other than 'local' now only work with L = 100 size.
T : int
number of time-steps per each trial
R: int
Connectivity radius (default: R = 1)
Returns
-------
laT : 2d array
network activity as #units * #time-steps
"""
# num_neigh = 1 # this is for having 8 neighnors
num_neigh = R
self_exciteP = 1 # cosidering self-exciation
if conn_type == 'local':
neigh_all = find_allneigh_strongSelf(L,L,num_neigh)
p = [pext, ps, (m-ps)/((2*num_neigh+1)**2-1)]
elif conn_type == 'random':
p = [pext, ps, (m-ps)/((2*num_neigh+1)**2-1)]
neigh_all = np.load('./connectivity_structures/neigh_random_8con_size10000.npy', allow_pickle=True)
elif conn_type == 'random_sp2':
p = [pext, ps, (m-ps)/((2*num_neigh+1)**2-1)]
if num_neigh == 1:
neigh_all = np.load('./connectivity_structures/neigh_randomSpa_8con_size10000_k2.npy', allow_pickle=True)
elif conn_type == 'random_sp3':
p = [pext, ps, (m-ps)/((2*num_neigh+1)**2-1)]
if num_neigh == 1:
neigh_all = np.load('./connectivity_structures/neigh_randomSpa_8con_size10000_k3.npy', allow_pickle=True)
elif conn_type == 'random_sp5':
p = [pext, ps, (m-ps)/((2*num_neigh+1)**2-1)]
if num_neigh == 1:
neigh_all = np.load('./connectivity_structures/neigh_randomSpa_8con_size10000_k5.npy', allow_pickle=True)
elif conn_type == 'random_sp7':
p = [pext, ps, (m-ps)/((2*num_neigh+1)**2-1)]
if num_neigh == 1:
neigh_all = np.load('./connectivity_structures/neigh_randomSpa_8con_size10000_k7.npy', allow_pickle=True)
elif conn_type == 'local_1D':
neigh_all = find_allneigh_strongSelf_1D_uniform(L,num_neigh)
p = [pext, ps, (m-ps)/(2*num_neigh)]
print('probabilities: ',p)
do_break = 0
lattice_activity = []
save_counter = 0
do_break = 0
# set initial condition
if conn_type == 'local_1D':
# for 1D connectivity
average_active = int((pext/(1-m)) * (L))
num_cells = L
else:
# for 2D connectivity
average_active = int((pext/(1-m)) * (L*L))
num_cells = L*L
print('initial cond (#active units): ', str(average_active))
id_initial_active = random.sample(range(num_cells), average_active)
s = np.zeros(num_cells)
s[id_initial_active] = 1
for i in range(T+1):
if do_break:
break
lattice_activity.append(s)
save_counter = save_counter+1
s = np.array([update_network_states(k,L,L,s,p,neigh_all) for k in range(0,len(s))])
if save_counter == T:
do_break = 1
break
avg_fr = np.sum(lattice_activity)/(T)
print('avg_fr: ', avg_fr)
return np.transpose(lattice_activity)