diff --git a/analysis/__pycache__/firing_rate_analysis.cpython-39.pyc b/analysis/__pycache__/firing_rate_analysis.cpython-39.pyc deleted file mode 100644 index a34bcef..0000000 Binary files a/analysis/__pycache__/firing_rate_analysis.cpython-39.pyc and /dev/null differ diff --git a/analysis/__pycache__/mydata.cpython-39.pyc b/analysis/__pycache__/mydata.cpython-39.pyc deleted file mode 100644 index a72036f..0000000 Binary files a/analysis/__pycache__/mydata.cpython-39.pyc and /dev/null differ diff --git a/connection/__pycache__/__init__.cpython-39.pyc b/connection/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 7710cc6..0000000 Binary files a/connection/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/connection/__pycache__/connect_2lattice.cpython-39.pyc b/connection/__pycache__/connect_2lattice.cpython-39.pyc deleted file mode 100644 index a2f34d3..0000000 Binary files a/connection/__pycache__/connect_2lattice.cpython-39.pyc and /dev/null differ diff --git a/connection/__pycache__/coordination.cpython-39.pyc b/connection/__pycache__/coordination.cpython-39.pyc deleted file mode 100644 index 5ea3310..0000000 Binary files a/connection/__pycache__/coordination.cpython-39.pyc and /dev/null differ diff --git a/connection/__pycache__/findnearbyneuron.cpython-39.pyc b/connection/__pycache__/findnearbyneuron.cpython-39.pyc deleted file mode 100644 index 8d8e77e..0000000 Binary files a/connection/__pycache__/findnearbyneuron.cpython-39.pyc and /dev/null differ diff --git a/connection/__pycache__/model_neu_syn_AD.cpython-39.pyc b/connection/__pycache__/model_neu_syn_AD.cpython-39.pyc deleted file mode 100644 index e6c2e3a..0000000 Binary files a/connection/__pycache__/model_neu_syn_AD.cpython-39.pyc and /dev/null differ diff --git a/connection/__pycache__/model_neu_syn_YG.cpython-39.pyc b/connection/__pycache__/model_neu_syn_YG.cpython-39.pyc deleted file mode 100644 index 407edaf..0000000 Binary files a/connection/__pycache__/model_neu_syn_YG.cpython-39.pyc and /dev/null differ diff --git a/connection/test/expo_connection.py b/connection/test/expo_connection.py deleted file mode 100644 index 11977b7..0000000 --- a/connection/test/expo_connection.py +++ /dev/null @@ -1,525 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Fri Sep 4 12:58:31 2020 - -@author: shni2598 -""" - -import numpy as np -#import brian2.numpy_ as np -#import matplotlib.pyplot as plt -import connection as cn -import warnings -from scipy import sparse -#from brian2.only import * -#import time -#import mydata -#import firing_rate_analysis -#import os -#import datetime -#%% -class get_ijwd: - - def __init__(self, *param_dict, **kwargs): - - self.Ne = 3969 - self.Ni = 1024 - self.width = 62 - self.decay_p_ee = 8 # decay constant of e to e connection probability as distance increases - self.decay_p_ei = 10 # decay constant of e to i connection probability as distance increases - self.decay_p_ie = 20 # decay constant of i to e connection probability as distance increases - self.decay_p_ii = 20 # decay constant of i to i connection probability as distance increases - self.mean_SynNumIn_ee = 320 ; # p = 0.08 - self.mean_SynNumIn_ei = 500 ; # p = 0.125 - self.mean_SynNumIn_ie = 200 ; # p = 0.2 - self.mean_SynNumIn_ii = 250 ; # p = 0.25 - self.w_ee_mean = 4 - self.w_ei_mean = 5 - self.w_ie_mean = 20 - self.w_ii_mean = 25 - self.delay = 4 - for dictionary in param_dict: - for key in dictionary: - setattr(self, key, dictionary[key]) - for key in kwargs: - setattr(self, key, kwargs[key]) - # if either param_dict or kwargs is not empty, reset some parameters which are dependent on other parameters - if bool(param_dict) or bool(kwargs): self.change_dependent_para() - - def change_dependent_para(self): - pass - - def generate_ijw(self): - - self.e_lattice = cn.coordination.makelattice(int(round(np.sqrt(self.Ne))), self.width, [0,0]) - self.i_lattice = cn.coordination.makelattice(int(round(np.sqrt(self.Ni))), self.width, [0,0]) - - self.p_peak_ee = self.find_peak_probability(self.mean_SynNumIn_ee, self.decay_p_ee, self.e_lattice, self.width, position=[0,0]) - self.p_peak_ei = self.find_peak_probability(self.mean_SynNumIn_ei, self.decay_p_ei, self.e_lattice, self.width, position=[0,0]) - self.p_peak_ie = self.find_peak_probability(self.mean_SynNumIn_ie, self.decay_p_ie, self.i_lattice, self.width, position=[0,0]) - self.p_peak_ii = self.find_peak_probability(self.mean_SynNumIn_ii, self.decay_p_ii, self.i_lattice, self.width, position=[0,0]) - - self.i_ee, self.j_ee, _ = cn.connect_2lattice.expo_decay(self.e_lattice, self.e_lattice, np.arange(self.Ne), self.width, periodic_boundary=True, interarea_dist=0, \ - peak_p=self.p_peak_ee, tau_d=self.decay_p_ee, src_equal_trg = True, self_cnt = False) - - self.i_ei, self.j_ei, _ = cn.connect_2lattice.expo_decay(self.e_lattice, self.i_lattice, np.arange(self.Ne), self.width, periodic_boundary=True, interarea_dist=0, \ - peak_p=self.p_peak_ei, tau_d=self.decay_p_ei, src_equal_trg = False, self_cnt = False) - - self.i_ie, self.j_ie, _ = cn.connect_2lattice.expo_decay(self.i_lattice, self.e_lattice, np.arange(self.Ni), self.width, periodic_boundary=True, interarea_dist=0, \ - peak_p=self.p_peak_ie, tau_d=self.decay_p_ie, src_equal_trg = False, self_cnt = False) - - self.i_ii, self.j_ii, _ = cn.connect_2lattice.expo_decay(self.i_lattice, self.i_lattice, np.arange(self.Ni), self.width, periodic_boundary=True, interarea_dist=0, \ - peak_p=self.p_peak_ii, tau_d=self.decay_p_ii, src_equal_trg = True, self_cnt = False) - - self.num_in_ee = self.find_indegree(self.i_ee, self.j_ee, self.Ne, self.Ne) - self.num_in_ei = self.find_indegree(self.i_ei, self.j_ei, self.Ne, self.Ni) - self.num_in_ie = self.find_indegree(self.i_ie, self.j_ie, self.Ni, self.Ne) - self.num_in_ii = self.find_indegree(self.i_ii, self.j_ii, self.Ni, self.Ni) - - self.J_ee = self.find_J(self.num_in_ee, self.w_ee_mean) - self.J_ei = self.find_J(self.num_in_ei, self.w_ei_mean) - self.J_ie = self.find_J(self.num_in_ie, self.w_ie_mean) - self.J_ii = self.find_J(self.num_in_ii, self.w_ii_mean) - - self.w_ee = self.find_synWeight(self.j_ee, self.J_ee, self.Ne, self.num_in_ee) - self.w_ei = self.find_synWeight(self.j_ei, self.J_ei, self.Ni, self.num_in_ei) - self.w_ie = self.find_synWeight(self.j_ie, self.J_ie, self.Ne, self.num_in_ie) - self.w_ii = self.find_synWeight(self.j_ii, self.J_ii, self.Ni, self.num_in_ii) - - def generate_d_rand(self): - - self.d_ee = np.random.uniform(0, self.delay, len(self.i_ee)) - self.d_ie = np.random.uniform(0, self.delay, len(self.i_ie)) - self.d_ei = np.random.uniform(0, self.delay, len(self.i_ei)) - self.d_ii = np.random.uniform(0, self.delay, len(self.i_ii)) - - def find_peak_probability(self, mean_SynNum, tau_d, lattice, width, position=[0,0]): - - dist = cn.coordination.lattice_dist(lattice, width, position) - p_peak = mean_SynNum/(np.sum(np.exp(-dist/tau_d))) - if p_peak > 1: - warnings.warn(" Error: peak connection probability exceeds '1', adjust 'decay_p' or 'mean_SynSum' to reduce it below '1'" ) - - return p_peak - - def find_indegree(self, i, j, N_src, N_trg): - - A = sparse.csc_matrix((np.ones(i.shape, dtype=int), (i, j)),shape=(N_src,N_trg)) - num_in = A.sum(0) - return num_in.A[0] - - def find_J(self, num_in, J_mean): - J = J_mean*np.sum(num_in)/(np.sum(np.sqrt(num_in))) - return J - - def find_synWeight(self, j_cnt, J_weight, N_trg, num_indegree): - - w_cnt = np.zeros(j_cnt.shape) - for j in range(N_trg): - J_mean = J_weight/np.sqrt(num_indegree[j]) - J_std = J_mean/4 - w_tmp = np.random.randn(num_indegree[j])*J_std + J_mean - negative_w = np.any(w_tmp <= 0) - while negative_w: - #w_tmp = np.random.randn(num_indegree[j])*J_std + J_mean - w_tmp[w_tmp <= 0] = np.random.randn(np.sum(w_tmp <= 0))*J_std + J_mean - negative_w = np.any(w_tmp <= 0) - - w_cnt[j_cnt == j] = w_tmp - - return w_cnt -#%% -""" -def find_peak_probability(mean_SynNum, tau_d, lattice, width, position=[0,0]): - - dist = cn.coordination.lattice_dist(lattice, width, position) - p_peak = mean_SynNum/(np.sum(np.exp(-dist/tau_d))) - if p_peak > 1: - warnings.warn(" Error: peak connection probability exceeds '1', adjust 'tau_d' or 'mean_SynSum' to reduce it below '1'" ) - - return p_peak - -#%% -e_lattice = cn.coordination.makelattice(63, 62, [0,0]) -i_lattice = cn.coordination.makelattice(32, 62, [0,0]) -#%% -tau_d_ee = 8 ;tau_d_ei = 10 ;tau_d_ie = 20 ;tau_d_ii = 20 ; -mean_SynNum_ee = 320 ;mean_SynNum_ei = 500 ;mean_SynNum_ie = 200 ;mean_SynNum_ii = 250 ; - -width = 62 -#%% - -p_peak_ee = find_peak_probability(mean_SynNum_ee, tau_d_ee, e_lattice, width, position=[0,0]) -p_peak_ei = find_peak_probability(mean_SynNum_ei, tau_d_ei, e_lattice, width, position=[0,0]) -p_peak_ie = find_peak_probability(mean_SynNum_ie, tau_d_ie, i_lattice, width, position=[0,0]) -p_peak_ii = find_peak_probability(mean_SynNum_ii, tau_d_ii, i_lattice, width, position=[0,0]) -#%% -Ne = 3969; -Ni = 1024; -i_ee, j_ee, _ = cn.connect_2lattice.expo_decay(e_lattice, e_lattice, np.arange(Ne), 62, periodic_boundary=True, interarea_dist=0, \ - peak_p=p_peak_ee, tau_d=tau_d_ee, src_equal_trg = True, self_cnt = False) - -i_ei, j_ei, _ = cn.connect_2lattice.expo_decay(e_lattice, i_lattice, np.arange(Ne), 62, periodic_boundary=True, interarea_dist=0, \ - peak_p=p_peak_ei, tau_d=tau_d_ei, src_equal_trg = False, self_cnt = False) - -i_ie, j_ie, _ = cn.connect_2lattice.expo_decay(i_lattice, e_lattice, np.arange(Ni), 62, periodic_boundary=True, interarea_dist=0, \ - peak_p=p_peak_ie, tau_d=tau_d_ie, src_equal_trg = False, self_cnt = False) - -i_ii, j_ii, _ = cn.connect_2lattice.expo_decay(i_lattice, i_lattice, np.arange(Ni), 62, periodic_boundary=True, interarea_dist=0, \ - peak_p=p_peak_ii, tau_d=tau_d_ii, src_equal_trg = True, self_cnt = False) - - -#%% -def find_indegree(i, j, N_src, N_trg): - A = sparse.csc_matrix((np.ones(i.shape, dtype=int), (i, j)),shape=(N_src,N_trg)) - num_in = A.sum(0) - return num_in.A[0] -#%% -num_in_ee = find_indegree(i_ee, j_ee, Ne, Ne) -num_in_ei = find_indegree(i_ei, j_ei, Ne, Ni) -num_in_ie = find_indegree(i_ie, j_ie, Ni, Ne) -num_in_ii = find_indegree(i_ii, j_ii, Ni, Ni) - - -#%% -def find_J(num_in, J_mean): - J = J_mean*np.sum(num_in)/(np.sum(np.sqrt(num_in))) - return J -#%% -w_ee_mean = 4 -w_ei_mean = 5 -w_ie_mean = 20 -w_ii_mean = 25 - -J_ee = find_J(num_in_ee, w_ee_mean) -J_ei = find_J(num_in_ei, w_ei_mean) -J_ie = find_J(num_in_ie, w_ie_mean) -J_ii = find_J(num_in_ii, w_ii_mean) - -#%% -def find_synWeight(j_cnt, J_weight, N_trg, num_indegree): - - w_cnt = np.zeros(j_cnt.shape) - for j in range(N_trg): - J_mean = J_weight/np.sqrt(num_indegree[j]) - J_std = J_mean/4 - w_tmp = np.random.randn(num_indegree[j])*J_std + J_mean - negative_w = np.any(w_tmp <= 0) - while negative_w: - w_tmp = np.random.randn(num_indegree[j])*J_std + J_mean - w_tmp[w_tmp <= 0] = np.random.randn(np.sum(w_tmp <= 0))*J_std + J_mean - negative_w = np.any(w_tmp <= 0) - - w_cnt[j_cnt == j] = w_tmp - - return w_cnt -#%% -w_ee = find_synWeight(j_ee, J_ee, Ne, num_in_ee) -w_ei = find_synWeight(j_ei, J_ei, Ni, num_in_ei) -w_ie = find_synWeight(j_ie, J_ie, Ne, num_in_ie) -w_ii = find_synWeight(j_ii, J_ii, Ni, num_in_ii) - - - -#%% -plt.figure() -plt.hist(num_in_ie) -#%% -#%%%%%%%%%%%%%%%%%%%%%% -e_lattice = cn.coordination.makelattice(63, 62, [0,0]) -i_lattice = cn.coordination.makelattice(32, 62, [0,0]) -""" -#%% - -""" -ijwd = get_ijwd() -ijwd.Ne = 77*77; ijwd.Ni = 39*39 -ijwd.width = 76 -ijwd.generate_ijw() -ijwd.generate_d_rand() -#%% - -chg_adapt_loca = [0, 0] -chg_adapt_range = 6 -chg_adapt_neuron = cn.findnearbyneuron.findnearbyneuron(ijwd.e_lattice, chg_adapt_loca, chg_adapt_range, ijwd.width) - - - -#%% -start_scope() - -neuronmodel_e = cn.model_neu_syn_AD.neuron_e_AD -neuronmodel_i = cn.model_neu_syn_AD.neuron_i_AD - -synapse_e = cn.model_neu_syn_AD.synapse_e_AD -synapse_i = cn.model_neu_syn_AD.synapse_i_AD - -group_e_1 =NeuronGroup(ijwd.Ne, model=neuronmodel_e, - threshold='v>v_threshold', method='euler', - reset='''v = v_reset - g_k += delta_gk''', refractory='(t-lastspike) 1: - warnings.warn(" Error: peak connection probability exceeds '1', adjust 'decay_p' or 'mean_SynSum' to reduce it below '1'" ) - - return p_peak - - def find_indegree(self, i, j, N_src, N_trg): - - A = sparse.csc_matrix((np.ones(i.shape, dtype=int), (i, j)),shape=(N_src,N_trg)) - num_in = A.sum(0) - return num_in.A[0] - - def find_J(self, num_in, J_mean): - J = J_mean*np.sum(num_in)/(np.sum(np.sqrt(num_in))) - return J - - def find_synWeight(self, j_cnt, J_weight, N_trg, num_indegree): - - w_cnt = np.zeros(j_cnt.shape) - for j in range(N_trg): - J_mean = J_weight/np.sqrt(num_indegree[j]) - J_std = J_mean/4 - w_tmp = np.random.randn(num_indegree[j])*J_std + J_mean - negative_w = np.any(w_tmp <= 0) - while negative_w: - #w_tmp = np.random.randn(num_indegree[j])*J_std + J_mean - w_tmp[w_tmp <= 0] = np.random.randn(np.sum(w_tmp <= 0))*J_std + J_mean - negative_w = np.any(w_tmp <= 0) - - w_cnt[j_cnt == j] = w_tmp - - return w_cnt -#%% - -""" -#%% -plt.figure() -plt.hist(num_in_ie) -#%%%%%%%%%%%%%%%%%%%%%% -e_lattice = cn.coordination.makelattice(63, 62, [0,0]) -i_lattice = cn.coordination.makelattice(32, 62, [0,0]) -""" -#%% - -""" -ijwd = get_ijwd() -ijwd.Ne = 77*77; ijwd.Ni = 39*39 -ijwd.width = 76 -ijwd.generate_ijw() -ijwd.generate_d_rand() -#%% - -chg_adapt_loca = [0, 0] -chg_adapt_range = 6 -chg_adapt_neuron = cn.findnearbyneuron.findnearbyneuron(ijwd.e_lattice, chg_adapt_loca, chg_adapt_range, ijwd.width) - - - -#%% -start_scope() - -neuronmodel_e = cn.model_neu_syn_AD.neuron_e_AD -neuronmodel_i = cn.model_neu_syn_AD.neuron_i_AD - -synapse_e = cn.model_neu_syn_AD.synapse_e_AD -synapse_i = cn.model_neu_syn_AD.synapse_i_AD - -group_e_1 =NeuronGroup(ijwd.Ne, model=neuronmodel_e, - threshold='v>v_threshold', method='euler', - reset='''v = v_reset - g_k += delta_gk''', refractory='(t-lastspike)