SHARE
TWEET

Untitled

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