Skip to content

Commit f716345

Browse files
Merge branch 'neurolib-dev:master' into Lead_Field_Matrix
2 parents 69e5e7b + ec2434e commit f716345

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+9317
-91
lines changed

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install dependencies 🛠
3030
run: |
3131
python -m pip install --upgrade pip
32-
pip install mkdocs mkdocs-material mkdocstrings mkdocstrings-python mknotebooks Pygments mkdocs-include-markdown-plugin livereload
32+
pip install mkdocs mkdocs-material mkdocstrings mkdocstrings-python mknotebooks Pygments livereload
3333
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3434
pip install .
3535
- name: Build documentation 👷‍♀️

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ You can chose from different neural mass [models](https://github.com/neurolib-de
3535

3636
📚 Please read the [gentle introduction](https://caglorithm.github.io/notebooks/neurolib-intro/) to `neurolib` for an overview of the basic functionality and the science behind whole-brain simulations or read the [documentation](https://neurolib-dev.github.io/) for getting started.
3737

38+
To browse the source code of `neurolib` visit out [GitHub repository](https://github.com/neurolib-dev/neurolib).
39+
3840
📝 <a href="#how-to-cite">Cite</a> the following paper if you use `neurolib` for your own research:
3941

4042
> Cakan, C., Jajcay, N. & Obermayer, K. neurolib: A Simulation Framework for Whole-Brain Neural Mass Modeling. [Cogn. Comput. (2021)](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1007822).
@@ -95,6 +97,10 @@ neurolib/ # Main module
9597
├── optimize/ # Optimization submodule
9698
├── evolution/ # Evolutionary optimization
9799
└── exploration/ # Parameter exploration
100+
├── control/optimal_control/ # Optimal control submodule
101+
├── oc.py # Optimal control base class
102+
├── cost_functions.py # cost functions for OC
103+
├── /.../ # Implemented OC models
98104
├── data/ # Empirical datasets (structural, functional)
99105
├── utils/ # Utility belt
100106
├── atlases.py # Atlases (Region names, coordinates)
@@ -120,6 +126,7 @@ Example [IPython Notebooks](examples/) on how to use the library can be found in
120126
- [Example 0.6](https://mybinder.org/v2/gh/neurolib-dev/neurolib/master?filepath=examples%2Fexample-0.6-custom-model.ipynb) - Minimal example of how to implement your own model in `neurolib`
121127
- [Example 1.2](https://mybinder.org/v2/gh/neurolib-dev/neurolib/master?filepath=examples%2Fexample-1.2-brain-network-exploration.ipynb) - Parameter exploration of a brain network and fitting to BOLD data
122128
- [Example 2.0](https://mybinder.org/v2/gh/neurolib-dev/neurolib/master?filepath=examples%2Fexample-2-evolutionary-optimization-minimal.ipynb) - A simple example of the evolutionary optimization framework
129+
- [Example 5.2](https://mybinder.org/v2/gh/neurolib-dev/neurolib/master?filepath=examples%2Fexample-5.2-oc-wc-model-deterministic.ipynb) - Example of optimal control of the noise-free Wilson-Cowan model
123130

124131
A basic overview of the functionality of `neurolib` is also given in the following.
125132

@@ -282,6 +289,31 @@ This will gives us a summary of the last generation and plots a distribution of
282289
<img src="https://github.com/neurolib-dev/neurolib/raw/master/resources/evolution_animated.gif">
283290
</p>
284291

292+
### Optimal control
293+
The optimal control module enables to compute efficient stimulation for your neural model. If you know how your output should look like, this module computes the optimal input. Detailes example notebooks can be found in the [example folder](https://github.com/neurolib-dev/neurolib/tree/master/examples) (examples 5.1, 5.2, 5.3, 5.4). In optimal control computations, you trade precision with respect to a target against control strength. You can determine how much each contribution affects the results, by setting weights accordingly.
294+
295+
To compute an optimal control signal, you need to create a model (e.g., an FHN model) and define a target state (e.g., a sine curve with period 2).
296+
```python
297+
from neurolib.models.fhn import FHNModel
298+
model = FHNModel()
299+
300+
duration = 10.
301+
model.params["duration"] = duration
302+
dt = model.params["dt"]
303+
304+
period = 2.
305+
target = np.sin(2. * np.pi * np.arange(0, duration+dt, dt) / period)
306+
```
307+
You can then create a controlled model and run the iterative optimization to find the most efficient control input. The optimal control and the controlled model activity can be taken from the controlled model.
308+
```python
309+
model_controlled = oc_fhn.OcFhn(model, target)
310+
model_controlled.optimize(500) # run 500 iterations
311+
optimal_control = model_controlled.control
312+
optimal_state = model_controlled.get_xs()
313+
```
314+
315+
For a comprehensive study on optimal control of the Wilson-Cowan model based on the neurolib optimal control module, see Salfenmoser, L. & Obermayer, K. Optimal control of a Wilson–Cowan model of neural population dynamics. Chaos 33, 043135 (2023). https://doi.org/10.1063/5.0144682.
316+
285317
## More information
286318

287319
### Built With
@@ -313,9 +345,11 @@ Cakan, C., Jajcay, N. & Obermayer, K. neurolib: A Simulation Framework for Whole
313345

314346
Caglar Cakan ([email protected])
315347
Department of Software Engineering and Theoretical Computer Science, Technische Universität Berlin, Germany
316-
Bernstein Center for Computational Neuroscience Berlin, Germany
348+
Bernstein Center for Computational Neuroscience Berlin, Germany
317349

318350
### Acknowledgments
319351
This work was supported by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) with the project number 327654276 (SFB 1315) and the Research Training Group GRK1589/2.
320352

353+
The optimal control module was developed by Lena Salfenmoser and Martin Krück supported by the DFG project 163436311 (SFB 910).
354+
321355
<!--end-include-in-documentation-->

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

docs/index.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/example-0-aln-minimal.ipynb

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

examples/example-0.1-hopf-minimal.ipynb

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

examples/example-0.2-basic_analysis.ipynb

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

examples/example-0.3-fhn-minimal.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# The Fitz-Hugh Nagumo oscillator\n",
88
"\n",
9-
"In this notebook, the basic use of the implementation of the Fitz-Hugh Nagumo (`fhn`) model is presented. Usually, the `fhn` model is used to represent a single neuron (for example in `Cakan et al. (2014)`, \"Heterogeneous delays in neural networks\"). This is due to the difference in timescales of the two equations that define the FHN model: The first equation is often referred to as the \"fast variable\" whereas the second one is the \"slow variable\". This makes it possible to create a model with a very fast spiking mechanism but with a slow refractory period. \n",
9+
"In this notebook, the basic use of the implementation of the FitzHugh-Nagumo (`fhn`) model is presented. Usually, the `fhn` model is used to represent a single neuron (for example in `Cakan et al. (2014)`, \"Heterogeneous delays in neural networks\"). This is due to the difference in timescales of the two equations that define the FHN model: The first equation is often referred to as the \"fast variable\" whereas the second one is the \"slow variable\". This makes it possible to create a model with a very fast spiking mechanism but with a slow refractory period. \n",
1010
"\n",
1111
"In our case, we are using a parameterization of the `fhn` model that is not quite as usual. Inspired by the paper by `Kostova et al. (2004)` \"FitzHugh–Nagumo revisited: Types of bifurcations, periodical forcing and stability regions by a Lyapunov functional.\", the implementation in `neurolib` produces a slowly oscillating dynamics and has the advantage to incorporate an external input term that causes a Hopf bifurcation. This means, that the model roughly approximates the behaviour of the `aln` model: For low input values, there is a low-activity fixed point, for intermediate inputs, there is an oscillatory region, and for high input values, the system is in a high-activity fixed point. Thus, it offers a simple way of exploring the dynamics of a neural mass model with these properties, such as the `aln` model.\n",
1212
"\n",

examples/example-0.5-kuramoto.ipynb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"source": [
6464
"# Single node simulation \n",
6565
"\n",
66-
"Here we will simulate a signal node with no noise. We then cap the phase values to be between 0 and 2*pi. We also willo plot the phase values over time."
66+
"Here we will simulate a signal node with no noise. We then cap the phase values to be between 0 and 2*pi. We also will plot the phase values over time."
6767
]
6868
},
6969
{
@@ -117,7 +117,7 @@
117117
"cell_type": "markdown",
118118
"metadata": {},
119119
"source": [
120-
"Here we simulate networks of oscillators. We will simulate a network of 8 oscillators with a global coupling strength 0.3. Here we initialize a connectivity matrix with all-to-all connectivity. We then simulate the network for 30 miliseconds assuming dt is in ms. We will also plot the phase values over time."
120+
"Here we simulate networks of oscillators. We will simulate a network of 8 oscillators with a global coupling strength 0.3. Here we initialize a connectivity matrix with all-to-all connectivity. We then simulate the network for 30 milliseconds assuming dt is in ms. We will also plot the phase values over time."
121121
]
122122
},
123123
{
@@ -222,13 +222,13 @@
222222
"cell_type": "markdown",
223223
"metadata": {},
224224
"source": [
225-
"Now the syncrhonization happens after 7 ms which is faster compared to the previous simulation."
225+
"Now the synchronization happens after 7 ms which is faster compared to the previous simulation."
226226
]
227227
}
228228
],
229229
"metadata": {
230230
"kernelspec": {
231-
"display_name": "kuramoto",
231+
"display_name": "Python 3 (ipykernel)",
232232
"language": "python",
233233
"name": "python3"
234234
},
@@ -242,10 +242,9 @@
242242
"name": "python",
243243
"nbconvert_exporter": "python",
244244
"pygments_lexer": "ipython3",
245-
"version": "3.9.16"
246-
},
247-
"orig_nbformat": 4
245+
"version": "3.8.13"
246+
}
248247
},
249248
"nbformat": 4,
250-
"nbformat_minor": 2
249+
"nbformat_minor": 4
251250
}

0 commit comments

Comments
 (0)