3.2 Optimization in the GUI
This tutorial walks through how to use the Optimization feature of HNN through the GUI. Make sure you have at least gone through 3.1 HNN GUI Quickstart first, so that you understand how to start and use the GUI in general.
For a more in-depth approach that covers similar functionality (and much more), see (Tolley et al., 2026). For tutorials on how to use optimization via the API, see here and here.
1. First simulation
First, let’s load some representative example data that we want to compare a simulation against. Go to our hnn-data repository here (separate from installing HNN) and download this file; on the right side of the page, near where it says Raw, you should see a download symbol. Click that, or feel free to git clone the hnn-data repository as a whole.
- Start the GUI (see 3.1 HNN GUI Quickstart for how).
- Click the
Load databutton (in theSimulationtab) and load theexperimental_S1_Threshold.txtfile you just downloaded. A plot showing the data should appear on the right, similar to the figure below:
Figure 1
- Next to
Cores(underSimulation Parameters), increase the number until it increases no further. - Click the
Run Simulationbutton to run the default simulation. - Once the simulation has completed, you should see its results on the right, similar to the figure below:
Figure 2
- Click the
Visualizationtab. - We want to display the simulation versus the experimental data. Click on the entry for
Data to Compare, and select the name of the file that you loaded,experimental_S1_Threshold. - Next, click the
Clear axisbutton at the bottom (you may have to scroll), and then clickAdd plot. - You should now see a plot on the right that displays both the simulation (
default) and the experimental loaded data, in addition to their root-mean-square-error (around6.9827) and correlation measures (around0.9918), similar to this figure:
Figure 3
2. Hand-tuning
Let’s try “hand-tuning” a parameter of one of our drive inputs to see if we can get the simulation to match the experimental data better.
- Click on the
External drivestab. - Click the box for the first and only distal drive,
evdist1. - Let’s try changing the mean time of when the distal drive spikes, in the hopes that it will improve how our simulation matches the experiment. Edit the value in the
Mean timebox to be64.00. Scientifically, this is analogous to us hypothesizing “What if, in our experiment, the distal input arriving from cortico-cortical and non-lemniscal thalamic sources is arriving slightly later?” Your screen should resemble the following:
Figure 4
- Click back to the
Simulationtab. We are going to run a new simulation. - In the
Namebox, change the simulation name to be something likedefault-handtune-evdist1(or whatever you prefer). - Click
Run Simulationagain, after which a new figure will appear on the right. - Similar to before, click the
Visualizationtab, then underData to Compare, selectexperimental_S1_Threshold. Next, click theClear axisbutton (you may have to scroll down) then theAdd plotbutton. You should see something like the following:
Figure 5
As it turns out, our change made things worse, since now the RMSE has increased to around 7.8567, and our corrrelation has decreased.
3. Optimization
Instead of using manual “hand-tuning” to try to see how changing parameters affects our simulation in relation to some experimental data, we can also use “optimization”. This will run several simulations where one or more parameters have their values changed automatically, and at each step, the computer will run try to get the simulation closer to the “objective” of being similar to the experimental data values. Again, see (Tolley et al., 2026) for more details.
Click the
Optimizationtab.We need to make several changes in this tab:
- Decrease
Max Iterationsto3. - Change
Solvertocma. - For
Target Data, select your loaded experimental data (experimental_S1_Threshold) - Click the box for
evdist1to expand it. - Inside the
evdist1box, in theOptimize against?column of checkboxes, check the checkbox forMean time. - Your GUI should now resemble the following:
- Decrease
Figure 6
- Click the
Run Optimizationtab. Note that depending on your computer speed, this could take up to several minutes. - Finally, depending on randomness, you will probably see that the optimization has resulted in an improved fit to your experimental data, in which case the screen will resemble the following:
Figure 7
Before we look at the results, click the
Save Optimization Historybutton. This will prompt you for where to save a raw text file that includes the history of all the parameters you optimized against, so that you can see what the parameters were both before and after optimization, including their final (optimized) values, and how much they changed.Since we used the default
dipole_rmseobject, the RMSE value was used during the optimization, and in the example shown above, it has decreased to6.8615. This is not just a better RMSE value than what we found by hand-tuning (7.8567, viewable by selectingFigure 3on the right), but in fact slightly better than the default simulation’s as well (6.9827, viewable by selectingFigure 2on the right).However, note that in our optimized simulation (
Figure 4in the GUI on the right), while some portions of the dipole time series are closer to the experimental data, other portions are farther away from it. This is an important point: a better quantitative fit does not necessarily mean that the scientific validity is better! You must always use your scientific judgment to evaluate if such a parameter change makes sense in the biological system you’re investigating.In HNN, you can optimize against multiple parameters and as many parameters as you want. However, be aware that increasing the number of parameters you optimize against greatly increases the computational cost of the simulations that it needs to run. Additionally, if you want to run many simulations or iterations of the optimization, we strongly recommend that you switch to the API, since the GUI consumes more memory to run simulations than the API.
For tutorials on how to use optimization via the API, see here and here.