hnn-core 0.4.3__tar.gz → 0.5.1.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. {hnn_core-0.4.3/hnn_core.egg-info → hnn_core-0.5.1.dev0}/PKG-INFO +1 -1
  2. hnn_core-0.5.1.dev0/examples/howto/optimize_evoked.py +295 -0
  3. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/optimize_rhythmic.py +8 -5
  4. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/__init__.py +1 -1
  5. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/gui/gui.py +298 -31
  6. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/hnn_io.py +14 -0
  7. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/network.py +203 -42
  8. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/optimization/general_optimization.py +68 -16
  9. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/optimization/objective_functions.py +23 -14
  10. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_general_optimization.py +150 -2
  11. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_gui.py +237 -11
  12. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_network.py +172 -10
  13. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0/hnn_core.egg-info}/PKG-INFO +1 -1
  14. hnn_core-0.4.3/examples/howto/optimize_evoked.py +0 -214
  15. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/LICENSE +0 -0
  16. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/MANIFEST.in +0 -0
  17. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/README.md +0 -0
  18. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/README.txt +0 -0
  19. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/README.txt +0 -0
  20. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/plot_batch_simulate.py +0 -0
  21. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/plot_connectivity.py +0 -0
  22. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/plot_firing_pattern.py +0 -0
  23. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/plot_hnn_animation.py +0 -0
  24. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/plot_record_extracellular_potentials.py +0 -0
  25. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/plot_replaying_spike_data_as_input.py +0 -0
  26. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/howto/plot_simulate_mpi_backend.py +0 -0
  27. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/workflows/README.txt +0 -0
  28. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/workflows/plot_simulate_alpha.py +0 -0
  29. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/workflows/plot_simulate_beta.py +0 -0
  30. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/workflows/plot_simulate_evoked.py +0 -0
  31. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/workflows/plot_simulate_gamma.py +0 -0
  32. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/examples/workflows/plot_simulate_somato.py +0 -0
  33. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/batch_simulate.py +0 -0
  34. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/cell.py +0 -0
  35. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/cell_response.py +0 -0
  36. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/cells_default.py +0 -0
  37. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/check.py +0 -0
  38. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/dipole.py +0 -0
  39. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/docs.py +0 -0
  40. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/drives.py +0 -0
  41. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/externals/__init__.py +0 -0
  42. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/externals/bayesopt.py +0 -0
  43. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/externals/mne.py +0 -0
  44. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/extracellular.py +0 -0
  45. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/gui/__init__.py +0 -0
  46. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/gui/_logging.py +0 -0
  47. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/gui/_viz_manager.py +0 -0
  48. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/gui/hnn_widget.ipynb +0 -0
  49. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/ar.mod +0 -0
  50. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/ca.mod +0 -0
  51. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/cad.mod +0 -0
  52. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/cat.mod +0 -0
  53. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/dipole.mod +0 -0
  54. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/dipole_pp.mod +0 -0
  55. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/hh2.mod +0 -0
  56. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/kca.mod +0 -0
  57. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/km.mod +0 -0
  58. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mod/vecevent.mod +0 -0
  59. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/mpi_child.py +0 -0
  60. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/network_builder.py +0 -0
  61. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/network_models.py +0 -0
  62. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/optimization/__init__.py +0 -0
  63. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/optimization/optimize_evoked.py +0 -0
  64. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/parallel_backends.py +0 -0
  65. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/param/N20.json +0 -0
  66. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/param/default.json +0 -0
  67. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/param/gamma_L5weak_L2weak.json +0 -0
  68. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/param/jones2009_base.json +0 -0
  69. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/params.py +0 -0
  70. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/params_default.py +0 -0
  71. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/conftest.py +0 -0
  72. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/regenerate_test_network.py +0 -0
  73. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_batch_simulate.py +0 -0
  74. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_cell.py +0 -0
  75. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_cell_response.py +0 -0
  76. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_cells_default.py +0 -0
  77. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_dipole.py +0 -0
  78. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_drives.py +0 -0
  79. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_extracellular.py +0 -0
  80. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_io.py +0 -0
  81. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_mpi_child.py +0 -0
  82. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_optimize_evoked.py +0 -0
  83. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_parallel_backends.py +0 -0
  84. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_params.py +0 -0
  85. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_utils.py +0 -0
  86. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/tests/test_viz.py +0 -0
  87. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/utils.py +0 -0
  88. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core/viz.py +0 -0
  89. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core.egg-info/SOURCES.txt +0 -0
  90. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core.egg-info/dependency_links.txt +0 -0
  91. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core.egg-info/entry_points.txt +0 -0
  92. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core.egg-info/requires.txt +0 -0
  93. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/hnn_core.egg-info/top_level.txt +0 -0
  94. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/pyproject.toml +0 -0
  95. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/setup.cfg +0 -0
  96. {hnn_core-0.4.3 → hnn_core-0.5.1.dev0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hnn-core
3
- Version: 0.4.3
3
+ Version: 0.5.1.dev0
4
4
  Summary: Code for biophysical simulation of a cortical column using Neuron
5
5
  Home-page:
6
6
  Download-URL: http://github.com/jonescompneurolab/hnn-core
@@ -0,0 +1,295 @@
1
+ """
2
+ =================================================
3
+ 05. Optimize simulated evoked response parameters
4
+ =================================================
5
+
6
+ This example demonstrates how to optimize the parameters
7
+ of the model simulation to match an experimental dipole waveform.
8
+ """
9
+
10
+ # Authors: Carolina Fernandez <cxf418@miami.edu>
11
+ # Nick Tolley <nicholas_tolley@brown.edu>
12
+ # Ryan Thorpe <ryan_thorpe@brown.edu>
13
+ # Mainak Jas <mjas@mgh.harvard.edu>
14
+
15
+ from hnn_core.optimization import Optimizer
16
+ from urllib.request import urlretrieve
17
+ import os.path as op
18
+
19
+ import matplotlib.pyplot as plt
20
+ from matplotlib.lines import Line2D
21
+
22
+ ###############################################################################
23
+ # 1. Import libraries and set up environment
24
+ # ------------------------------------------
25
+ #
26
+ # We'll start by importing the necessary `hnn_core` modules and other libraries
27
+ # required for this tutorial.
28
+
29
+ import hnn_core
30
+ from hnn_core import (MPIBackend, jones_2009_model, simulate_dipole,
31
+ read_dipole)
32
+ from hnn_core.viz import plot_dipole
33
+
34
+ hnn_core_root = op.join(op.dirname(hnn_core.__file__))
35
+
36
+ # The number of cores may need modifying depending on your current machine.
37
+ n_procs = 10
38
+
39
+ ###############################################################################
40
+ # 2. Load experimental dipole
41
+ # ---------------------------
42
+ #
43
+ # Our goal is to optimize our model to match experimental data.
44
+ #
45
+ # We'll load a pre-recorded MEG dipole waveform, which represents early evoked
46
+ # activity from primary somatosensory cortex in response to a brief tap to
47
+ # the finger. This data will serve as our *target dipole* for the optimization
48
+ # process.
49
+
50
+ data_url = ('https://raw.githubusercontent.com/jonescompneurolab/hnn/master/'
51
+ 'data/MEG_detection_data/yes_trial_S1_ERP_all_avg.txt')
52
+ urlretrieve(data_url, 'yes_trial_S1_ERP_all_avg.txt')
53
+ dipole_experimental = read_dipole('yes_trial_S1_ERP_all_avg.txt')
54
+
55
+ # Plot
56
+ fig, ax = plt.subplots(figsize=(6, 6))
57
+ dipole_experimental.plot(ax=ax, layer='agg', show=False,
58
+ color='tab:blue')
59
+ ax.legend(['experimental'])
60
+
61
+ ###############################################################################
62
+ # 3. Simulate initial dipole
63
+ # --------------------------
64
+ #
65
+ # Now, we'll simulate the initial dipole using a predefined set of parameters
66
+ # we arrived to after some hand-tuning. This simulation will provide a baseline
67
+ # to compare against the experimental data before optimization.
68
+
69
+ net_initial = jones_2009_model()
70
+
71
+ n_drive_cells = 1
72
+ cell_specific = False
73
+
74
+ # Proximal 1
75
+ weights_ampa_p1 = {'L2_basket': 0.08831, 'L2_pyramidal': 0.01525,
76
+ 'L5_basket': 0.19934, 'L5_pyramidal': 0.00865}
77
+ synaptic_delays_p = {'L2_basket': 0.1, 'L2_pyramidal': 0.1,
78
+ 'L5_basket': 1., 'L5_pyramidal': 1.}
79
+ net_initial.add_evoked_drive('evprox1',
80
+ mu=26.61,
81
+ sigma=2.47,
82
+ numspikes=1,
83
+ location='proximal',
84
+ weights_ampa=weights_ampa_p1,
85
+ synaptic_delays=synaptic_delays_p,
86
+ n_drive_cells=n_drive_cells,
87
+ cell_specific=cell_specific)
88
+
89
+ # Distal
90
+ weights_ampa_d1 = {'L2_basket': 0.006562, 'L2_pyramidal': .000007,
91
+ 'L5_pyramidal': 0.142300}
92
+ weights_nmda_d1 = {'L2_basket': 0.019482, 'L2_pyramidal': 0.004317,
93
+ 'L5_pyramidal': 0.080074}
94
+ synaptic_delays_d1 = {'L2_basket': 0.1, 'L2_pyramidal': 0.1,
95
+ 'L5_pyramidal': 0.1}
96
+ net_initial.add_evoked_drive('evdist1',
97
+ mu=63.53,
98
+ sigma=3.85,
99
+ numspikes=1,
100
+ location='distal',
101
+ weights_ampa=weights_ampa_d1,
102
+ weights_nmda=weights_nmda_d1,
103
+ synaptic_delays=synaptic_delays_d1,
104
+ n_drive_cells=n_drive_cells,
105
+ cell_specific=cell_specific)
106
+
107
+ # Proximal 2
108
+ weights_ampa_p2 = {'L2_basket': 0.000003, 'L2_pyramidal': 1.438840,
109
+ 'L5_basket': 0.008958, 'L5_pyramidal': 0.1}
110
+ net_initial.add_evoked_drive('evprox2',
111
+ mu=120.,
112
+ sigma=1.,
113
+ numspikes=1,
114
+ location='proximal',
115
+ weights_ampa=weights_ampa_p2,
116
+ synaptic_delays=synaptic_delays_p,
117
+ n_drive_cells=n_drive_cells,
118
+ cell_specific=cell_specific)
119
+
120
+ # Simulate initial dipole
121
+ n_trials = 3
122
+ tstop = dipole_experimental.times[-1]
123
+ with MPIBackend(n_procs=n_procs, mpi_cmd='mpiexec'):
124
+ dipoles_initial = simulate_dipole(
125
+ net_initial, tstop=tstop, n_trials=n_trials)
126
+
127
+ # Smooth and scale
128
+ window_length = 30
129
+ scaling_factor = 3000
130
+ for dipole in dipoles_initial:
131
+ dipole.smooth(window_length).scale(scaling_factor)
132
+
133
+ # Plot
134
+ fig, ax = plt.subplots(figsize=(6, 6))
135
+ dipole_experimental.plot(ax=ax, layer='agg', show=False,
136
+ color='tab:blue')
137
+ plot_dipole(dipoles_initial.copy(), ax=ax, layer='agg', show=False,
138
+ color='tab:orange', average=True)
139
+
140
+ # Legend
141
+ legend_handles = [Line2D([0], [0], color='tab:blue', lw=1.0),
142
+ Line2D([0], [0], color='tab:orange', lw=1.0)]
143
+ ax.legend(legend_handles, ['experimental', 'initial'])
144
+
145
+ ###############################################################################
146
+ # 4. Define the ``set_params`` function
147
+ # -----------------------------------
148
+ #
149
+ # Now we can begin the optimization!
150
+ #
151
+ # First, we'll define a ``set_params`` function. This function tells the optimizer
152
+ # how to apply the chosen parameters to the network during each iteration.
153
+ #
154
+ # Comparison of the initial dipoles reveals that the second positive peak of the
155
+ # experimental dipole (blue) has a larger amplitude, later latency, and broader
156
+ # temporal distribution than the corresponding peak in the initial dipole (orange).
157
+ #
158
+ # Let's optimize the relevant parameters for the second proximal (evprox2) drive,
159
+ # as it is primarily responsible for this component of the dipole.
160
+
161
+
162
+ def set_params(net, params):
163
+
164
+ # Proximal 1
165
+ net.add_evoked_drive('evprox1',
166
+ mu=26.61,
167
+ sigma=2.47,
168
+ numspikes=1,
169
+ location='proximal',
170
+ weights_ampa=weights_ampa_p1,
171
+ synaptic_delays=synaptic_delays_p,
172
+ n_drive_cells=n_drive_cells,
173
+ cell_specific=cell_specific)
174
+
175
+ # Distal
176
+ net.add_evoked_drive('evdist1',
177
+ mu=63.53,
178
+ sigma=3.85,
179
+ numspikes=1,
180
+ location='distal',
181
+ weights_ampa=weights_ampa_d1,
182
+ weights_nmda=weights_nmda_d1,
183
+ synaptic_delays=synaptic_delays_d1,
184
+ n_drive_cells=n_drive_cells,
185
+ cell_specific=cell_specific)
186
+
187
+ # Proximal 2
188
+ weights_ampa_p2 = {'L2_basket': 0.000003, 'L2_pyramidal': 1.438840,
189
+ 'L5_basket': 0.008958, 'L5_pyramidal': params['evprox2_ampa_L5_pyramidal']}
190
+ net.add_evoked_drive('evprox2',
191
+ mu=params['evprox2_mu'],
192
+ sigma=params['evprox2_sigma'],
193
+ numspikes=1,
194
+ location='proximal',
195
+ weights_ampa=weights_ampa_p2,
196
+ synaptic_delays=synaptic_delays_p,
197
+ n_drive_cells=n_drive_cells,
198
+ cell_specific=cell_specific)
199
+
200
+ ###############################################################################
201
+ # 5. Define optimization constraints
202
+ # ----------------------------------
203
+ #
204
+ # The constraints define the permissible range (lower and upper bounds) for each
205
+ # parameter during the optimization process.
206
+ #
207
+ # The ranges for synaptic weights (µS) are set to maintain physiologically
208
+ # realistic model behavior, rather than solely relying on existing literature values.
209
+
210
+
211
+ constraints = dict({'evprox2_ampa_L5_pyramidal': (0.01, 1.0),
212
+ 'evprox2_mu': (100., 150.),
213
+ 'evprox2_sigma': (1., 20.)})
214
+
215
+ ###############################################################################
216
+ # 6. Define the initial parameters
217
+ # --------------------------------
218
+ #
219
+ # For optimal results, set initial_params to your hand-tuned values since they
220
+ # already provide a good fit.
221
+ #
222
+ # If ``initial_params`` is not set, the optimizer will use the midpoint of the
223
+ # constraints as the initial parameters.
224
+
225
+ initial_params = dict({'evprox2_ampa_L5_pyramidal': 0.1,
226
+ 'evprox2_mu': 120.,
227
+ 'evprox2_sigma': 1.})
228
+
229
+ ###############################################################################
230
+ # 7. Initialize and run the optimizer
231
+ # -----------------------------------
232
+ #
233
+ # Finally, let's initialize and run the optimizer. We'll instantiate the Optimizer
234
+ # class, providing our network, simulation time, constraints, and the ``set_params``
235
+ # function.
236
+ #
237
+ # By default, the Optimizer aims to minimize the Root Mean Square Error (RMSE)
238
+ # between the simulated and experimental dipoles.
239
+ #
240
+ # To capture the model's average behavior, it's recommended to set ``n_trials``
241
+ # to a value greater than 1. Using ``n_trials=1`` might find a parameter set that
242
+ # works well for a single, specific simulation run but performs poorly on average.
243
+ #
244
+ # Additionally, while ``max_iter`` is set to 50 in this example for a quicker
245
+ # demonstration, you can set it to any value. The default is 200.
246
+ #
247
+ # .. note:: A custom objective function can also be supplied.
248
+
249
+ net = jones_2009_model()
250
+ optim = Optimizer(net, tstop=tstop, constraints=constraints,
251
+ set_params=set_params, initial_params=initial_params, max_iter=50)
252
+ with MPIBackend(n_procs=n_procs, mpi_cmd='mpiexec'):
253
+ optim.fit(target=dipole_experimental, n_trials=n_trials, scale_factor=scaling_factor,
254
+ smooth_window_len=window_length)
255
+
256
+ ###############################################################################
257
+ # 8. Simulate the optimized dipole
258
+ # --------------------------------
259
+ #
260
+ # Now, we can simulate the dipole using the newly found optimized parameters
261
+ # to see how well they match the experimental data.
262
+
263
+ with MPIBackend(n_procs=n_procs, mpi_cmd='mpiexec'):
264
+ dipoles_optimized = simulate_dipole(
265
+ optim.net_, tstop=tstop, n_trials=n_trials)
266
+
267
+ # Smooth and scale
268
+ for dipole in dipoles_optimized:
269
+ dipole.smooth(window_length).scale(scaling_factor)
270
+
271
+ ###############################################################################
272
+ # 9. Visualize the results
273
+ # ------------------------
274
+ #
275
+ # Finally, we can compare the experimental, initial, and optimized dipoles.
276
+ #
277
+ # We can also plot the convergence.
278
+
279
+ fig, ax = plt.subplots(sharex=True, figsize=(6, 6))
280
+ dipole_experimental.plot(ax=ax, layer='agg', show=False,
281
+ color='tab:blue')
282
+ plot_dipole(dipoles_initial.copy(), ax=ax, layer='agg', show=False,
283
+ color='tab:orange', average=True)
284
+ plot_dipole(dipoles_optimized.copy(), ax=ax, layer='agg',
285
+ show=False, color='tab:green', average=True)
286
+
287
+ # Legend
288
+ legend_handles = [Line2D([0], [0], color='tab:blue', lw=1.0),
289
+ Line2D([0], [0], color='tab:orange', lw=1.0),
290
+ Line2D([0], [0], color='tab:green', lw=1.0)]
291
+ ax.legend(legend_handles, ['experimental', 'initial', 'optimized'])
292
+
293
+ # Convergence plot
294
+ optim.plot_convergence()
295
+ plt.show()
@@ -10,6 +10,8 @@ components.
10
10
 
11
11
  # Authors: Carolina Fernandez <cxf418@miami.edu>
12
12
 
13
+ from hnn_core.viz import plot_psd
14
+ from hnn_core.optimization import Optimizer
13
15
  import matplotlib.pyplot as plt
14
16
 
15
17
  ###############################################################################
@@ -26,6 +28,7 @@ n_procs = 10
26
28
  # object with no attached drives, and a dictionary of the parameters we wish to
27
29
  # optimize.
28
30
 
31
+
29
32
  def set_params(net, params):
30
33
 
31
34
  # Proximal (alpha)
@@ -70,6 +73,7 @@ def set_params(net, params):
70
73
  # The following synaptic weight parameter ranges (units of micro-siemens)
71
74
  # were chosen so as to keep the model in physiologically realistic regimes.
72
75
 
76
+
73
77
  constraints = dict()
74
78
  constraints.update({'alpha_prox_weight': (4.4e-5, 6.4e-5),
75
79
  'alpha_prox_tstart': (45, 55),
@@ -82,7 +86,6 @@ constraints.update({'alpha_prox_weight': (4.4e-5, 6.4e-5),
82
86
 
83
87
  ###############################################################################
84
88
  # Now we define and fit the optimizer.
85
- from hnn_core.optimization import Optimizer
86
89
 
87
90
  tstop = 300
88
91
  scale_factor = 3000
@@ -90,19 +93,18 @@ smooth_window_len = 20
90
93
 
91
94
  net = jones_2009_model()
92
95
  optim = Optimizer(net, tstop=tstop, constraints=constraints,
93
- set_params=set_params, obj_fun='maximize_psd')
96
+ set_params=set_params, obj_fun='maximize_psd', max_iter=50)
94
97
 
95
98
  # 8-15 Hz (alpha) and 15-30 Hz (beta) are the frequency bands whose
96
99
  # power we wish to maximize in a ratio of 1 to 2.
97
100
  with MPIBackend(n_procs=n_procs, mpi_cmd='mpiexec'):
98
- optim.fit(f_bands=[(9, 11), (19, 21)], relative_bandpower=(1, 2),
101
+ optim.fit(f_bands=[(9, 11), (19, 21)], relative_bandpower=[1, 2],
99
102
  scale_factor=scale_factor, smooth_window_len=smooth_window_len)
100
103
 
101
104
  ###############################################################################
102
105
  # Finally, we can plot the optimized dipole, power spectral density (PSD), and
103
106
  # convergence plot.
104
107
 
105
- from hnn_core.viz import plot_psd
106
108
 
107
109
  with MPIBackend(n_procs=n_procs, mpi_cmd='mpiexec'):
108
110
  opt_dpl = simulate_dipole(optim.net_, tstop=tstop, n_trials=1)[0]
@@ -119,4 +121,5 @@ axes[0].legend(['optimized'])
119
121
  plot_psd(opt_dpl, fmax=50, ax=axes[1], show=False)
120
122
 
121
123
  # convergence
122
- fig1 = optim.plot_convergence()
124
+ optim.plot_convergence()
125
+ plt.show()
@@ -19,4 +19,4 @@ from .hnn_io import (
19
19
  write_network_configuration,
20
20
  )
21
21
 
22
- __version__ = "0.4.3"
22
+ __version__ = "0.5.1.dev0"