source: sasview/src/sas/qtgui/Perspectives/Fitting/media/fitting_help.rst @ 8e674ccf

Last change on this file since 8e674ccf was dbba134, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

More fitting help updates - SASVIEW-917

  • Property mode set to 100755
File size: 31.6 KB
RevLine 
[ec392464]1.. fitting_help.rst
2
3.. This is a port of the original SasView html help file to ReSTructured text
4.. by S King, ISIS, during SasView CodeCamp-III in Feb 2015.
5
[b64b87c]6Fitting
7=======
[ec392464]8
[3e1c9e5]9.. note:: If some code blocks are not readable, expand the documentation window
10
[a6f3613]11.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
12
13Preparing to fit data
14---------------------
15
16To fit some data you must first load some data, activate one or more data sets,
[b64b87c]17send those data sets to fitting, and select a model to fit to each data set.
[a6f3613]18
[f3377b8]19Instructions on how to load and activate data are in the section :ref:`Loading_data`.
[ec392464]20
[a6f3613]21SasView can fit data in one of three ways:
[ec392464]22
[a6f3613]23*  in *Single* fit mode - individual data sets are fitted independently one-by-one
[ec392464]24
[5295cf5]25*  in *Simultaneous* fit mode - multiple data sets are fitted simultaneously to
26   the *same* model with/without constrained parameters (this might be useful,
27   for example, if you have measured the same sample at different contrasts)
[ec392464]28
[5005ae0]29*  in *Batch* fit mode - multiple data sets are fitted sequentially to the
30   *same* model (this might be useful, for example, if you have performed
31   a kinetic or time-resolved experiment and have *lots* of data sets!)
[a6f3613]32
33.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
[ec392464]34
[a6f3613]35Selecting a model
36-----------------
[ec392464]37
[5295cf5]38The models in SasView are grouped into categories. By default these consist of:
[ec392464]39
[5295cf5]40*  *Cylinder* - cylindrical shapes (disc, right cylinder, cylinder with endcaps
41   etc)
42*  *Ellipsoid* - ellipsoidal shapes (oblate,prolate, core shell, etc)
43*  *Parellelepiped* - as the name implies
44*  *Sphere* - sheroidal shapes (sphere, core multishell, vesicle, etc)
45*  *Lamellae* - lamellar shapes (lamellar, core shell lamellar, stacked
46   lamellar, etc)
[5005ae0]47*  *Shape-Independent* - models describing structure in terms of density
48   correlation functions, fractals, peaks, power laws, etc
[5295cf5]49*  *Paracrystal* - semi ordered structures (bcc, fcc, etc)
[a6f3613]50*  *Structure Factor* - S(Q) models
[5295cf5]51*  *Plugin Models* - User-created (custom/non-library) Python models
[ec392464]52
[a6f3613]53Use the *Category* drop-down menu to chose a category of model, then select
[b31b7e2]54a model from the drop-down menu to the right. The "Show Plot" button on the
55bottom of the dialog will become active. If you click on it,
56a graph of the chosen model, calculated using default parameter values, will appear.
57The graph will update dynamically as the parameter values are changed.
[f3377b8]58
[dbba134]59.. TODO: uncomment after Category_Manager done
60.. You can decide your own model categorizations using the :ref:`Category_Manager`.
[ce62e75]61
[b31b7e2]62Once you have selected a model you can read its help documentation by right clicking
63on the empty space in the parameter table.
64
65.. image:: descr_fig.png
[a6f3613]66
67Show 1D/2D
68^^^^^^^^^^
69
70Models are normally fitted to 1D (ie, I(Q) vs Q) data sets, but some models in
71SasView can also be fitted to 2D (ie, I(Qx,Qy) vs Qx vs Qy) data sets.
72
73*NB: Magnetic scattering can only be fitted in SasView in 2D.*
74
[b31b7e2]75To activate 2D fitting mode, select the *2D view* checkbox on the *Fit Page*. To
76return to 1D fitting model, de-select the same checkbox.
[ce62e75]77
[ec392464]78.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
79
[dbba134]80.. TODO: uncomment after Category_Manager done
81..
82  .. _Category_Manager:
[a6f3613]83
[dbba134]84  Category Manager
85  ----------------
[a6f3613]86
[dbba134]87  To change the model categorizations, either choose *Category Manager* from the
88  *View* option on the menubar, or click on the *Modify* button on the *Fit Page*.
[a6f3613]89
[dbba134]90  .. image:: cat_fig0.png
[a6f3613]91
[dbba134]92  The categorization of all models except the user supplied Plugin Models can be
93  reassigned, added to, and removed using *Category Manager*. Models can also be
94  hidden from view in the drop-down menus.
[a6f3613]95
[dbba134]96  .. image:: cat_fig1.png
[a6f3613]97
[dbba134]98  Changing category
99  ^^^^^^^^^^^^^^^^^
[a6f3613]100
[dbba134]101  To change category, highlight a model in the list by left-clicking on its entry
102  and then click the *Modify* button. Use the *Change Category* panel that appears
103  to make the required changes.
[a6f3613]104
[dbba134]105  .. image:: cat_fig2.png
[a6f3613]106
[dbba134]107  To create a category for the selected model, click the *Add* button. In order
108  to delete a category, select the category name and click the *Remove Selected*
109  button. Then click *Done*.
[a6f3613]110
[dbba134]111  Showing/hiding models
112  ^^^^^^^^^^^^^^^^^^^^^
[a6f3613]113
[dbba134]114  Use the *Enable All / Disable All* buttons and the check boxes beside each model
115  to select the models to show/hide. To apply the selection, click *Ok*. Otherwise
116  click *Cancel*.
[a6f3613]117
[dbba134]118  *NB: It may be necessary to change to a different category and then back again*
119  *before any changes take effect.*
120..
[a6f3613]121.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
122
[f3377b8]123Model Functions
124---------------
[a6f3613]125
[5295cf5]126For a complete list of all the library models available in SasView, see
127the `Model Documentation <../../../index.html>`_ .
[a6f3613]128
[f3377b8]129It is also possible to add your own models.
[a6f3613]130
[f3377b8]131.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
[a6f3613]132
[b5846a10]133.. _Adding_your_own_models:
134
[3e1c9e5]135Adding your own Models
[f3377b8]136----------------------
[a6f3613]137
[3e1c9e5]138There are essentially three ways to generate new fitting models for SasView:
139
[5295cf5]140*  Using the SasView :ref:`New_Plugin_Model` helper dialog (best for beginners
141   and/or relatively simple models)
142*  By copying/editing an existing model (this can include models generated by
[5005ae0]143   the New Plugin Model* dialog) in the :ref:`Python_shell` or
[b31b7e2]144   :ref:`Plugin_Editor` (suitable for all use cases)
[5295cf5]145*  By writing a model from scratch outside of SasView (only recommended for code
146   monkeys!)
[3e1c9e5]147
148Please read the guidance on :ref:`Writing_a_Plugin` before proceeding.
[f3377b8]149
[3e1c9e5]150**To be found by SasView your model must reside in the *~\\.sasview\\plugin_models* folder.**
[f3377b8]151
[a6f3613]152.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
153
[3e1c9e5]154.. _Plugin_Model_Operations:
[f3377b8]155
[3e1c9e5]156Plugin Model Operations
157-----------------------
[a6f3613]158
[b31b7e2]159From the *Fitting* option in the menu bar, select one of the options:
[a6f3613]160
[82b0b05e]161.. image:: edit_model_menu.png
[a6f3613]162
[b31b7e2]163*  *Add Custom Model* - to create a plugin model template with a helper dialog
164*  *Edit Custom Model* - to edit a plugin model in an editor window
165*  *Manage Custom Models* - to open a custom model manager allowing for a number of actions to be taken on custom models: listing, adding, deleteing, duplicating, editing
166*  *Add/Multiply Models* - to create a plugin model by summing/multiplying *existing models* in the model library
[a6f3613]167
[3e1c9e5]168.. _New_Plugin_Model:
169
[b31b7e2]170Add Custom Model
[3e1c9e5]171^^^^^^^^^^^^^^^^
[a6f3613]172
[5295cf5]173Relatively straightforward models can be programmed directly from the SasView
[b31b7e2]174GUI using the *Plugin Definition* Function.
[26c8be3]175
[6aad2e8]176.. image:: new_model.png
[a6f3613]177
[5005ae0]178When using this feature, be aware that even if your code has errors, including
179syntax errors, a model file is still generated. When you then correct the errors
180and click 'Apply' again to re-compile you will get an error informing you that
181the model already exists if the 'Overwrite' box is not checked. In this case you
182will need to supply a new model function name. By default the 'Overwrite' box is
[26c8be3]183*checked*\ .
[f3377b8]184
[5295cf5]185Also note that the 'Fit Parameters' have been split into two sections: those
186which can be polydisperse (shape and orientation parameters) and those which are
187not (eg, scattering length densities).
[26c8be3]188
189A model file generated by this option can be viewed and further modified using
[b31b7e2]190the :ref:`Model_Editor`.
[05829fb]191
[5005ae0]192**SasView version 4.2** made it possible to specify whether a plugin created with
193the *New Plugin Model* dialog is actually a form factor P(Q) or a structure factor
194S(Q). To do this, simply add one or other of the following lines under the *import*
[f485ba0]195statements.
196
197For a form factor::
198
199     form_factor = True
[5005ae0]200
[f485ba0]201or for a structure factor::
202
203     structure_factor = True
[5005ae0]204
205If the plugin is a structure factor it is *also* necessary to add two variables to
[f485ba0]206the parameter list::
207
[5005ae0]208     parameters = [
[ca383a0]209                     ['radius_effective', '', 1, [0.0, numpy.inf], 'volume', ''],
210                     ['volfraction', '', 1, [0.0, 1.0], '', ''],
[e081946]211                     [...],
[f485ba0]212
213and to the declarations of the functions Iq and Iqxy:::
214
215     def Iq(x , radius_effective, volfraction, ...):
216
217     def Iqxy(x, y, radius_effective, volfraction, ...):
218
[5005ae0]219Such a plugin should then be available in the S(Q) drop-down box on a FitPage (once
[f485ba0]220a P(Q) model has been selected).
221
[b31b7e2]222
223.. Model_Editor:
224
225Model Editor
226^^^^^^^^^^^^
227
228Selecting "Edit Custom Model" option opens the editor window.
229
230.. image :: model_editor_empty.png
231
232Initially, the editor is empty. A custom model can be loaded by clicking on the *Load plugin...* button and choosing one of the existing custom plugins.
233
234Once the model is loaded, it can be edited and saved with *Save* button.
235Saving the model will perform the validation and only when the model is correct it will be saved to a file.
236Successful model check is indicated by a SasView status bar message.
237
238When *Cancel* is clicked, any changes to the model are discarded and the window is closed.
239
240
241For details of the SasView plugin model format see :ref:`Writing_a_Plugin` .
242
243To use the model, go to the relevant *Fit Page*, select the *Plugin Models*
244category and then select the model from the drop-down menu.
245
246
247.. Plugin_Manager:
248
249Plugin Manager
250^^^^^^^^^^^^^^
251
252Selecting the *Manage Custom Models* option shows a list of all the plugin models in the plugin model folder, on Windows this is
253
254  *C:\\Users\\{username}\\.sasview\\plugin_models*
255
256You can add, edit, duplicate and delete these models using buttons on the right side of the list.
257
258.. image:: plugin_manager.png
259
260
261Add a model
262^^^^^^^^^^^
263
264Clicking the "Add" button opens the Model Editor window, allowing you to create a new plugin as described above.
265
266Duplicate a model
267^^^^^^^^^^^^^^^^^
268
269Clicking the "Duplicate" button will create a copy of the selected model(s). Naming of the duplicate follows the standard, with added * (n)* to the plugin model name, with *n* being the first unused yet integer.
270
271Edit a model
272^^^^^^^^^^^^
273
274When a single model is selected, clicking this button will open the Advanced *Model Editor* allowing you to edit the
275Python code of the model.
276If no models or multiple models are selected, the *Edit* button is disabled.
277
278Delete Plugin Models
279^^^^^^^^^^^^^^^^^^^^
280
281Simply highlight the plugin model(s) to be removed and click on the "Delete" button. The operation is final.
282
283*NB: Models shipped with SasView cannot be removed in this way.*
284
285
286Add/Multiply Models
287^^^^^^^^^^^^^^^^^^^
[a6f3613]288
[6aad2e8]289.. image:: sum_model.png
[a0637de]290
[5295cf5]291This option creates a custom Plugin Model of the form::
[f3377b8]292
[5295cf5]293     Plugin Model = scale_factor * {(scale_1 * model_1) +/- (scale_2 * model_2)} + background
[f3377b8]294
[3e1c9e5]295or::
296
[f485ba0]297     Plugin Model = scale_factor * (model1 * model2) + background
[3e1c9e5]298
[b31b7e2]299In the *Add/Multiply Models* give the new model a function name and brief
[3e1c9e5]300description (to appear under the *Details* button on the *FitPage*). Then select
[b31b7e2]301two existing models, as model_1 and model_2, and the required operator, '+' or '*' between
[f485ba0]302them. Finally, click the *Apply* button to generate and test the model and then click *Close*.
[f3377b8]303
[f485ba0]304
[5005ae0]305**SasView version 4.2** introduced a much simplified and more extensible structure for plugin models
[b31b7e2]306generated through the Add/Multiply Models editor. For example, the code for a combination of a sphere model
[f485ba0]307with a power law model now looks like this::
308
309     from sasmodels.core import load_model_info
310     from sasmodels.sasview_model import make_model_from_info
[5005ae0]311
[f485ba0]312     model_info = load_model_info('sphere+power_law')
[e081946]313     model_info.name = 'MyPluginModel'
[f485ba0]314     model_info.description = 'sphere + power_law'
315     Model = make_model_from_info(model_info)
316
[5005ae0]317To change the models or operators contributing to this plugin it is only necessary to edit the string
318in the brackets after *load_model_info*, though it would also be a good idea to update the model name
[f485ba0]319and description too!!!
320
[5005ae0]321The model specification string can handle multiple models and combinations of operators (+ or *) which
322are processed according to normal conventions. Thus 'model1+model2*model3' would be valid and would
323multiply model2 by model3 before adding model1. In this example, parameters in the *FitPage* would be
324prefixed A (for model2), B (for model3) and C (for model1). Whilst this might appear a little
325confusing, unless you were creating a plugin model from multiple instances of the same model the parameter
[e081946]326assignments ought to be obvious when you load the plugin.
[f485ba0]327
[5005ae0]328If you need to include another plugin model in the model specification string, just prefix the name of
[e081946]329that model with *custom*. For instance::
330
331     sphere+custom.MyPluginModel
332
333To create a P(Q)*\S(Q) model use the @ symbol instead of * like this::
334
335     sphere@hardsphere
[5005ae0]336
337This streamlined approach to building complex plugin models from existing library models, or models
338available on the *Model Marketplace*, also permits the creation of P(Q)*\S(Q) plugin models, something
339that was not possible in earlier versions of SasView.
[f3377b8]340
341
[afb93df]342
[ec392464]343.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
344
[4666660]345.. _Fitting_Options:
346
[b31b7e2]347Fit Algorithms
[f3377b8]348---------------
[a6f3613]349
[f3377b8]350It is possible to specify which optimiser SasView should use to fit the data, and
351to modify some of the configurational parameters for each optimiser.
352
[b31b7e2]353From *Fitting* in the menu bar select *Fit Algorithms*, then select one of the following
[f3377b8]354optimisers:
[a6f3613]355
[f3377b8]356*  DREAM
357*  Levenberg-Marquardt
358*  Quasi-Newton BFGS
359*  Differential Evolution
360*  Nelder-Mead Simplex
[a6f3613]361
[b31b7e2]362.. image:: fit_algorithms.png
363
[6af2785]364The DREAM optimiser is the most sophisticated, but may not necessarily be the best
365option for fitting simple models. If uncertain, try the Levenberg-Marquardt optimiser
366initially.
367
[f3377b8]368These optimisers form the *Bumps* package written by P Kienzle. For more information
[4666660]369on each optimiser, see the :ref:`Fitting_Documentation`.
[a6f3613]370
[f3377b8]371.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
[a6f3613]372
[5ac0a7a]373Fitting Limits
374--------------
375
376By default, *SasView* will attempt to model fit the full range of the data; ie,
377across all *Q* values. If necessary, however, it is possible to specify only a
378sub-region of the data for fitting.
379
[b31b7e2]380In a *FitPage* or *BatchPage* change the tab to *Fit Options* and then change
381the *Q* values in the *Min* and/or *Max*
382text boxes.
383
384..
385  Vertical coloured bars will appear on the graph with the data and
386  'theory' indicating the current *Q* limits (red = *Qmin*, purple = *Qmax*).
[5ac0a7a]387
388To return to including all data in the fit, click the *Reset* button.
389
390.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
391
[b31b7e2]392..
[5ac0a7a]393
[b31b7e2]394  Shortcuts
395  ---------
[a6f3613]396
[b31b7e2]397  Copy/Paste Parameters
398  ^^^^^^^^^^^^^^^^^^^^^
[a6f3613]399
[b31b7e2]400  It is possible to copy the parameters from one *Fit Page* and to paste them into
401  another *Fit Page* using the same model.
[a6f3613]402
[b31b7e2]403  To *copy* parameters, either:
[a6f3613]404
[b31b7e2]405  *  Select *Edit -> Copy Params* from the menu bar, or
406  *  Use Ctrl(Cmd on Mac) + Left Mouse Click on the *Fit Page*.
[a6f3613]407
[b31b7e2]408  To *paste* parameters, either:
[f3377b8]409
[b31b7e2]410  *  Select *Edit -> Paste Params* from the menu bar, or
411  *  Use Ctrl(Cmd on Mac) + Shift + Left-click on the *Fit Page*.
[f3377b8]412
[b31b7e2]413  If either operation is successful a message will appear in the info line at the
414  bottom of the SasView window.
[f3377b8]415
[b31b7e2]416  Bookmark
417  ^^^^^^^^
[a6f3613]418
[b31b7e2]419  To *Bookmark* a *Fit Page* either:
[a6f3613]420
[b31b7e2]421  *  Select a *Fit Page* and then click on *Bookmark* in the tool bar, or
422  *  Right-click and select the *Bookmark* in the popup menu.
[a6f3613]423
424.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
425
[4666660]426.. _Status_bar:
427
[b31b7e2]428Status Bar & Log Explorer
429-------------------------
[1fda506]430
431The status bar is located at the bottom of the SasView window and displays
[b31b7e2]432messages, warnings and errors.
[1fda506]433
[b31b7e2]434.. image:: log_explorer.png
[1fda506]435
[b31b7e2]436The bottom part of the SasView application window contains the *Log Explorer*.
437The *Log Explorer* displays available message history and run-time traceback information.
[1fda506]438
439.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
440
[6af2785]441.. _Single_Fit_Mode:
442
[a6f3613]443Single Fit Mode
444---------------
[ec392464]445
[b31b7e2]446*NB: Before proceeding, ensure that the Batch mode checkbox at the bottom of*
447*the Data Explorer is unchecked (see the section* :ref:`Loading_data` *).*
[4666660]448
[63d314b]449This mode fits one data set.
450
[b31b7e2]451.. When data is sent to the fitting it is plotted in a graph window as markers.
452When data is sent to the fitting, the Fit Page will show the dataset name.
453
454.. image:: dataset_name.png
455
456Clicking on the *Show Plot* will cause the data can be plotted in a graph window as markers.
[4666660]457
458If a graph does not appear, or a graph window appears but is empty, then the data
459has not loaded correctly. Check to see if there is a message in the :ref:`Status_Bar`
460or in the *Console* window.
461
[b31b7e2]462Assuming the data has loaded correctly, when a model is selected a blue model
[4666660]463calculation (or what SasView calls a 'Theory') line will appear in the earlier graph
464window, and a second graph window will appear displaying the residuals (the
465difference between the experimental data and the theory) at the same X-data values.
[f9250dc]466See :ref:`Assessing_Fit_Quality`.
[4666660]467
468The objective of model-fitting is to find a *physically-plausible* model, and set
469of model parameters, that generate a theory that reproduces the experimental data
470and gives residual values as close to zero as possible.
471
472Change the default values of the model parameters by hand until the theory line
473starts to represent the experimental data. Then uncheck the tick boxes alongside
474all parameters *except* the 'background' and the 'scale'. Click the *Fit* button.
475SasView will optimise the values of the 'background' and 'scale' and also display
476the corresponding uncertainties on the optimised values.
477
478*NB: If no uncertainty is shown it generally means that the model is not very*
479*dependent on the corresponding parameter (or that one or more parameters are*
480*'correlated').*
481
[b31b7e2]482In the bottom right corner of the *Fit Page* is a box displaying the normalised value
[5ed76f8]483of the statistical $\chi^2$ parameter returned by the optimiser.
[4666660]484
485Now check the box for another model parameter and click *Fit* again. Repeat this
486process until most or all parameters are checked and have been optimised. As the
487fit of the theory to the experimental data improves the value of 'chi2/Npts' will
488decrease. A good model fit should easily produce values of 'chi2/Npts' that are
[5ed76f8]489close to one, and certainly <100. See :ref:`Assessing_Fit_Quality`.
[4666660]490
491SasView has a number of different optimisers (see the section :ref:`Fitting_Options`).
492The DREAM optimiser is the most sophisticated, but may not necessarily be the best
493option for fitting simple models. If uncertain, try the Levenberg-Marquardt optimiser
494initially.
[ec392464]495
496.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
497
[a6f3613]498Simultaneous Fit Mode
499---------------------
[ec392464]500
[63d314b]501*NB: Before proceeding, ensure that the Single Mode radio button at the bottom of*
502*the Data Explorer is checked (see the section* :ref:`Loading_data` *).*
[ec392464]503
[6af2785]504This mode is an extension of the :ref:`Single_Fit_Mode` that fits two or more data
[5005ae0]505sets *to the same model* simultaneously. If necessary it is possible to constrain
[63d314b]506fit parameters between data sets (eg, to fix a background level, or radius, etc).
507
[b5846a10]508If the data to be fit are in multiple files, load each file, then select each file
509in the *Data Explorer*, and *Send To Fitting*. If multiple data sets are in one file,
510load that file, *Unselect All Data*, select just those data sets to be fitted, and
511*Send To Fitting*. Either way, the result should be that for *n* data sets you have
[6af2785]5122\ *n* graphs (*n* of the data and model fit, and *n* of the resulting residuals). But
[f9250dc]513it may be helpful to minimise the residuals plots for clarity. Also see
514:ref:`Assessing_Fit_Quality`.
[b5846a10]515
[5295cf5]516*NB: If you need to use a custom Plugin Model, you must ensure that model is
517available first (see* :ref:`Adding_your_own_models` *).*
[b5846a10]518
[6af2785]519Method
520^^^^^^
521
[b5846a10]522Now go to each *FitPage* in turn and:
523
524  Select the required category and model;
525
526  Unselect all the model parameters;
527
528  Enter some starting guesses for the parameters;
529
530  Enter any parameter limits (recommended);
[63d314b]531
[b5846a10]532  Select which parameters will refine (selecting all is generally a bad idea...);
[63d314b]533
[b5846a10]534When done, select *Constrained or Simultaneous Fit* under *Fitting* in the menu bar.
535
536In the *Const & Simul Fit* page that appears, select which data sets are to be
537simultaneously fitted (this will probably be all of them or you would not have loaded
538them in the first place!).
539
[dbba134]540.. image:: constraint_1.png
541
542To tie parameters between the data sets with constraints, select the data sets and right click.
543From the menu choose *Mutual constraint of parameters in selected models*
[b5846a10]544
[dbba134]545.. image:: constraint_2.png
[b5846a10]546
547When ready, click the *Fit* button on the *Const & Simul Fit* page, NOT the *Fit*
548button on the individual *FitPage*'s.
[63d314b]549
550Simultaneous Fits without Constraints
551^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ec392464]552
[b5846a10]553The results of the model-fitting will be returned to each of the individual
554*FitPage*'s.
[ec392464]555
[b5846a10]556Note that the chi2/Npts value returned is the SUM of the chi2/Npts of each fit. To
[6af2785]557see the chi2/Npts value for a specific *FitPage*, click the *Compute* button at the
[f9250dc]558bottom of that *FitPage* to recalculate. Also see :ref:`Assessing_Fit_Quality`.
[ec392464]559
[63d314b]560Simultaneous Fits with Constraints
561^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ec392464]562
[dbba134]563In the *Const. & Simul. Fit* page select two data sets which are to be constrained.
564Right clicking in the *Source choice for simultaneous fitting* area will bring up
565the context menu:
566
567.. image:: constraint_2.png
568
569Here you can choose datasets for fitting and define constraints between parameters in
570both datasets.
571
572Selecting this option will bring up the *Complex Constraint* dialog.
573
574.. image:: complex_constraint.png
[b5846a10]575
[6af2785]576Constraints will generally be of the form
577
578  Mi Parameter1 = Mj.Parameter1
579
580however the text box after the '=' sign can be used to adjust this
581relationship; for example
582
583  Mi Parameter1 = scalar \* Mj.Parameter1
584
585A 'free-form' constraint box is also provided.
[b5846a10]586
587Many constraints can be entered for a single fit.
588
589The results of the model-fitting will be returned to each of the individual
590*FitPage*'s.
[ec392464]591
[b5846a10]592Note that the chi2/Npts value returned is the SUM of the chi2/Npts of each fit. To
[6af2785]593see the chi2/Npts value for a specific *FitPage*, click the *Compute* button at the
[f9250dc]594bottom of that *FitPage* to recalculate. Also see :ref:`Assessing_Fit_Quality`.
[ec392464]595
596.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
597
[e6c74e8]598.. _Batch_Fit_Mode:
599
[a6f3613]600Batch Fit Mode
601--------------
[ec392464]602
[6af2785]603*NB: Before proceeding, ensure that the Single Mode radio button at the bottom of*
604*the Data Explorer is checked (see the section* :ref:`Loading_data` *). The Batch*
605*Mode button will be used later on!*
[63d314b]606
[6af2785]607This mode *sequentially* fits two or more data sets *to the same model*. Unlike in
608simultaneous fitting, in batch fitting it is not possible to constrain fit parameters
609between data sets.
[ec392464]610
[6af2785]611If the data to be fit are in multiple files, load each file in the *Data Explorer*.
612If multiple data sets are in one file, load just that file. *Unselect All Data*, then
613select a single initial data set to be fitted. Fit that selected data set as described
[5295cf5]614above under :ref:`Single_Fit_Mode`.
[ec392464]615
[5295cf5]616*NB: If you need to use a custom Plugin Model, you must ensure that model is
617available first (see* :ref:`Adding_your_own_models` *).*
[ec392464]618
[6af2785]619Method
620^^^^^^
[ec392464]621
[6af2785]622Now *Select All Data* in the *Data Explorer*, check the *Batch Mode* radio button
623at the bottom of that panel and *Send To Fitting*. A *BatchPage* will be created.
[ec392464]624
[6aad2e8]625.. image:: batch_button_area.png
[ec392464]626
[6af2785]627*NB: The Batch Page can also be created by checking the Batch Mode radio button*
628*and selecting New Fit Page under Fitting in the menu bar.*
[ec392464]629
[6af2785]630Using the drop-down menus in the *BatchPage*, now set up the *same* data set
631with the *same* model that you just fitted in single fit mode. A quick way to
632set the model parameter values is to just copy them from the earlier Single
633Fit. To do this, go back to the Single Fit *FitPage*, select *Copy Params*
634under *Edit* in the menu bar, then go back to the *BatchPage* and *Paste Params*.
[ec392464]635
[6af2785]636When ready, use the *Fit* button on the *BatchPage* to perform the fitting, NOT
637the *Fit* button on the individual *FitPage*'s.
[ec392464]638
[6af2785]639Unlike in single fit mode, the results of batch fits are not returned to
640the *BatchPage*. Instead, a spreadsheet-like :ref:`Grid_Window` will appear.
[ec392464]641
[6af2785]642If you want to visually check a graph of a particular fit, click on the name of
643a *Data set* in the *Grid Window* and then click the *View Fits* button. The
644data and the model fit will be displayed. If you select mutliple data sets they
645will all appear on one graph.
[ec392464]646
[6aad2e8]647.. image:: view_button.png
[ec392464]648
[6af2785]649*NB: In theory, returning to the BatchPage and changing the name of the I(Q)*
650*data source should also work, but at the moment whilst this does change the*
651*data set displayed it always superimposes the 'theory' corresponding to the*
652*starting parameters.*
[ec392464]653
[6af2785]654If you select a 'Chi2' value and click the *View Fits* button a graph of the
655residuals for that data set is displayed. Again, if you select multiple 'Chi2'
[f9250dc]656values then all the residuals data will appear on one graph. Also see
657:ref:`Assessing_Fit_Quality`.
[ec392464]658
[6af2785]659Chain Fitting
660^^^^^^^^^^^^^
[ec392464]661
[6af2785]662By default, the *same* parameter values copied from the initial single fit into
663the *BatchPage* will be used as the starting parameters for all batch fits. It
664is, however, possible to get *SasView* to use the results of a fit to a preceding
665data set as the starting parameters for the next fit in the sequence. This
666variation of batch fitting is called *Chain Fitting*, and will considerably speed
667up model-fitting if you have lots of very similar data sets where a few parameters
668are gradually changing. Do not use chain fitting on disparate data sets.
[ec392464]669
[6af2785]670To use chain fitting, select *Chain Fitting* under *Fitting* in the menu bar. It
671toggles on/off, so selecting it again will switch back to normal batch fitting.
[ec392464]672
[6af2785]673.. _Grid_Window:
[ec392464]674
[6af2785]675Grid Window
676^^^^^^^^^^^
[ec392464]677
[6af2785]678The *Grid Window* provides an easy way to view the results from batch fitting.
679It will be displayed automatically when a batch fit completes, but may be
680opened at any time by selecting *Show Grid Window* under *View* in the menu
681bar.
[ec392464]682
[6aad2e8]683.. image:: restore_batch_window.png
[ec392464]684
[dbba134]685..
686  Once a batch fit is completed, all model parameters are displayed but *not*
687  their uncertainties. To view the uncertainties, click on a given column then
688  go to *Edit* in the menu bar, select *Insert Column Before* and choose the
689  required data from the list. An empty column can be inserted in the same way.
[ec392464]690
691
[dbba134]692  To remove a column from the grid, click on the column header and choose
693  *Remove Column* under *Edit* in the menu bar. The same functionality also
694  allows you to re-order columns.
[ec392464]695
[dbba134]696  *NB: You cannot insert/remove/re-order the rows in the Grid Window.*
[ec392464]697
[dbba134]698  All of the above functions are also available by right-clicking on a column
699  label.
[ec392464]700
[dbba134]701  .. image:: edit_menu.png
702..
703
704If there is an existing Grid Window and another batch fit is performed,*
[6af2785]705*an additional 'Table' tab will be added to the Grid Window.*
[ec392464]706
[6af2785]707The parameter values in the *currently selected* table of the *Grid Window*
708can be output to a CSV file by choosing *Save As* under *File* in the (*Grid*
709*Window*) menu bar. The default filename includes the date and time that the
710batch fit was performed.
[ec392464]711
[6af2785]712Saved CSV files can be reloaded by choosing *Open* under *File* in the *Grid*
713*Window* menu bar. The loaded parameters will appear in a new table tab.
[ec392464]714
[6aad2e8]715.. image:: file_menu.png
[ec392464]716
[6af2785]717*NB: Saving the Grid Window does not save any experimental data, residuals*
718*or actual model fits. Consequently if you reload a saved CSV file the*
719*ability to View Fits will be lost.*
[ec392464]720
[6af2785]721Parameter Plots
722^^^^^^^^^^^^^^^
[ec392464]723
[dbba134]724..
725  Any column of *numeric* parameter values can be plotted against another using
726  the *Grid Window*. Simply select one column at the time and click the *Add*
727  button next to the required *X/Y-axis Selection Range* text box. When both
728  the X and Y axis boxes have been completed, click the *Plot* button.
729
730  When the *Add* button is clicked, *SasView* also automatically completes the
731  *X/Y-axis Label* text box with the heading from Row 1 of the selected table,
732  but different labels and units can be entered manually.
[ec392464]733
[dbba134]734  .. image:: plot_button.png
[ec392464]735
[dbba134]736  The *X/Y-axis Selection Range* can be edited manually. The text control box
737  recognises the operators +, -, \*, /, or 'pow', and allows the following
738  types of expression :
[ec392464]739
[dbba134]740    1) if an axis label range is a function of 1 or more *columns*, write
741      this type of expression
[5005ae0]742
[dbba134]743      constant1 * column_name1 [minimum row index :  maximum  row index]
744      operator constant2 * column_name2 [minimum row index :  maximum  row index]
[ec392464]745
[dbba134]746      Example: radius [2 : 5] -3 * scale [2 : 5]
[ec392464]747
[dbba134]748    2) if only some *values* of a given column are needed but the range between
749      the first row and the last row used is not continuous, write this type of
750      expression
[ec392464]751
[dbba134]752      column_name1 [minimum row index1 :  maximum  row index1] , column_name1
753      [minimum row index2 :  maximum  row index2]
[ec392464]754
[dbba134]755      Example: radius [2 : 5] , radius [10 : 25]
756..
[ec392464]757
[dbba134]758Any row (dataset) can be plotted by selecting it and either right-clicking and choosing
759*Plot selected fits* menu item or by clicking on the *Plot* button.
[5005ae0]760
[9d93c37]761.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
762
763Combined Batch Fit Mode
764-----------------------
765
[e6c74e8]766The purpose of the Combined Batch Fit is to allow running two or more batch
767fits in sequence without overwriting the output table of results.  This may be
768of interest for example if one is fitting a series of data sets where there is
769a shape change occurring in the series that requires changing the model part
770way through the series; for example a sphere to rod transition.  Indeed the
771regular batch mode does not allow for multiple models and requires all the
772files in the series to be fit with single model and set of parameters.  While
773it is of course possible to just run part of the series as a batch fit using
774model one followed by running another batch fit on the rest of the series with
775model two (and/or model three etc), doing so will overwrite the table of
776outputs from the previous batch fit(s).  This may not be desirable if one is
777interested in comparing the parameters: for example the sphere radius of set
[05b0bf6]778one and the cylinder radius of set two.
[e6c74e8]779
780Method
781^^^^^^
[9d93c37]782
[e6c74e8]783In order to use the *Combined Batch Fit*, first load all the data needed as
784described in :ref:`Loading_data`. Next start up two or more *BatchPage* fits
785following the instructions in :ref:`Batch_Fit_Mode` but **DO NOT PRESS FIT**.
[9d93c37]786
[dbba134]787When done, select *Constrained or Simultaneous Fit* under *Fitting* in the menu bar.
788
789In the *Const & Simul Fit* page that appears, choose *Batch fits* radio button and
790select which data sets are to be  fitted.
791
792.. image:: simult_batch.png
793
794Once all are selected, click the Fit button on
795the *Const. Simult. Fitting* to run each batch fit in *sequence*
796
[9d93c37]797
[e6c74e8]798The batch table will then pop up at the end as for the case of the simple Batch
799Fitting with the following caveats:
[9d93c37]800
801.. note::
802   The order matters.  The parameters in the table will be taken from the model
[e6c74e8]803   used in the first *BatchPage* of the list.  Any parameters from the
804   second and later *BatchPage* s that have the same name as a parameter in the
805   first will show up allowing for plotting of that parameter across the
806   models. The other parameters will not be available in the grid.
[9d93c37]807.. note::
808   a corralary of the above is that currently models created as a sum|multiply
809   model will not work as desired because the generated model parameters have a
810   p#_ appended to the beginning and thus radius and p1_radius will not be
811   recognized as the same parameter.
[5005ae0]812
[9d93c37]813
[dbba134]814..
815  .. image:: combine_batch_grid.png
[9d93c37]816
[dbba134]817  In the example shown above the data is a time series with a shifting peak.
818  The first part of the series was fitted using the *broad_peak* model, while
819  the rest of the data were fit using the *gaussian_peak* model. Unfortunately the
820  time is not listed in the file but the file name contains the information. As
821  described in :ref:`Grid_Window`, a column can be added manually, in this case
822  called time, and the peak position plotted against time.
[9d93c37]823
[dbba134]824  .. image:: combine_batch_plot.png
[ec392464]825
[dbba134]826  Note the discontinuity in the peak position.  This reflects the fact that the
827  Gaussian fit is a rather poor model for the data and is not actually
828  finding the peak.
829..
[ec392464]830.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
[6af2785]831
[dbba134]832.. note::  This help document was last changed by Piotr Rozyczko, 18 May 2018
Note: See TracBrowser for help on using the repository browser.