| 1 |
+++ |
| 2 |
title = "GISAS 2D fits" |
| 3 |
weight = 20 |
| 4 |
+++ |
| 5 |
|
| 6 |
# Fitting GISAS in 2D |
| 7 |
|
| 8 |
This example demonstrates fitting of 2D GISAS data. |
| 9 |
|
| 10 |
## Fit script |
| 11 |
|
| 12 |
The fit script shown and discussed below displays its progress visually, |
| 13 |
and terminates with the following result: |
| 14 |
|
| 15 |
{{< galleryscg >}} |
| 16 |
{{< figscg src="/files/fitted/gisas2d_1.png" width="800px" caption="Fit window">}} |
| 17 |
{{< /galleryscg >}} |
| 18 |
|
| 19 |
{{< show-ex file="fit/scatter2d/fit2d.py" >}} |
| 20 |
|
| 21 |
|
| 22 |
### Explanation |
| 23 |
|
| 24 |
The function `get_sample` is basically the same as |
| 25 |
in our [basic GISAS simulation example](/ref/sim/class/scattering/ex/gisas), |
| 26 |
except that radius and height of the cylindrical disks are now |
| 27 |
supplied as external parameters. |
| 28 |
These parameters are passed through the function argument `params` |
| 29 |
which can be either a Python dict, |
| 30 |
or an instance of the BornAgain class `Parameters`. |
| 31 |
|
| 32 |
The function `get_simulation` has the same function argument `params`, |
| 33 |
from which it takes beam intensity and background level. |
| 34 |
These two parameters are on a logarithmic scale. |
| 35 |
|
| 36 |
The function `start_parameters_1` is supplied along with the model |
| 37 |
in order to facilitate the benchmarking of different fith methods. |
| 38 |
|
| 39 |
The `FitObjective` created here is used to put into correspondence the real data, |
| 40 |
represented by a numpy array, and the simulation, represented by the `get_simulation` callable. |
| 41 |
On every fit iteration `FitObjective` |
| 42 |
|
| 43 |
+ will generate a new simulation object |
| 44 |
for a given set of fit parameter values using the `get_simulation` callable, |
| 45 |
+ run it to obtain simulated detector intensities, |
| 46 |
+ calculate $\chi^2$ between simulated and real data. |
| 47 |
|
| 48 |
The method `fit_objective.evaluate` provided by the `FitObjective` class interface is used here as an objective function. |
| 49 |
The method accepts fit parameters and returns the $\chi^2$ value, |
| 50 |
calculated between experimental and simulated images for the given values of the fit parameters. |
| 51 |
|
| 52 |
The method is passed to the minimizer together with the initial fit parameter values. |
| 53 |
The `minimizer.minimize` starts a fit that will |
| 54 |
continue further without user intervention until the minimum |
| 55 |
is found or the minimizer failed to converge. |
| 56 |
The rest of the code demonstrates how to access the fit results. |