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

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since b31b7e2 was b31b7e2, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Fitting perspective documentation - part 1. SASVIEW-917

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