CLsqFit:AddPt
The AddPt method adds data points to the sample used in the fit. This function offers various argument lists to handle data both numeric and RGB data of up to 10 independent variables. All points are assigned unit weight in the solution. To add points with weights that are non-zero, use the AddPtWt method.
CLsqFit:AddPt( x, V ) CLsqFit:AddPt( tableX, V ) CLsqFit:AddPt( x, y, V ) |
The AddPt and AddPtWt methods provide the only way to add points to the sample that will be fit. The AddPt method adds points with unit weight whereas AddPtWt adds points with a specified weight. Regardless of how a point is added, you can later change its weight using SetPtWt.
This method accommodates both numeric data and multi-channel RGB data for the value parameter (V in the syntax description). To use multi-channel data, call SetNumChannels to specify either 3 or 4 channels before adding points. Mira distinguishes single channel (numeric) data from multi-channel (RGB) data according to whether the value is a number or a string. The string separates the channel values with a comma, like "100,255,14". The channel values may be integer- or real-valued and are not limited to the range 0 to 255. Thus the following string would be acceptable: "0.0215, 56, 75000.4".
Once added to the sample, a point can be deleted or its weight can be changed. In addition, you can alter a point's independent variables and observed value. If you want to permanently delete all sample points, call the ResetPoints method. After using ResetPoints, new points can be added to the same CLsqFit object using AddPt or AddPtWt.
The following examples illustrate how various forms of AddPt are used to add sample data. The first example specifies 2 coefficients for fitting a line, or 1st order polynomial. Since only 1 argument is specified, the polynomial fits 1 independent variable; such a fit could be described as y = a[1] + a[2] x.
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetNumCoefs( 2 ) |
-- set 2 coefficients |
|
-- add a point for x = 3.5, y = 5.15 |
|
-- add a point |
|
-- add a point |
L:Fit() |
-- Fit the line |
The next example fits a hyperplane of 4 variables and 5 coefficients (one coefficient is the constant term). Notice that the basis is multi-dimensional, so the coordinate values, x, are passed as a table.
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetBasisFunc( 2 ) |
-- select basis function number 2, the "Hyperplane". |
L:SetNumCoefs( 5, 4 ) |
-- set 5 coefficients and 4 dimensions (variables) |
|
-- add a point with 4 dimensions and observed value 12.5 |
|
-- add another point |
|
-- add more points |
L:Fit() |
-- Fit the basis function |
The final example below selects a user-defined basis function of 3 variables and fits RGB data. In this case, the value argument is passed as a string:
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetNumChannels( 3 ) |
-- setup the fit for 3 channel (RGB) data |
L:SetBasisFunc( F ) |
-- specify a basis function named F |
L:SetNumCoefs( 9, 3 ) |
-- set 9 coefficients and 3 independent variables |
|
-- add a point with 3 dimensions and an RGB value |
|
-- add more points |
L:Fit() |
-- Fit the basis function |
For an example that adds data directly from a displayed image, see Using CLsqFit with Image Pixels.
CLsqFit class, Using Multiple Independent Variables, AddPtWt, SetPtWt, Using CLsqFit with Image Pixels