source: sasview/src/sas/sasgui/perspectives/fitting/media/fitting_help.rst @ ae69c690

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since ae69c690 was 05b0bf6, checked in by butler, 7 years ago

Fix typos and improve last sentence.

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