This dialog is activated by selecting the command Fit Wizard 2D from the Fitting -> Analysis menu. This command is active if a 3D plot, a matrix or a table window are selected.
This dialog can be used to fit discrete data points with a 2D mathematical function f(x, y). The fitting is done by minimizing the least square differences between the data points and the Z values of this function.
The default algorithm used by QtiPlot is the Levenberg-Marquardt iterative algorithm, as provided by the MPFIT library. In the Pro edition of QtiPlot it is also possible to use the Nelder-Mead algorithm (or downhill simplex method).
The data set to be fitted, as well as the 2D fit model can be visualized in a 3D plot panel embedded in this dialog. This 3D plot can be shown/hidden with the help of the Preview check box.
This tab displays a different set of controls depending on the type of the active window in the project: a 3D plot, a matrix or a table.
In the case of a table, in the Data tab you can choose the input data columns and also set a weighting method for your fit (the default is No weighting). The available weighting methods are:
No weighting: all weighting coefficients are set to 1 (wi = 1).
Statistical: the weighting coefficients are calculated as wi = 1/zi, where zi are the z values in the fitted data set.
Arbitrary Dataset: allows setting the weighting coefficients using an arbitrary data set wi = 1/ci2, where ci are the values in the arbitrary data set.
Direct Weighting: allows setting the weighting coefficients using an arbitrary data set wi = ci, where ci are the values in the arbitrary data set.
This tab is used to define the function which will be used for fitting. To choose a function, first select a Type (Built-in or User defined) and then the desired function from the drop-down list next to it.
The only difference between the built-in and the user defined fit models, from the point of view of the fitting algorithm, is that the Jacobian matrix is calculated analystically for the built-in functions, while for the user defined functions the derivatives are evaluated numerically. The list of built-in 2D fit functions with their description and a sample image can be found in the Surface Fitting section of this manual.
When a function is selected its title and parameters are displayed in the Name and Parameters fields and its analytical expression is shown in the z(x, y) text panel below. The Name field and the z(x, y) text panel are not editable for fit functions from the Built-in category.
When the selected built-in model is the Polynomial2D function the Polynomial Order input box becomes available, allowing to choose the order of the polynomial fit function.
If you wish to define your own fit model, you should select the User defined category. In this case the z(x, y) text panel as well as the Name field become editable and a range of edit tool buttons are available, see image below:
You can either write your own mathematical expressions from scratch or add expressions with the help of
the function selector, the Σ button. When pressing this button a menu pops-up listing all basic mathematical
functions and fit models provided by QtiPlot. Selecting one of the actions from this menu copies the displayed
function into the edit box at the position of the text cursor. Clicking the Clear
button removes the contents of the function definition text box.
It is worth mentioning that it is possible to write the name of a basic mathematical function or of a built-in/user defined fit model in the editing panel and after the first two characters QtiPlot pops-up a case sensitive selection list for a faster editing process. The names of built-in/user defined fit models are automatically replaced with their analytical expression.
Once a custom expression is completed, clicking on the Save button
adds the function to the list of user defined fit models. The text in the Name field is used
as the title of the function. A copy of the function is saved on disk with the extension .fit. You can define
the folder where .fit files are saved using either the
Choose models folder button or
by selecting a new folder in the Save file dialog.
User defined functions can be removed from the User defined list by selecting them and clicking on the
Remove button. You will be asked to confirm the deletion.
In this tab a starting point should be provided for the fit parameters via the
Value column of the Parameters table.
The initial values of the fit parameters are by default set to 1.0.
Some of the built-in fit models (Exponential2D, Gauss2D and
LogisticCum) provide a guessing mechanism for the initial values of the parameters.
These guesses can be displayed by pressing the button.
Boundary constraints can be defined for the fit parameters if the Range box is checked. This shows the From and To columns of the parameters table. It is also possible to keep the value of some parameters constant during the iterative fit process by checking their corresponding box from the Fixed column. If all the boxes from the Fixed column are checked QtiPlot raises an error message informing that there are no free parameters and that the fit operation cannot be performed.
Figure 5-163. The Fit Wizard 2D dialog box: providing initial guesses for the fit parameters and defining constraints.
The Comment column of the Parameters table is only available in the case of user defined fit models. It can be shown/hidden by checking the Comments box, see the image below. This column can be used in order to provide explanations for the fit parameters. Even if the Comment column is hidden, these explanations are displayed when clicking on a cell containing the name of a fit parameter.
The numerical format used to display the results of the fit operations can be chosen from the Format list box. The value set in the Precision input box has a different meaning depending on the numeric format. The following format and precision options are available:
Decimal or scientific e-notation, whichever is the most concise. The Precision value represents the maximum number of significant figures in the output (trailing zeroes are omitted).
Decimal notation. The Precision value represents the number of digits after the decimal point.
Scientific e-notation where the letter e
is used to represent "times ten raised to the power of" and is followed by the value of the exponent. The Precision value represents the number of digits after the decimal point.
Scientific e-notation where the letter E
is used to represent "times ten raised to the power of" and is followed by the value of the exponent. The Precision value represents the number of digits after the decimal point.
In the Algorithm tab you can set a maximum number of Iterations and a Tolerance value, which are both stopping criteria for the iterative fit algorithms.
The default solver is the Levenberg-Marquardt algorithm, as provided by the MPFIT library. In the Pro edition of QtiPlot it is also possible to use the Nelder-Mead algorithm (or downhill simplex method) as it is implemented in this public GitHub repository. This feature is not available in the student edition of QtiPlot.
The controls in the Function and Data group boxes from this tab can be used to customise the appearance of the fit surface preview and of the input data curve, respectively.
If the option Create Plot is checked, a new 3D plot window is displayed after the fit wizard dialog is closed. This 3D plot displays the input data and the analytical surface resulting after the last fit operation performed, using the style settings from the Function and Data group boxes. If the options Parameters Table and Covariance Matrix from the Options group are checked, QtiPlot also creates a new table window displaying the values of the fit parameters and their corresponding error values, as well as a new matrix window displaying the values of the fit covariance matrix.
If the Write Parameters to Result Log box from the Options group is checked, the log window is opened after a fit and displays the results of the fitting operation.
The Scale Errors with sqrt(Chi^2/doF) option only affects the errors on the parameters reported after the fit operation. It does not affect the fitting process or the data in any way. If checked, the reported errors on the parameters, εj, are calculated as the square root of the diagonal elements of the covariance matrix Cov(j, j) multiplied with sqrt(Chi2/(n - p)), where n is the number of data points and p the number of fit parameters. Otherwise, the reported errors equal the square root of the diagonal elements of the covariance matrix Cov(j, j).