Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.00 KB | None | 0 0
  1. import os
  2. import nest
  3. from time import time
  4. from multiprocessing import cpu_count
  5. from NEST.functions import Functions
  6. from NEST.functions import Parameters
  7. from GRAS.tests_runner import convert_to_hdf5, plot_results
  8.  
  9.  
  10. class V3(Functions):
  11. def __init__(self, parameters, iteration):
  12. """
  13. ToDo add info
  14. Args:
  15. parameters (Parameters):
  16. iteration (int):
  17. """
  18. nest.ResetKernel()
  19. nest.SetKernelStatus({'data_path': "dat",
  20. 'print_time': True,
  21. 'resolution': 0.025,
  22. 'overwrite_files': True,
  23. 'data_prefix': f"{iteration}_",
  24. 'total_num_virtual_procs': cpu_count(),
  25. 'rng_seeds': [int(time() * 10000 % 10000)] * cpu_count()})
  26.  
  27. super().__init__(parameters)
  28. self.P = parameters
  29.  
  30. self.init_network()
  31. self.simulate()
  32. self.resave()
  33.  
  34. def init_network(self):
  35. """
  36. TODO add info
  37. """
  38. inh_coef = 1
  39. quadru_coef = 0.5 if self.P.ped == 4 else 1
  40. sero_coef = 5.3 if self.P.ht5 else 1
  41.  
  42. syn_outdegree = 27 # synapse number outgoing from one neuron
  43. neurons_in_ip = 196 # number of neurons in interneuronal pool
  44. neurons_in_moto = 169 # motoneurons number
  45. neurons_in_group = 20 # number of neurons in a group
  46. neurons_in_aff_ip = 196 # number of neurons in interneuronal pool
  47. neurons_in_afferent = 120 # number of neurons in afferent
  48.  
  49. # groups of neurons
  50. EES = self.form_group("EES")
  51. E1 = self.form_group("E1")
  52. E2 = self.form_group("E2")
  53. E3 = self.form_group("E3")
  54. E4 = self.form_group("E4")
  55. E5 = self.form_group("E5")
  56.  
  57. CV1 = self.form_group("CV1", 40)
  58. CV2 = self.form_group("CV2", 40)
  59. CV3 = self.form_group("CV3", 40)
  60. CV4 = self.form_group("CV4", 40)
  61. CV5 = self.form_group("CV5", 40)
  62. CD4 = self.form_group("CD4", 40)
  63. CD5 = self.form_group("CD5", 40)
  64.  
  65. OM1_0 = self.form_group("OM1_0")
  66. OM1_1 = self.form_group("OM1_1")
  67. OM1_2_E = self.form_group("OM1_2_E")
  68. OM1_2_F = self.form_group("OM1_2_F")
  69. OM1_3 = self.form_group("OM1_3")
  70.  
  71. OM2_0 = self.form_group("OM2_0")
  72. OM2_1 = self.form_group("OM2_1")
  73. OM2_2_E = self.form_group("OM2_2_E")
  74. OM2_2_F = self.form_group("OM2_2_F")
  75. OM2_3 = self.form_group("OM2_3")
  76.  
  77. OM3_0 = self.form_group("OM3_0")
  78. OM3_1 = self.form_group("OM3_1")
  79. OM3_2_E = self.form_group("OM3_2_E")
  80. OM3_2_F = self.form_group("OM3_2_F")
  81. OM3_3 = self.form_group("OM3_3")
  82.  
  83. OM4_0 = self.form_group("OM4_0")
  84. OM4_1 = self.form_group("OM4_1")
  85. OM4_2_E = self.form_group("OM4_2_E")
  86. OM4_2_F = self.form_group("OM4_2_F")
  87. OM4_3 = self.form_group("OM4_3")
  88.  
  89. OM5_0 = self.form_group("OM5_0")
  90. OM5_1 = self.form_group("OM5_1")
  91. OM5_2_E = self.form_group("OM5_2_E")
  92. OM5_2_F = self.form_group("OM5_2_F")
  93. OM5_3 = self.form_group("OM5_3")
  94.  
  95. MN_E = self.form_group("MN_E", neurons_in_moto)
  96. MN_F = self.form_group("MN_F", neurons_in_moto)
  97.  
  98. Ia_E_aff = self.form_group("Ia_E_aff", neurons_in_afferent)
  99. Ia_F_aff = self.form_group("Ia_F_aff", neurons_in_afferent)
  100.  
  101. R_E = self.form_group("R_E")
  102. R_F = self.form_group("R_F")
  103.  
  104. Ia_E_pool = self.form_group("Ia_E_pool", neurons_in_aff_ip)
  105. Ia_F_pool = self.form_group("Ia_F_pool", neurons_in_aff_ip)
  106.  
  107. eIP_E = self.form_group("eIP_E", neurons_in_ip)
  108. eIP_F = self.form_group("eIP_F", neurons_in_ip)
  109.  
  110. iIP_E = self.form_group("iIP_E", neurons_in_ip)
  111. iIP_F = self.form_group("iIP_F", neurons_in_ip)
  112.  
  113. self.connect_spike_generator(EES, rate=self.P.EES)
  114. self.connect_noise_generator(CV1, rate=5000, t_end=self.P.skin_stim - 2)
  115. self.connect_noise_generator(CV2, rate=5000, t_start=self.P.skin_stim, t_end=2 * self.P.skin_stim - 2)
  116. self.connect_noise_generator(CV3, rate=5000, t_start=2 * self.P.skin_stim, t_end=3 * self.P.skin_stim - 2)
  117. self.connect_noise_generator(CV4, rate=5000, t_start=3 * self.P.skin_stim, t_end=5 * self.P.skin_stim - 2)
  118. self.connect_noise_generator(CV5, rate=5000, t_start=5 * self.P.skin_stim, t_end=6 * self.P.skin_stim - 2)
  119. self.connect_noise_generator(iIP_F, rate=3000, t_start=6 * self.P.skin_stim, t_end=11 * self.P.skin_stim - 5)
  120.  
  121. # connectomes
  122. self.connect_fixed_outdegree(EES, E1, 1, 370, no_distr=True)
  123. self.connect_fixed_outdegree(E1, E2, 1, 80, no_distr=True)
  124. self.connect_fixed_outdegree(E2, E3, 1, 80, no_distr=True)
  125. self.connect_fixed_outdegree(E3, E4, 1, 80, no_distr=True)
  126. self.connect_fixed_outdegree(E4, E5, 1, 80, no_distr=True)
  127.  
  128. self.connect_one_to_all(CV1, iIP_E, 0.5, 20)
  129. self.connect_one_to_all(CV2, iIP_E, 0.5, 20)
  130. self.connect_one_to_all(CV3, iIP_E, 0.5, 20)
  131. self.connect_one_to_all(CV4, iIP_E, 0.5, 20)
  132. self.connect_one_to_all(CV5, iIP_E, 0.5, 20)
  133.  
  134. #########################################################################
  135. #########################################################################
  136. #
  137. #
  138. self.connect_fixed_outdegree(OM1_2_E, eIP_E, 1, 14.4, neurons_in_ip) # 1, 14.4
  139. self.connect_fixed_outdegree(OM2_2_E, eIP_E, 1.75, 7.9, neurons_in_ip) # 1.75, 7.9
  140. self.connect_fixed_outdegree(OM3_2_E, eIP_E, 1.5, 7.35, neurons_in_ip) # 1.85, 7.35
  141. self.connect_fixed_outdegree(OM4_2_E, eIP_E, 3, 9.65, neurons_in_ip)
  142. self.connect_fixed_outdegree(OM5_2_E, eIP_E, 3.5, 7.2, neurons_in_ip)
  143. #
  144. self.connect_fixed_outdegree(eIP_E, MN_E, 2.5, 3, neurons_in_moto)
  145. #
  146. self.connect_fixed_outdegree(MN_E, R_E, 0.7, 0)
  147. self.connect_fixed_outdegree(R_E, MN_E, 0.7, 0, neurons_in_moto)
  148. #
  149. #########################################################################
  150. #
  151. self.connect_fixed_outdegree(OM1_2_F, eIP_F, 1, 0.5, neurons_in_ip)
  152. self.connect_fixed_outdegree(OM2_2_F, eIP_F, 1, 5, neurons_in_ip)
  153. self.connect_fixed_outdegree(OM3_2_F, eIP_F, 1, 7, neurons_in_ip)
  154. self.connect_fixed_outdegree(OM4_2_F, eIP_F, 1, 7, neurons_in_ip)
  155. self.connect_fixed_outdegree(OM5_2_F, eIP_F, 1, 7, neurons_in_ip)
  156. #
  157. self.connect_fixed_outdegree(eIP_F, MN_F, 1, 50, neurons_in_moto)
  158. #
  159. self.connect_fixed_outdegree(MN_F, R_F, 0.5, 6)
  160. self.connect_fixed_outdegree(R_F, MN_F, 2, 0, neurons_in_moto)
  161. #
  162. self.connect_fixed_outdegree(Ia_F_aff, MN_F, 2, 22, neurons_in_moto)
  163. self.connect_fixed_outdegree(Ia_E_pool, MN_F, 1, -50, neurons_in_ip)
  164. #
  165. #
  166. ##########################################################################
  167. ##########################################################################
  168.  
  169. # OM 1
  170. # input from EES group 1
  171. self.connect_fixed_outdegree(E1, OM1_0, 1, 20)
  172. # input from sensory
  173. self.connect_one_to_all(CV1, OM1_0, 0.5, 2 * quadru_coef * sero_coef)
  174. self.connect_one_to_all(CV2, OM1_0, 0.5, 2 * quadru_coef * sero_coef)
  175. # [inhibition]
  176. self.connect_one_to_all(CV3, OM1_3, 1, 80)
  177. self.connect_one_to_all(CV4, OM1_3, 1, 80)
  178. self.connect_one_to_all(CV5, OM1_3, 1, 80)
  179. # inner connectomes
  180. self.connect_fixed_outdegree(OM1_0, OM1_1, 1, 30)
  181. self.connect_fixed_outdegree(OM1_1, OM1_2_E, 1, 24)
  182. self.connect_fixed_outdegree(OM1_1, OM1_2_F, 0.4, 22)
  183. self.connect_fixed_outdegree(OM1_1, OM1_3, 3.5, 4)
  184. self.connect_fixed_outdegree(OM1_2_E, OM1_1, 2.5, 20)
  185. self.connect_fixed_outdegree(OM1_2_F, OM1_1, 2.5, 22)
  186. self.connect_fixed_outdegree(OM1_2_E, OM1_3, 1, 2)
  187. self.connect_fixed_outdegree(OM1_2_F, OM1_3, 0.4, 15.5)
  188. self.connect_fixed_outdegree(OM1_3, OM1_1, 1.5, -3 * inh_coef)
  189. self.connect_fixed_outdegree(OM1_3, OM1_2_E, 0.4, -60 * inh_coef)
  190. self.connect_fixed_outdegree(OM1_3, OM1_2_F, 1, -1 * inh_coef)
  191. # output to OM2
  192. self.connect_fixed_outdegree(OM1_2_F, OM2_2_F, 1, 50)
  193. # # output to IP
  194. #
  195. # OM 2
  196. # input from EES group 2
  197. self.connect_fixed_outdegree(E2, OM2_0, 1, 7)
  198. # input from sensory [CV]
  199. self.connect_one_to_all(CV2, OM2_0, 0.5, 2 * quadru_coef * sero_coef)
  200. self.connect_one_to_all(CV3, OM2_0, 0.5, 2 * quadru_coef * sero_coef)
  201. # [inhibition]
  202. self.connect_one_to_all(CV4, OM2_3, 1, 80)
  203. self.connect_one_to_all(CV5, OM2_3, 1, 80)
  204. # # inner connectomes
  205. self.connect_fixed_outdegree(OM2_0, OM2_1, 1, 30)
  206. self.connect_fixed_outdegree(OM2_1, OM2_2_E, 1, 24)
  207. self.connect_fixed_outdegree(OM2_1, OM2_2_F, 0.4, 25)
  208. self.connect_fixed_outdegree(OM2_1, OM2_3, 3.5, 4)
  209. self.connect_fixed_outdegree(OM2_2_E, OM2_1, 2.5, 20)
  210. self.connect_fixed_outdegree(OM2_2_F, OM2_1, 2.5, 25)
  211. self.connect_fixed_outdegree(OM2_2_E, OM2_3, 1, 2)
  212. self.connect_fixed_outdegree(OM2_2_F, OM2_3, 0.4, 15.5)
  213. self.connect_fixed_outdegree(OM2_3, OM2_1, 1.5, -3 * inh_coef)
  214. self.connect_fixed_outdegree(OM2_3, OM2_2_E, 0.4, -60 * inh_coef)
  215. self.connect_fixed_outdegree(OM2_3, OM2_2_F, 1, -1 * inh_coef)
  216. # output to OM3
  217. self.connect_fixed_outdegree(OM2_2_F, OM3_2_F, 1, 50)
  218. # output to IP
  219.  
  220. # OM 3
  221. # input from EES group 3
  222. self.connect_fixed_outdegree(E3, OM3_0, 1, 7)
  223. # input from sensory [CV]
  224. self.connect_one_to_all(CV3, OM3_0, 0.5, 2 * quadru_coef * sero_coef)
  225. self.connect_one_to_all(CV4, OM3_0, 0.5, 2 * quadru_coef * sero_coef)
  226. # [inhibition]
  227. self.connect_one_to_all(CV5, OM3_3, 1, 80)
  228. # input from sensory [CD]
  229. self.connect_one_to_all(CD4, OM3_0, 1, 11)
  230. # inner connectomes
  231. self.connect_fixed_outdegree(OM3_0, OM3_1, 1, 30)
  232. self.connect_fixed_outdegree(OM3_1, OM3_2_E, 1, 24)
  233. self.connect_fixed_outdegree(OM3_1, OM3_2_F, 0.4, 25)
  234. self.connect_fixed_outdegree(OM3_1, OM3_3, 3.5, 4)
  235. self.connect_fixed_outdegree(OM3_2_E, OM3_1, 2.5, 20)
  236. self.connect_fixed_outdegree(OM3_2_F, OM3_1, 2.5, 25)
  237. self.connect_fixed_outdegree(OM3_2_E, OM3_3, 1, 2)
  238. self.connect_fixed_outdegree(OM3_2_F, OM3_3, 0.4, 15.5)
  239. self.connect_fixed_outdegree(OM3_3, OM3_1, 1.5, -3 * inh_coef)
  240. self.connect_fixed_outdegree(OM3_3, OM3_2_E, 0.4, -60 * inh_coef)
  241. self.connect_fixed_outdegree(OM3_3, OM3_2_F, 1, -1 * inh_coef)
  242. # output to OM3
  243. self.connect_fixed_outdegree(OM3_2_F, OM4_2_F, 1, 50)
  244. # output to IP
  245.  
  246. # OM 4
  247. # input from EES group 4
  248. self.connect_fixed_outdegree(E4, OM4_0, 1, 7)
  249. # input from sensory [CV]
  250. self.connect_one_to_all(CV4, OM4_0, 0.5, 2 * quadru_coef * sero_coef)
  251. self.connect_one_to_all(CV5, OM4_0, 0.5, 2 * quadru_coef * sero_coef)
  252. # input from sensory [CD]
  253. self.connect_one_to_all(CD4, OM4_0, 1, 11)
  254. self.connect_one_to_all(CD5, OM4_0, 1, 11)
  255. # inner connectomes
  256. self.connect_fixed_outdegree(OM4_0, OM4_1, 1, 30)
  257. self.connect_fixed_outdegree(OM4_1, OM4_2_E, 1, 23)
  258. self.connect_fixed_outdegree(OM4_1, OM4_2_F, 0.4, 25)
  259. self.connect_fixed_outdegree(OM4_1, OM4_3, 3.5, 4)
  260. self.connect_fixed_outdegree(OM4_2_E, OM4_1, 2.5, 18)
  261. self.connect_fixed_outdegree(OM4_2_F, OM4_1, 2.5, 25)
  262. self.connect_fixed_outdegree(OM4_2_E, OM4_3, 1, 2)
  263. self.connect_fixed_outdegree(OM4_2_F, OM4_3, 0.4, 15.5)
  264. self.connect_fixed_outdegree(OM4_3, OM4_1, 1.5, -3 * inh_coef)
  265. self.connect_fixed_outdegree(OM4_3, OM4_2_E, 0.4, -60 * inh_coef)
  266. self.connect_fixed_outdegree(OM4_3, OM4_2_F, 1, -1 * inh_coef)
  267. # output to OM4
  268. self.connect_fixed_outdegree(OM4_2_F, OM5_2_F, 1, 50)
  269. # output to IP
  270.  
  271. # OM 5
  272. # input from EES group 5
  273. self.connect_fixed_outdegree(E5, OM5_0, 1, 7)
  274. # input from sensory [CV]
  275. self.connect_one_to_all(CV5, OM5_0, 0.5, 2 * quadru_coef * sero_coef)
  276. # input from sensory [CD]
  277. self.connect_one_to_all(CD5, OM5_0, 1, 11)
  278. # inner connectomes
  279. self.connect_fixed_outdegree(OM5_0, OM5_1, 1, 30)
  280. self.connect_fixed_outdegree(OM5_1, OM5_2_E, 1, 24)
  281. self.connect_fixed_outdegree(OM5_1, OM5_2_F, 0.4, 25)
  282. self.connect_fixed_outdegree(OM5_1, OM5_3, 3.5, 4)
  283. self.connect_fixed_outdegree(OM5_2_E, OM5_1, 2.5, 20)
  284. self.connect_fixed_outdegree(OM5_2_F, OM5_1, 2.5, 25)
  285. self.connect_fixed_outdegree(OM5_2_E, OM5_3, 1, 2)
  286. self.connect_fixed_outdegree(OM5_2_F, OM5_3, 0.4, 15.5)
  287. self.connect_fixed_outdegree(OM5_3, OM5_1, 1.5, -2 * inh_coef)
  288. self.connect_fixed_outdegree(OM5_3, OM5_2_E, 0.4, -40 * inh_coef)
  289. self.connect_fixed_outdegree(OM5_3, OM5_2_F, 1, -1 * inh_coef)
  290. # output to IP
  291.  
  292. # reflex arc
  293. self.connect_fixed_outdegree(iIP_E, eIP_F, 0.5, -5, neurons_in_ip)
  294. self.connect_fixed_outdegree(iIP_F, eIP_E, 0.5, -40, neurons_in_ip)
  295.  
  296. self.connect_fixed_outdegree(iIP_E, OM1_2_F, 0.5, -1, neurons_in_ip)
  297. self.connect_fixed_outdegree(iIP_E, OM2_2_F, 0.5, -1, neurons_in_ip)
  298. self.connect_fixed_outdegree(iIP_E, OM3_2_F, 0.5, -1, neurons_in_ip)
  299. self.connect_fixed_outdegree(iIP_E, OM4_2_F, 0.5, -1, neurons_in_ip)
  300.  
  301. self.connect_fixed_outdegree(EES, Ia_E_aff, 1, 500)
  302. self.connect_fixed_outdegree(EES, Ia_F_aff, 1, 500)
  303.  
  304.  
  305. self.connect_fixed_outdegree(iIP_E, Ia_E_pool, 1, 30, neurons_in_ip)
  306. self.connect_fixed_outdegree(iIP_F, Ia_F_pool, 1, 30, neurons_in_ip)
  307.  
  308. self.connect_fixed_outdegree(Ia_E_pool, Ia_F_pool, 1, -1, neurons_in_ip)
  309. self.connect_fixed_outdegree(Ia_F_pool, MN_E, 1, -10, neurons_in_ip)
  310. self.connect_fixed_outdegree(Ia_F_pool, Ia_E_pool, 1, -1, neurons_in_ip)
  311.  
  312. self.connect_fixed_outdegree(Ia_E_aff, MN_E, 2, 30, neurons_in_moto)
  313.  
  314.  
  315. self.connect_fixed_outdegree(R_E, R_F, 2, -1)
  316.  
  317. self.connect_fixed_outdegree(R_F, R_E, 2, -1)
  318.  
  319.  
  320. if __name__ == "__main__":
  321. parameters = Parameters()
  322. parameters.tests = 1
  323. parameters.steps = 1
  324. parameters.cms = 21
  325. parameters.EES = 40
  326. parameters.inh = 100
  327. parameters.ped = 2
  328. parameters.ht5 = False
  329. parameters.save_all = True
  330.  
  331. save_folder = f"{os.getcwd()}/dat"
  332.  
  333. for i in range(parameters.tests):
  334. try:
  335. V3(parameters, iteration=i)
  336. except Exception as error:
  337. print(error)
  338.  
  339. convert_to_hdf5(save_folder)
  340. plot_results(save_folder, ees_hz=parameters.EES)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement