Skip to content

Commit a3ff868

Browse files
committed
improved fitting
1 parent ec3fc0c commit a3ff868

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
omit = gridgen/matlab/*

docs/tutorial.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,56 @@ The fitting procedure will run for a while.
410410
Here we specify a very sparse range value (the step value is 5) for quicker computation.
411411

412412
The results show:
413-
413+
- `parameters.json` : summary of the parameters used for the fit
414+
- `results.json` : summary of the results to recompute the grid and fit
415+
- `electrodes.tsv` : electrode locations for the best fit in T1 space
416+
- `electrodes.label` : electrode locations for the best fit for freeview
417+
- `electrodes.fcsv` : electrode locations for the best fit for 3DSlicer
418+
- `projected.html` : interactive plot with electrode locations for the best fit (with ECoG values)
419+
- `morphology.html` : the values for each electrode based on morphology of the pial surface
420+
- `functional.html` : the values for each electrode based on functional MRI
421+
- `merged.html` : the combined values of functional and morphology values
414422

415423
### Brute Force
424+
Compute the model at each combination of the values in the range.
425+
The ranges are specificied with [`start point`, `step size`, `end point`].
426+
It runs in parallel and at the end it runs the simplex method as well (for increased accuracy).
427+
428+
```json
429+
"fit": {
430+
"method": "brute",
431+
"ranges": {
432+
"x": [-10, 1, 10],
433+
"y": [-10, 1, 10],
434+
"rotation": [-10, 1, 10]
435+
}
436+
}
437+
```
416438

417-
### Nelder-Mead
439+
### Simplex (Nelder-Mead)
440+
Fitting procedure is based on the [Nelder-Mead method](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method).
441+
You should specify the step sizes in each direction, then it computes the value at each node of the simplex:
418442

419443
![nelder-mead method](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Nelder-Mead_Rosenbrock.gif/240px-Nelder-Mead_Rosenbrock.gif)
420444

445+
446+
You should specify the size of the simplex in each direction with `steps`:
447+
```json
448+
"fit": {
449+
"method": "simplex",
450+
"steps": {
451+
"x": 5,
452+
"y": 5,
453+
"rotation": 4
454+
}
455+
}
456+
```
457+
458+
There are no bounds, so it can get out of the start position, if it can find a better fit.
459+
It's a good idea to run:
460+
461+
```bash
462+
gridgen --log debug parameters.json grid2d
463+
```
464+
465+
So that you see the steps and values computed at each node of the simplex.

gridgen/bin/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@
185185
"type": "str",
186186
"necessary": False,
187187
"values": ['gaussian', 'sphere', 'inverse'],
188-
"help": "TODO",
188+
"help": "method to compute the value at each electrode. `sphere` is the sum of the voxels around the electrodes, within `kernel` distance. `gaussian` is the weighted average of the voxels around an electrode, weighted by a 3d gaussian kernel. With `inverse`, the weights are based on the inverse of the distance.",
189189
"default": "inverse",
190190
},
191191
"kernel": {
192192
"type": "float",
193193
"necessary": False,
194-
"help": "TODO",
194+
"help": "With method `sphere`, this is the size of the sphere. With method `gaussian`, this is the size of the sigma of the 3D weighting kernel. With method `inverse`, this is the exponent (1 -> linear, 2 -> quadratic).",
195195
"default": 2,
196196
},
197197
},

gridgen/fitting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ def fitting_brute(func, args):
157157
ranges[k][1] += ranges[k][2]
158158

159159
ranges = (
160-
slice(ranges['x']),
161-
slice(ranges['y']),
162-
slice(ranges['rotation']),
160+
slice(*ranges['x']),
161+
slice(*ranges['y']),
162+
slice(*ranges['rotation']),
163163
)
164164

165165
if mkl is not None:

0 commit comments

Comments
 (0)