source:
sasview/src/sas/perspectives/fitting/media/fitting_help.rst
@
5e880fe1
Last change on this file since 5e880fe1 was a0637de, checked in by smk78, 10 years ago | |
---|---|
|
|
File size: 16.2 KB |
Fitting Perspective
Preparing to fit data
To fit some data you must first load some data, activate one or more data sets, then send those data sets to the fitting perspective.
Instructions on how to do this are in the User Documentation section Loading Data.
SasView can fit data in one of three ways:
- in Single fit mode
- in Simultaneous fit mode
- in Batch fit mode
These modes of operation are described below.
Single Fit
One of two fit-engines can be chosen from the Fitting menu bar. The Simple Fit- engine uses Scipy's leasqr and the Complex Fit-Engine is a custom optimizer that provides a better chance to find the global minimum of the χ 2 but that requires longer computation time. In order to set a data to a control panel (FitPage), see the "DataLoader Help". Once a data set to the FiPage, select a model from the combo box. The default parameters of the model will be display. Set initial parameters if need. Check and uncheck parameters to fit/fix. Click the 'Fit' button. When the fitting is finished, the resultant parameter values will be displayed with the errors. If a error is missing, it generally means that the corresponding parameter is not very depending on the model. The chisq/Npt_fit and the plot associated with the fit operation will be also updated.
Simultaneous Fitting
This fitting option enables to set a number of the constraints between the parameters of fitting(s). It requires one or more FitPages with a data and a model set for the fitting, and performs multiple fittings given by the FitPage(s). The Complex (ParkMC) FitEngine will be used automatically.
Simultaneous Fit without Constraint
Assuming some FitPages are already set up, check the checkboxes of the model_data rows to fit. And click the 'Fit' button. The results will return to each FitPages.
Note that the chi2/Npts returned is the sum of the chi2/Npts of each fits. If one needs the chi2 value only for a page, click the 'Compute' button in the FitPage to recalculate.
Simultaneous Fit with Constraint
Enter constraint in the text control next to constraint fit button. Constraint should be of type model1 parameter name = f(model2 parameter name) for example, M0.radius=2*M1.radius. Many constraints can be entered for a single fit. Each of them should be separated by a newline charater or ";" The easy setup can generate many constraint inputs easily when the selected two models are the same type.
Note that the chi2/Npts returned is the sum of the chi2/Npts of each fits. If one needs the chi2 value only for one fit, click the 'Compute' button in the FitPage to recalculate.
Batch Fit
Create a Batch Page by selecting the Batch radio button on the DataExplorer (see figure below) and for a new control page select 'New FitPage' in the Fitting menubar.
Figure 1: MenuBar:
Load Data to the DataExplorer if not already loaded.
Select one or more data sets by checking the check boxes, and then make sure that "Fitting" is selected in the dropdown menu next to the "Send To" button. Once ready, click the 'Send To' button to set data to a BatchPage. If already an empty batch page exists, it will be set there. Otherwise it will create a new Batch Page. Set up the model and the parameter values as same as a single fitting (see Single Fit help) <Single_Fit>. Then use 'Fit' button to perform the fitting.
Unlike a single fit, the results of the fittings will not return to the BatchPage'. Instead, a Grid window will be provided once the fitting is completed. The Grid window is also accessible from the 'View' menu (see Figure 2).
Note that only one model is used for all the data. The initial parameter values given in the control page will be used all the data fittings. If one wants the FitEngine to use the initial values from the results of the previous data fitting (if any), choose the 'Chain Fitting' option in the Fitting menubar, which will speed up the fitting especially when you have lots of, and similar, data sets.
Batch Window
Batch Window provides an easy way to view the fit results, i.e., plot data, fits, and residuals. Batch window will be automatically shown after a batch fit is finished.
Once closed, it can be opened anytime from the "View" menubar item (see Figure 2).
Figure 2: Edit Menu:
Edit Grid
Once a batch fit is completed, all fitted and fixed model parameters are displayed to the current sheet of the batch window except the errors of the parameters. To view the errors, click on a given column then under Edit menubar item, and insert the desired parameter by selecting a menu item with the appropriated label. Empty column can be inserted in the same way. A column value can be customized by editing an existing empty column.
To Remove column from the grid, select it, choose edit menu, and click the 'remove' menu item. Any removed column should reinserted whenever needed.
All above options are also available when right clicking on a given column label(see Figure 3).
Note: A column always needs to be selected in order to remove or insert a column in the grid.
Figure 3: Edit Menu:
Save Grid
To save the current page on the batch window, select the 'File' menubar item(see Figure 4), then choose the 'Save as' menu item to save it as a .csv file.
Note: The grid doesn't save the data array, fits, and the array residuals. As a result, the 'View (fit) Results' functionality will be lost when reloading the saved file.
Warning! To ensure accuracy of saved fit results, it is recommended to save the current grid before modifying it .
Open Batch Results
Any csv file can be opened in the grid by selecting the 'Open' under the 'File' menu in the Grid Window(see Figure 4). All columns in the file will be displayed but insertion will not available. Insertion will be available only when at least one column will be removed from the grid.
Figure 4: MenuBar:
Plot
To plot a column versus another, select one column at the time, click the 'Add' button next to the text control of X/Y -axis Selection Range to plot the value of this column on the X/Y axis. Alternatively, all available range can be selected by clicking the column letter (eg. B). Repeat the same procedure the next axis. Finally, click the 'Plot' button. When clicking on Add button, the grid will automatically fill the axis label, but different labels and units can be entered in the correct controls before clicking on the plot button.
X/Y -Axis Selection Range can be edited manually. These text controls allow the following types of expression (operation can be + - * /, or pow)
1) if the current axis label range is a function of 1 or more columns, write this type of expression
constant1 * column_name1 [minimum row index : maximum row index] operator constant2 * column_name2 [minimum row index : maximum row index]
Example: radius [2 : 5] -3 * scale [2 : 5]
2) if only some values of a given column are need but the range between the first row and the last row used is not continuous, write the following expression in the text control
column_name1 [minimum row index1 : maximum row index1] , column_name1 [minimum row index2 : maximum row index2]
Example : radius [2 : 5] , radius [10 : 25]
Note: Both text controls ( X and Y-axis Selection Ranges) need to be filled with valid entries for plotting to work. The dY-bar is optional (see Figure 5).
Figure 5: Plotting
View Column/Cell(s)
Select 1 or more cells from the same column, click the 'View Fits' button to display available curves.
For example, select the cells of the 'Chi2' column, then click the 'View Fits' button. The plots generates will represent the residuals plots.
If you select any cells of the 'Data' column and click the 'View Fits' button. It generates both data and fits in the graph (see Figure 6).
Alternatively, just click the column letter (eg. B) to choose all the available data sets, then simply click the 'View Fits' button to plot the data and fits.
Figure 6: View Fits
Model Type
Models are grouped into three classes
- Shapes
- Shape-Independent
- Uncategorised
- Customized Models
- Structure Factor
Change Model Parameters
To visualize model in a different window, from menu click on Model. Select a type of model and then the name of your model.A new window will appear with the plot of your model with default values. Change model's parameters on model view tab and view the plotted model with its new parameters.
Write your Own Model
The custom model editors are provided from 'Fitting' menu in the menu bar. See 'Custom model editor' in the side menu on left. Advanced users can write your own model and save it (in .py format) into plugin_models directory in .sasview of your home directory (eg., username.sasview>plugin_models). Your plugin model will be added into "<>Customized Models" on the next model selection.
Model Category Manager
Our SAS models are, by default, classified into 5 categories; shapes, shape-independent, structure factor, and customized models, where these categories (except the customized models) can be reassigned, added, and removed using 'Category Manager'. Each models can also be enabled(shown)/ disabled(hidden) from the category that they belong. The Category Manager panel is accessible from the model category 'Modify' button in the fitting panel or the 'View/Category Manager' menu in the menu bar (Fig. 1).
1) Enable/Disable models: Check/uncheck the check boxes to enable/disable the models (Fig. 2).
2) Change category: Highlight a model in the list by left-clicking and click the 'Modify' button. In the 'Change Category' panel, one can create/use a category for the model, then click the 'Add' button. In order to delete a category, select a category name and click the 'Remove Selected' button (Fig. 3).
3) To apply the changes made, hit the OK button. Otherwise, click the 'Cancel' button (Fig. 2).
Fig.1
Fig.2
Fig.3
Model Functions
See Model Documentation.
Description
This menu (Fitting/Edit Custom Model in the menu bar) interface is to provide you an easy way to write your own custom models. The changes in a model function are effective after it is re-selected from the combo-box menu.
New
This option is used to make a new model. A model code generated by this option can be viewed and further modified by the 'Advanced' option below.
Sum|Multi(p1,p2)
This option create a new sum (or multiplication) model. Fill up the (sum model function) name and the description. The description will show up on details button in the application. Then select the p1 or p2 model for the sum/multi model, select an operator as necessary and click the Apply button for activation. Hit the 'Close' button when it's done.
Advanced
The menu option shows all the files in the plugin_models folder. You can edit, modify, and save it. It is recommended to modify only the lines with arrow (-------). In the end of edit, 'Compile' and 'Run' from the menu bar to activate or to see the model working properly.
Delete
The menu option is to delete the custom models. Just select the file name to delete.
Copy & Paste
To copy the parameter values in a Fit(Model) panel to the clipboard:
Ctrl(Cmd on MAC) + Left(Mouse)Click on the panel.
To paste the parameter values to a Fit(Model)panel from the clipboard:
Ctrl(Cmd on MAC) + Shift + Left(Mouse)Click on the panel.
If this operation is successful, it will say so in the info line at the bottom of the SasView window.
Bookmark
Bookmark of a fit-panel or model-panel status:
(Mouse)Right-Click and select the bookmark in the popup list.
Graph Context Menu
To get the graph context menu to print, copy, save data, (2D)average, etc.:
Locate the mouse point on the plot to highlight and *(Mouse) Right Click to bring up the full menu.
FTolerance (SciPy)
To change the ftol value of the Scipy FitEngine (leastsq):
First, make sure that the Fit panel has data and a model selected.
Ctrl(Cmd on MAC) + Shift + Alt + Right(Mouse)Click on the panel.
Then, set up the value in the dialog panel.
If this operation is successful, the new ftol value will be displayed in the info line at the bottom of the SV window.Note that increasing the ftol value may cause for the fitting to terminate with higher χ sq.
Message/Warning/Hint
The status bar located at the bottom of the application frame, displays messages, hints, warnings and errors.
Console
Select light bulb/info icon button in the status bar at the bottom of the application window to display available history. During a long task, the console can also help users to understand the status in progressing.