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

Last change on this file since 3ec78a1 was 3ec78a1, checked in by smk78, 5 years ago

Link fitting_sq.rst from fitting_help.rst

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