Skip to content

Commit 45cda1c

Browse files
small formatting improvements
1 parent fabac27 commit 45cda1c

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

exercises_text/ni2_forward1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ will yield the same result as:
150150

151151
For this reason, it is custom (and convenient) that leadfields are defined as the spatial topography of the electric potential (EEG) or magnetic field (MEG) due to a unit-amplitude source at a given location and orientation.
152152

153-
In the example above the amplitude information (the value '2') just represented the activity of a source in a single time point. The amplitude term can be very easily extended to contain multiple time points, i.e. to become a vector. Mathematically, this can still be expressed as a matrix multiplication:
153+
In the example above the amplitude information (the value '2') just represented the activity of a source in a single time point. The amplitude term can be very easily extended to contain multiple time points, i.e., to become a vector. Mathematically, this can still be expressed as a matrix multiplication:
154154

155155
leadfield x amplitude time course
156156

exercises_text/ni2_forward2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ After doing these exercises
99
- You understand this very basic equation.
1010
- In particular, you will understand that the sources’ time courses can be 'uncoupled’ from the spatial topographies.
1111

12-
In the previous section it was briefly discussed that the spatial fingerprint of a given (dipolar) source, its leadfield, can be uncoupled from its moment, i.e. the amplitude and orientation. In other words, we can construct for a given location a leadfield matrix (consisting of 3 columns) that defines the spatial topography of a unit amplitude source in the x, y, and z directions. Consequently, we can compute any spatial topography due to a dipole at that location with an arbitrary strength and orientation by right multiplying this leadfield matrix by an appropriate dipole moment vector: `x = L*m`, where m consists of three elements. To take this even further, rather than defining m as a 3x1-vector, m can be defined as a 3xt matrix, where each column represents the dipole moment at a particular time point. If the orientation of the dipole does not change over time, the dipole is said to have a fixed orientation, and the matrix that represents the dipole moment as a function of time can be decomposed into a 3x1-vector representing the orientation (typically normalized to unit length) and a 1xt-vector describing the activation time course of the dipole. In a formula: `y = m*s`. If the orientation of the dipole changes over time, e.g. when the activation is spreading over the crown of a gyrus into the bank of a sulcus, the dipole is said to be a rotating dipole. In that case, the latter simplification is not appropriate.
12+
In the previous section it was briefly discussed that the spatial fingerprint of a given (dipolar) source, its leadfield, can be uncoupled from its moment, i.e., the amplitude and orientation. In other words, we can construct for a given location a leadfield matrix (consisting of 3 columns) that defines the spatial topography of a unit amplitude source in the x, y, and z directions. Consequently, we can compute any spatial topography due to a dipole at that location with an arbitrary strength and orientation by right multiplying this leadfield matrix by an appropriate dipole moment vector: `x = L*m`, where m consists of three elements. To take this even further, rather than defining m as a 3x1-vector, m can be defined as a 3xt matrix, where each column represents the dipole moment at a particular time point. If the orientation of the dipole does not change over time, the dipole is said to have a fixed orientation, and the matrix that represents the dipole moment as a function of time can be decomposed into a 3x1-vector representing the orientation (typically normalized to unit length) and a 1xt-vector describing the activation time course of the dipole. In a formula: `y = m*s`. If the orientation of the dipole changes over time, e.g. when the activation is spreading over the crown of a gyrus into the bank of a sulcus, the dipole is said to be a rotating dipole. In that case, the latter simplification is not appropriate.
1313

1414
Let’s explore these issues in the next exercises. We begin with the construction of some sensor data that measures the activity of a single, fixed orientation dipole. To this end, we first need to compute a leadfield:
1515

@@ -109,7 +109,7 @@ Note that for the MEG situation, the volume conduction model can consist of just
109109
> Describe and explain the differences in topography.
110110
111111
> Explore the effect of the source parameters on the topographies. To this end, you can vary the location of the dipole, as well as the dipole moment. In particular:
112-
- Observe what happens if you change the depth of the dipole, i.e. by moving the position closer to the center of the head.
112+
- Observe what happens if you change the depth of the dipole, i.e., by moving the position closer to the center of the head.
113113
- Observe what happens if the dipole moment has a non-zero radial component, where in the extreme case the orientation is fully radial. See below for some notes with respect to dipole orientation.
114114

115115
> Explore what happens if there is more than one source in the topography. For example, model 2 dipoles with positions [4 0 6] and [-4 0 6] both with a moment [1 0 0], and visualize the combined leadfield. Use matrix multiplication to do the instantaneous mixing.

exercises_text/ni2_inverse3_dipoles.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ In MATLAB this can be done in the following way. We assume a dipole at an arbitr
4444

4545
leadfield = ni2_leadfield(sens, headmodel, [5 5 4]);
4646

47-
Next, we are going to estimate the remainder of the parameters, i.e. the 3 dipole moment parameters, using linear estimation/least-squares regression. In MATLAB this can be easily done using the `\` or backslash operator.
47+
Next, we are going to estimate the remainder of the parameters, i.e., the 3 dipole moment parameters, using linear estimation/least-squares regression. In MATLAB this can be easily done using the `\` or backslash operator.
4848

4949
dipmom = leadfield\topo_observed;
5050

@@ -58,13 +58,13 @@ Now we can quantify the difference between the observed and modelled data, by su
5858

5959
sumsq = sum((topo_observed-topo_modelled).^2)./sum(topo_observed.^2);
6060

61-
The value we have obtained for sumsq does not mean much, unless it is compared to the sumsq obtained for a fitted model with different parameters (i.e. a dipole at another location and or with different orientation).
61+
The value we have obtained for sumsq does not mean much, unless it is compared to the sumsq obtained for a fitted model with different parameters (i.e., a dipole at another location and or with different orientation).
6262

6363
> Model a dipole at location [-5 5 4], estimate the dipole moment given the observed data, and compute the relative sum of squared differences. Compare this to the value obtained above. Is the model fit better or worse?
6464
6565
# 3 Finding the optimal model
6666

67-
Now we know how to model the observed data using the leadfields created for one or more dipoles with a prespecified location, and we know how to quantify the goodness-of-fit between the modelled and observed data. Next, we need to consider the strategies that can be used to find the optimal model. Since the leadfields are non-linear functions of the parameters, there is no easy analytic solution to this problem. Therefore, the implicit strategy is to sample the parameter space, and to quantify for each setting of the parameters the goodness-of-fit. The parameter settings yielding the best model fit are selected. Typically, it does not make sense to just start placing dipoles at random locations and to hope that you will find the model with the best overall fit (out of all possible models. Particularly, when more than one dipole is assumed, the number of potential combinations of locations quickly explodes, and becomes unmanageable. However, in the single dipole case this seems to be a reasonable strategy. Under the assumption that the error landscape (i.e. 1 – goodness-of-fit expressed as a function of dipole location) is relatively smooth, one can sample the total set of possible source locations on a 3-dimensional grid of equally spaced dipole locations, and select the location that yields the smallest error. From this location, one could start a non-linear search to find a final solution.
67+
Now we know how to model the observed data using the leadfields created for one or more dipoles with a prespecified location, and we know how to quantify the goodness-of-fit between the modelled and observed data. Next, we need to consider the strategies that can be used to find the optimal model. Since the leadfields are non-linear functions of the parameters, there is no easy analytic solution to this problem. Therefore, the implicit strategy is to sample the parameter space, and to quantify for each setting of the parameters the goodness-of-fit. The parameter settings yielding the best model fit are selected. Typically, it does not make sense to just start placing dipoles at random locations and to hope that you will find the model with the best overall fit (out of all possible models. Particularly, when more than one dipole is assumed, the number of potential combinations of locations quickly explodes, and becomes unmanageable. However, in the single dipole case this seems to be a reasonable strategy. Under the assumption that the error landscape (i.e., 1 – goodness-of-fit expressed as a function of dipole location) is relatively smooth, one can sample the total set of possible source locations on a 3-dimensional grid of equally spaced dipole locations, and select the location that yields the smallest error. From this location, one could start a non-linear search to find a final solution.
6868
After these exercises
6969

7070
- You will understand the concept of the error function
@@ -74,7 +74,7 @@ To create an error function, one simply needs to repeat multiple times the model
7474

7575
sourcemodel = ni2_sourcemodel('type', 'grid', 'resolution', 1);
7676

77-
As a little aside, this creates a variable in MATLAB that is a so-called structure, which is a special type of variable that is convenient when working with data objects that have multiple attributes, i.e. features that belong together. These features are stored in so-called fields, which contain the actual data. In this example, if you type `sourcemodel` on the command line, you will see:
77+
As a little aside, this creates a variable in MATLAB that is a so-called structure, which is a special type of variable that is convenient when working with data objects that have multiple attributes, i.e., features that belong together. These features are stored in so-called fields, which contain the actual data. In this example, if you type `sourcemodel` on the command line, you will see:
7878

7979
sourcemodel =
8080
pos: [3610x3 double]
@@ -90,7 +90,7 @@ For illustration purposes we will first look at a subset of all positions in thi
9090
sel = find(pos(:, 3)==6);
9191
pos = pos(sel,:);
9292

93-
Now, what we can do is repeat the steps in the previous section for each of these points, i.e. we will model for each of the positions a dipole that optimally explains the observed topography and compute a measure of goodness-of-fit. We store these goodness-of-fit measures in a vector, so that we later can determine which position gave the best fit. Doing the same time multiple times can be easily solved with a for-loop.
93+
Now, what we can do is repeat the steps in the previous section for each of these points, i.e., we will model for each of the positions a dipole that optimally explains the observed topography and compute a measure of goodness-of-fit. We store these goodness-of-fit measures in a vector, so that we later can determine which position gave the best fit. Doing the same time multiple times can be easily solved with a for-loop.
9494

9595
> If you don’t know already about the concept of a for-loop, read a bit about this in the MATLAB-documentation (type ‘help for’ or ‘doc for’ for this purpose).
9696
@@ -109,7 +109,7 @@ Now we have a variable sumsq that is a vector, rather than a single number. We c
109109

110110
> Do this.
111111
112-
We can now look for the position that yields the lowest sum of squared difference values, i.e. the one with the best model fit. We could achieve this by zooming in into the figure and writing down the x-coordinate where the sumsq-variable seems to have the lowest value, but we can also use MATLAB’s min function:
112+
We can now look for the position that yields the lowest sum of squared difference values, i.e., the one with the best model fit. We could achieve this by zooming in into the figure and writing down the x-coordinate where the sumsq-variable seems to have the lowest value, but we can also use MATLAB’s min function:
113113

114114
[m, ix] = min(sumsq);
115115
pos(ix,:)
@@ -216,7 +216,7 @@ The output variable to `ft_dipolefitting` has a field `dip` containing informati
216216
217217
# 6 It’s all about the assumptions
218218

219-
One important issue in dipole modeling is that the prior assumptions critically constrain the final model (and thus the model fit). If these assumptions don’t coincide with what’s actually in the data, this can lead to erroneous interpretations. This can work in two directions, either the model is too simplistic (i.e. you assume too few dipoles), or too complicated (you assume too many dipoles).
219+
One important issue in dipole modeling is that the prior assumptions critically constrain the final model (and thus the model fit). If these assumptions don’t coincide with what’s actually in the data, this can lead to erroneous interpretations. This can work in two directions, either the model is too simplistic (i.e., you assume too few dipoles), or too complicated (you assume too many dipoles).
220220

221221
After these exercises:
222222

@@ -277,6 +277,6 @@ We can also fit a model with two dipoles, this can be easily achieved by changin
277277

278278
> Do this and evaluate the result.
279279
280-
As you may have noticed, the result is not particularly accurate. The reason for this is that the optimization algorithm got trapped in a local minimum of the error function. This is more likely to happen, the more complicated the underlying model (i.e. more free parameters lead to a high-dimensional error function with a complicated structure and potentially many local minima). We can however inform the fitting algorithm with dipole positions from which to start the non-linear search. If these starting positions are sufficiently close to the actual source positions, the algorithm will converge to the correct solution.
280+
As you may have noticed, the result is not particularly accurate. The reason for this is that the optimization algorithm got trapped in a local minimum of the error function. This is more likely to happen, the more complicated the underlying model (i.e., more free parameters lead to a high-dimensional error function with a complicated structure and potentially many local minima). We can however inform the fitting algorithm with dipole positions from which to start the non-linear search. If these starting positions are sufficiently close to the actual source positions, the algorithm will converge to the correct solution.
281281

282282
> Specify `cfg.dip.pos = [4 0 6;-4 0 6]` and verify that the result is now much better.

0 commit comments

Comments
 (0)