interneuron_placement.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. import random as rng
  2. import matplotlib.pyplot as plt
  3. import noise
  4. import numpy as np
  5. from brian2.units import *
  6. from matplotlib.patches import Ellipse
  7. from tqdm import tqdm
  8. from scripts.spatial_maps.orientation_map import OrientationMap
  9. class Pickle:
  10. def __init__(self, x, y, a, b, phi):
  11. self.x = x
  12. self.y = y
  13. self.a = a # Semimajor axis
  14. self.b = b # Semiminor axis
  15. self.phi = phi
  16. self.c = 2.0 * a # Sum distance
  17. self.foc_len = np.sqrt(a ** 2 - b ** 2)
  18. self.area = np.pi * a * b
  19. def get_p1(self):
  20. x1 = self.x - self.foc_len * np.cos(self.phi)
  21. y1 = self.y - self.foc_len * np.sin(self.phi)
  22. return x1, y1
  23. def get_p2(self):
  24. x2 = self.x + self.foc_len * np.cos(self.phi)
  25. y2 = self.y + self.foc_len * np.sin(self.phi)
  26. return x2, y2
  27. def get_ellipse(self):
  28. ell = Ellipse((self.x, self.y), 2.0 * self.a, 2.0 * self.b,
  29. angle=self.phi * 180. / np.pi, linewidth=1, fill=False, zorder=2)
  30. return ell
  31. def get_area(self):
  32. return np.pi * self.a * self.b
  33. def plot_neural_sheet(ex_positions, ex_tunings, axonal_clouds=None):
  34. X, Y = get_correct_position_mesh(ex_positions)
  35. n_ex = int(np.sqrt(len(ex_positions)))
  36. head_dir_preference = np.array(ex_tunings).reshape((n_ex, n_ex))
  37. fig = plt.figure(figsize=(4, 4))
  38. ax = fig.add_subplot(111)
  39. c = ax.pcolor(X, Y, head_dir_preference, vmin=-np.pi, vmax=np.pi, cmap="twilight")
  40. fig.colorbar(c, ax=ax, label="Orientation")
  41. if axonal_clouds is not None:
  42. for i, p in enumerate(axonal_clouds):
  43. ell = p.get_ellipse()
  44. # print(ell)
  45. ax.add_artist(ell)
  46. def get_position_mesh(ex_positions):
  47. n_ex = int(np.sqrt(len(ex_positions)))
  48. X = np.array([x for x, _ in ex_positions]).reshape((n_ex, n_ex))
  49. Y = np.array([y for _, y in ex_positions]).reshape((n_ex, n_ex))
  50. return X, Y
  51. def get_correct_position_mesh(ex_positions):
  52. n_ex = int(np.sqrt(len(ex_positions)))
  53. x_wrong = np.array([x for x, _ in ex_positions]).reshape((n_ex, n_ex))
  54. y_wrong = np.array([y for _, y in ex_positions]).reshape((n_ex, n_ex))
  55. x = x_wrong[0, :]
  56. y = y_wrong[:, 0]
  57. xmin = np.min(x)
  58. xmax = np.max(x)
  59. dx = (xmax - xmin) / (x.shape[0] - 1)
  60. ymin = np.min(y)
  61. ymax = np.max(y)
  62. dy = (ymax - ymin) / (y.shape[0] - 1)
  63. X, Y = np.meshgrid(np.arange(xmin, xmax + 2 * dx, dx) - dx / 2., np.arange(ymin, ymax + 2 * dy, dy) - dy / 2.)
  64. return X, Y
  65. def get_entropy_of_axonal_coverage(ex_neuron_tuning, ie_connections):
  66. ex_phase_vals_per_pickle = []
  67. phase_entropy_per_pickle = []
  68. n_hist_bins = 10
  69. for connected_idxs in ie_connections:
  70. ex_phase_vals_of_p = [ex_neuron_tuning[idx] for idx in connected_idxs]
  71. phase_entropy = 0.0
  72. ex_phase_vals_per_pickle.append(ex_phase_vals_of_p)
  73. ex_phase_hist, _ = np.histogram(ex_phase_vals_of_p, n_hist_bins)
  74. n_ex_of_p = float(len(ex_phase_vals_of_p))
  75. ex_phase_hist = 1. / n_ex_of_p * ex_phase_hist.astype(float)
  76. for n_phi in ex_phase_hist:
  77. if n_phi != 0:
  78. phase_entropy -= n_phi * np.log(n_phi)
  79. phase_entropy_per_pickle.append(phase_entropy)
  80. return phase_entropy_per_pickle
  81. def get_excitatory_neurons_in_inhibitory_axonal_clouds(ex_neuron_positions, inhibitory_axonal_clouds):
  82. ie_connections = []
  83. for p in inhibitory_axonal_clouds:
  84. ie_conn_p = []
  85. x_p_1, y_p_1 = p.get_p1()
  86. x_p_2, y_p_2 = p.get_p2()
  87. for ex_idx, ex_pos in enumerate(ex_neuron_positions):
  88. x_ex, y_ex = ex_pos
  89. d_1 = np.sqrt((x_ex - x_p_1) ** 2 + (y_ex - y_p_1) ** 2)
  90. d_2 = np.sqrt((x_ex - x_p_2) ** 2 + (y_ex - y_p_2) ** 2)
  91. if d_1 + d_2 < p.c:
  92. ie_conn_p.append(ex_idx)
  93. ie_connections.append(ie_conn_p)
  94. return ie_connections
  95. def get_excitatory_phases_in_inhibitory_axon(ex_neuron_positions, ex_neuron_tunings, inhibitory_neuron):
  96. ex_phase_vals = []
  97. x_p_1, y_p_1 = inhibitory_neuron.get_p1()
  98. x_p_2, y_p_2 = inhibitory_neuron.get_p2()
  99. for ex_idx, ex_pos in enumerate(ex_neuron_positions):
  100. x_ex, y_ex = ex_pos
  101. d_1 = np.sqrt((x_ex - x_p_1) ** 2 + (y_ex - y_p_1) ** 2)
  102. d_2 = np.sqrt((x_ex - x_p_2) ** 2 + (y_ex - y_p_2) ** 2)
  103. if d_1 + d_2 < inhibitory_neuron.c:
  104. ex_phase_vals.append(ex_neuron_tunings[ex_idx])
  105. return ex_phase_vals
  106. def get_interneuron_entropy(ex_phase_vals, entropy_bins):
  107. phase_entropy = 0.
  108. ex_phase_hist, _ = np.histogram(ex_phase_vals, entropy_bins)
  109. ex_phase_prob = ex_phase_hist / len(ex_phase_vals)
  110. for prob in ex_phase_prob:
  111. if prob > 0.0:
  112. phase_entropy += -prob * np.log(prob)
  113. return phase_entropy
  114. def create_interneuron_sheet_by_noise(ex_positions, ex_tunings, number_of_interneurons, long_axis, short_axis, max_x,
  115. max_y, random_seed=None,
  116. n_iterations=100):
  117. '''
  118. Start with uniform distribution
  119. '''
  120. if random_seed is not None:
  121. rng.seed(random_seed)
  122. pickle_a = long_axis
  123. pickle_b = short_axis
  124. pickle_n = number_of_interneurons
  125. x_n = int(np.sqrt(pickle_n))
  126. y_n = int(np.sqrt(pickle_n))
  127. x_step = int(max_x / (x_n + 1))
  128. y_step = int(max_y / (y_n + 1))
  129. inhibitory_axonal_clouds = []
  130. for n in range(pickle_n):
  131. inhibitory_axonal_clouds.append(Pickle(((n % x_n) + 1) * x_step, \
  132. (int(n / y_n) + 1) * y_step, \
  133. pickle_a, pickle_b, rng.random() * 2. * np.pi))
  134. '''
  135. Determine initial tunings and entropy values
  136. '''
  137. entropy_bins = np.linspace(-np.pi, np.pi, 30)
  138. ex_tunings_of_interneurons = []
  139. entropies_of_interneurons = []
  140. for i_neuron in inhibitory_axonal_clouds:
  141. ex_phase_vals = get_excitatory_phases_in_inhibitory_axon(ex_positions, ex_tunings, i_neuron)
  142. ex_tunings_of_interneurons.append(ex_phase_vals)
  143. entropies_of_interneurons.append(get_interneuron_entropy(ex_phase_vals, entropy_bins))
  144. '''
  145. (Randomly) perturb interneuron and see if entropy increases, if so update position and axonal tunings
  146. '''
  147. # print('Mean Entropy before rotation ', np.mean(entropies_of_interneurons))
  148. pert_phi = np.pi / 4.0
  149. pert_phi_decrease = pert_phi / (n_iterations + 1)
  150. for it in tqdm(range(n_iterations), desc="Optimizing axonal cloud distribution"):
  151. rotation_perturbation = pert_phi - it * pert_phi_decrease
  152. for i_neuron_id, i_neuron in enumerate(inhibitory_axonal_clouds):
  153. perturbed_interneuron = Pickle(i_neuron.x, i_neuron.y, long_axis, short_axis,
  154. i_neuron.phi + rotation_perturbation)
  155. perturbed_phase_vals = get_excitatory_phases_in_inhibitory_axon(ex_positions, ex_tunings,
  156. perturbed_interneuron)
  157. perturbed_entropy = get_interneuron_entropy(perturbed_phase_vals, entropy_bins)
  158. if perturbed_entropy > entropies_of_interneurons[i_neuron_id]:
  159. ex_tunings_of_interneurons.append(ex_phase_vals)
  160. entropies_of_interneurons[i_neuron_id] = perturbed_entropy
  161. i_neuron.phi = perturbed_interneuron.phi
  162. else:
  163. perturbed_interneuron = Pickle(i_neuron.x, i_neuron.y, long_axis, short_axis,
  164. i_neuron.phi - rotation_perturbation)
  165. perturbed_phase_vals = get_excitatory_phases_in_inhibitory_axon(ex_positions, ex_tunings,
  166. perturbed_interneuron)
  167. perturbed_entropy = get_interneuron_entropy(perturbed_phase_vals, entropy_bins)
  168. if perturbed_entropy > entropies_of_interneurons[i_neuron_id]:
  169. ex_tunings_of_interneurons.append(ex_phase_vals)
  170. entropies_of_interneurons[i_neuron_id] = perturbed_entropy
  171. i_neuron.phi = perturbed_interneuron.phi
  172. # print('Mean Entropy after rotation', np.mean(entropies_of_interneurons))
  173. return inhibitory_axonal_clouds, np.mean(entropies_of_interneurons)
  174. def create_interneuron_sheet_entropy_max_orientation(ex_positions, ex_tunings, number_of_interneurons, long_axis,
  175. short_axis, max_x, max_y, trial_orientations=30,
  176. number_of_bins=30, placement_jitter=0.0, seed=0):
  177. inhibitory_axonal_clouds = initialize_axonal_clouds_on_grid_with_random_orientation(number_of_interneurons,
  178. long_axis, short_axis, max_x,
  179. max_y, placement_jitter, seed)
  180. interneuron_positions = [(inh.x, inh.y) for inh in inhibitory_axonal_clouds]
  181. '''
  182. Determine initial tunings and entropy values
  183. '''
  184. entropies_of_interneurons = [0.]
  185. if trial_orientations > 0:
  186. entropies_of_interneurons, optimal_orientations = get_optimal_orientations_for_maximum_entropy(ex_positions,
  187. ex_tunings,
  188. interneuron_positions,
  189. long_axis,
  190. short_axis,
  191. number_of_bins,
  192. trial_orientations)
  193. for opt_orientation, axon in zip(optimal_orientations, inhibitory_axonal_clouds):
  194. axon.phi = opt_orientation
  195. return inhibitory_axonal_clouds, np.mean(entropies_of_interneurons)
  196. def create_interneuron_sheet_entropy_min_orientation(ex_positions, ex_tunings, number_of_interneurons, long_axis,
  197. short_axis, max_x, max_y, trial_orientations=30,
  198. number_of_bins=30, placement_jitter=0.0):
  199. inhibitory_axonal_clouds = initialize_axonal_clouds_on_grid_with_random_orientation(number_of_interneurons,
  200. long_axis, short_axis, max_x,
  201. max_y, placement_jitter)
  202. interneuron_positions = [(inh.x, inh.y) for inh in inhibitory_axonal_clouds]
  203. '''
  204. Determine initial tunings and entropy values
  205. '''
  206. entropies_of_interneurons, optimal_orientations = get_optimal_orientations_for_minimum_entropy(ex_positions,
  207. ex_tunings,
  208. interneuron_positions,
  209. long_axis,
  210. short_axis,
  211. number_of_bins,
  212. trial_orientations)
  213. for opt_orientation, axon in zip(optimal_orientations, inhibitory_axonal_clouds):
  214. axon.phi = opt_orientation
  215. return inhibitory_axonal_clouds, np.mean(entropies_of_interneurons)
  216. def get_optimal_orientations_for_maximum_entropy(ex_positions, ex_tunings, interneuron_positions, long_axis, short_axis,
  217. number_of_bins, trial_orientations):
  218. entropy_bins = np.linspace(-np.pi, np.pi, number_of_bins)
  219. entropies_of_interneurons = []
  220. optimal_orientations = []
  221. # for i_neuron in tqdm(inhibitory_axonal_clouds, desc="Maximizing entropy by rotation"):
  222. for x, y in interneuron_positions:
  223. orientations = np.linspace(-np.pi, np.pi, trial_orientations)
  224. entropy_for_orientation = []
  225. for orientation in orientations:
  226. perturbed_interneuron = Pickle(x, y, long_axis, short_axis, orientation)
  227. ex_phase_vals = get_excitatory_phases_in_inhibitory_axon(ex_positions, ex_tunings, perturbed_interneuron)
  228. entropy_for_orientation.append(get_interneuron_entropy(ex_phase_vals, entropy_bins))
  229. optimal_orientations.append(orientations[np.argmax(entropy_for_orientation)])
  230. entropies_of_interneurons.append(np.max(entropy_for_orientation))
  231. return entropies_of_interneurons, optimal_orientations
  232. def get_optimal_orientations_for_minimum_entropy(ex_positions, ex_tunings, interneuron_positions, long_axis, short_axis,
  233. number_of_bins, trial_orientations):
  234. entropy_bins = np.linspace(-np.pi, np.pi, number_of_bins)
  235. entropies_of_interneurons = []
  236. optimal_orientations = []
  237. # for i_neuron in tqdm(inhibitory_axonal_clouds, desc="Maximizing entropy by rotation"):
  238. for x, y in interneuron_positions:
  239. orientations = np.linspace(-np.pi, np.pi, trial_orientations)
  240. entropy_for_orientation = []
  241. for orientation in orientations:
  242. perturbed_interneuron = Pickle(x, y, long_axis, short_axis, orientation)
  243. ex_phase_vals = get_excitatory_phases_in_inhibitory_axon(ex_positions, ex_tunings, perturbed_interneuron)
  244. entropy_for_orientation.append(get_interneuron_entropy(ex_phase_vals, entropy_bins))
  245. optimal_orientations.append(orientations[np.argmin(entropy_for_orientation)])
  246. entropies_of_interneurons.append(np.min(entropy_for_orientation))
  247. return entropies_of_interneurons, optimal_orientations
  248. def initialize_axonal_clouds_on_grid_with_random_orientation(number_of_interneurons, long_axis, short_axis, sheet_x,
  249. sheet_y, placement_jitter=0.0, seed=0):
  250. '''
  251. Start with uniform distribution
  252. '''
  253. rng.seed(seed)
  254. pickle_a = long_axis
  255. pickle_b = short_axis
  256. pickle_n = number_of_interneurons
  257. x_n = int(np.sqrt(pickle_n))
  258. y_n = int(np.sqrt(pickle_n))
  259. x_step = int(sheet_x / (x_n + 1))
  260. y_step = int(sheet_y / (y_n + 1))
  261. inhibitory_axonal_clouds = []
  262. pj = placement_jitter
  263. for n in range(pickle_n):
  264. theta = rng.random() * 2. * np.pi
  265. pj_x = pj * np.cos(theta)
  266. pj_y = pj * np.sin(theta)
  267. inhibitory_axonal_clouds.append(Pickle(((n % x_n) + 1) * x_step + pj_x, \
  268. (int(n / y_n) + 1) * y_step + pj_y, \
  269. pickle_a, pickle_b, theta))
  270. return inhibitory_axonal_clouds
  271. def create_interneuron_sheet_by_repulsive_force(number_of_interneurons, long_axis, short_axis, max_x, max_y,
  272. random_seed=None,
  273. n_iterations=100):
  274. # '''
  275. # Start with random pickle distribution
  276. # '''
  277. # if random_seed is not None:
  278. # rng.seed(random_seed)
  279. # pickle_a = long_axis
  280. # pickle_b = short_axis
  281. # pickle_n = number_of_interneurons
  282. # x_rng_min = pickle_a
  283. # x_rng_max = max_x - pickle_a
  284. # y_rng_min = pickle_a
  285. # y_rng_max = max_y - pickle_a
  286. # inhibitory_axonal_clouds = []
  287. # for n in range(pickle_n):
  288. # inhibitory_axonal_clouds.append(Pickle(rng.uniform(x_rng_min, x_rng_max), \
  289. # rng.uniform(y_rng_min, y_rng_max), \
  290. # pickle_a, pickle_b, rng.random() * 2. * np.pi))
  291. '''
  292. Start with uniform distribution
  293. '''
  294. if random_seed is not None:
  295. rng.seed(random_seed)
  296. pickle_a = long_axis
  297. pickle_b = short_axis
  298. pickle_n = number_of_interneurons
  299. x_n = int(np.sqrt(pickle_n))
  300. y_n = int(np.sqrt(pickle_n))
  301. x_step = int(max_x / (x_n + 1))
  302. y_step = int(max_y / (y_n + 1))
  303. inhibitory_axonal_clouds = []
  304. for n in range(pickle_n):
  305. inhibitory_axonal_clouds.append(AxonalCloud(((n % x_n) + 1) * x_step, \
  306. (int(n / y_n) + 1) * y_step, \
  307. pickle_a, pickle_b, rng.random() * 2. * np.pi))
  308. # plotting()
  309. '''
  310. Distribute pickles by repulsive "force"
  311. '''
  312. f_scale = 0.2
  313. def point_repulsion(x_i, y_i, x_j, y_j):
  314. d_x = x_i - x_j
  315. d_y = y_i - y_j
  316. # Distance is torus-like as to approach more homogenous distribution
  317. if d_x > max_x / 2.:
  318. d_x = -max_x + d_x
  319. elif d_x < -max_x / 2.:
  320. d_x = max_x + d_x
  321. if d_y > max_y / 2.:
  322. d_y = -max_y + d_y
  323. elif d_y < -max_y / 2.:
  324. d_y = max_y + d_y
  325. d = np.sqrt(d_x ** 2 + d_y ** 2)
  326. f_i = f_scale * 1. / (d + 1) ** 2
  327. f_x = f_i * d_x / d
  328. f_y = f_i * d_y / d
  329. return f_x, f_y
  330. def pickle_repulsion(p_i, p_j):
  331. phi = p_i.phi
  332. p_i_x1, p_i_y1 = p_i.get_p1()
  333. p_i_x2, p_i_y2 = p_i.get_p2()
  334. p_j_x1, p_j_y1 = p_j.get_p1()
  335. p_j_x2, p_j_y2 = p_j.get_p2()
  336. f_p1p1_x, f_p1p1_y = point_repulsion(p_i_x1, p_i_y1, p_j_x1, p_j_y1) # p1-p1
  337. f_p1p2_x, f_p1p2_y = point_repulsion(p_i_x1, p_i_y1, p_j_x2, p_j_y2) # p1-p2
  338. f_p2p1_x, f_p2p1_y = point_repulsion(p_i_x2, p_i_y2, p_j_x1, p_j_y1) # p2-p1
  339. f_p2p2_x, f_p2p2_y = point_repulsion(p_i_x2, p_i_y2, p_j_x2, p_j_y2) # p2-p2
  340. f_p1_x = f_p1p1_x + f_p1p2_x
  341. f_p1_y = f_p1p1_y + f_p1p2_y
  342. f_p2_x = f_p2p1_x + f_p2p2_x
  343. f_p2_y = f_p2p1_y + f_p2p2_y
  344. m_p1 = (f_p1_x * np.sin(phi) - f_p1_y * np.cos(phi))
  345. m_p2 = (-f_p2_x * np.sin(phi) + f_p2_y * np.cos(phi))
  346. f_x_sum = f_p1_x + f_p2_x
  347. f_y_sum = f_p1_y + f_p2_y
  348. m_sum = m_p1 + m_p2
  349. return f_x_sum, f_y_sum, m_sum
  350. for i in tqdm(range(n_iterations), desc="Optimizing axonal cloud distribution"):
  351. delta_xyphi = []
  352. for i, p_i in enumerate(inhibitory_axonal_clouds):
  353. delta_x = 0.
  354. delta_y = 0.
  355. delta_phi = 0.
  356. for p_j in inhibitory_axonal_clouds:
  357. if p_i is not p_j:
  358. del_x, del_y, del_m = pickle_repulsion(p_i, p_j)
  359. delta_x += del_x
  360. delta_y += del_y
  361. delta_phi += del_m
  362. delta_xyphi.append([delta_x, delta_y, delta_phi])
  363. # plotting(delta_xy)
  364. for i, p_i in enumerate(inhibitory_axonal_clouds):
  365. x_new = p_i.x + delta_xyphi[i][0]
  366. y_new = p_i.y + delta_xyphi[i][1]
  367. p_i.phi = p_i.phi + delta_xyphi[i][2]
  368. # Torus-like distance so pickles can cross borders and behave like a subset of a bigger distribution
  369. if x_new < max_x and x_new > 0.0:
  370. p_i.x = x_new
  371. elif x_new < 0.:
  372. p_i.x = max_x + x_new
  373. elif x_new > max_x:
  374. p_i.x = x_new - max_x
  375. if y_new < max_y and y_new > 0.0:
  376. p_i.y = y_new
  377. elif y_new < 0.:
  378. p_i.y = max_y + y_new
  379. elif y_new > max_y:
  380. p_i.y = y_new - max_y
  381. # plotting()
  382. # plotting()
  383. return inhibitory_axonal_clouds
  384. def create_grid_of_excitatory_neurons(max_x, max_y, number_of_excitatory_neurons_per_row, tuning_map):
  385. grid_x = number_of_excitatory_neurons_per_row
  386. grid_y = number_of_excitatory_neurons_per_row
  387. x = np.linspace(0, max_x, grid_x)
  388. y = np.linspace(0, max_y, grid_y)
  389. ex_neuron_positions = []
  390. ex_neuron_tuning = []
  391. head_dir_preference = np.zeros((grid_x, grid_y))
  392. for y_idx, yy in enumerate(y):
  393. for x_idx, xx in enumerate(x):
  394. p_noise = tuning_map(xx, yy)
  395. head_dir_preference[x_idx, y_idx] = p_noise
  396. ex_neuron_positions.append([xx, yy])
  397. ex_neuron_tuning.append(p_noise)
  398. return ex_neuron_positions, ex_neuron_tuning
  399. def test_run():
  400. '''
  401. Neural sheet
  402. '''
  403. # To go from the 3d data obtained in Peng 2017 to a 2d sheet is not straightforward
  404. # Assuming a depth of 100um, the density becomes a 1000 interneurons/mm2 and thus about 3000-4000 exneurons/mm2
  405. # A long 200um short 50um interneuron axon would cover about 90 partners
  406. # On the other hand, the typical contacts per excitatory neuron would be A_total/(A_I*N_I) = 30
  407. N_E = 400
  408. N_I = 40
  409. sheet_x = 300 * um
  410. sheet_y = 300 * um
  411. inhibitory_axon_long_axis = 100 * um
  412. inhibitory_axon_short_axis = 25 * um
  413. number_of_excitatory_neurons_per_row = int(np.sqrt(N_E))
  414. '''
  415. Tuning Maps
  416. '''
  417. # tuning_label = "Perlin"
  418. tuning_label = "Orientation map"
  419. if tuning_label == "Perlin":
  420. tuning_map = lambda x, y: noise.pnoise2(x / 100.0, y / 100.0, octaves=2) * np.pi
  421. elif tuning_label == "Orientation map":
  422. map = OrientationMap(20, 20, 7, sheet_x / um, sheet_y / um)
  423. map.improve(10)
  424. tuning_map = lambda x, y: map.orientation_map_float(x, y)
  425. ex_positions, ex_tunings = create_grid_of_excitatory_neurons(sheet_x / um, sheet_y / um,
  426. number_of_excitatory_neurons_per_row, tuning_map)
  427. # inhibitory_axonal_clouds = create_interneuron_sheet(N_I, inhibitory_axon_long_axis / um,
  428. # inhibitory_axon_short_axis / um, sheet_x / um,
  429. # sheet_y / um, random_seed=2, n_iterations=1000)
  430. inhibitory_axonal_clouds = create_interneuron_sheet_by_noise(ex_positions, ex_tunings, N_I,
  431. inhibitory_axon_long_axis / um,
  432. inhibitory_axon_short_axis / um, sheet_x / um,
  433. sheet_y / um, random_seed=3, n_iterations=10)
  434. plot_neural_sheet(ex_positions, ex_tunings, inhibitory_axonal_clouds)
  435. if __name__ == "__main__":
  436. test_run()