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 ) where |
x is the coordinate for dimension 1 of the sample point.
tableX is a Lua table containing n values for the n independent variables of the sample point. Use this form when the basis function takes more than 1 independent variable (i.e., the basis function uses more than 1 dimension).
V is the observed value at the coordinate x or coordinate vector x. When fitting numeric data, this is a number. When fitting RGB data, this is a string with the 3 channel values separated by commas.
y is the coordinate for dimension 2 when using the built-in n-dimensional polynomial. This is a special form provided to make it easier to fit 2 dimensional polynomials.
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.
|
-- create a CLsqFit object |
|
-- set 2 coefficients |
|
-- add a point for x = 3.5, y = 5.15 |
|
-- add a point |
|
-- add a point |
|
-- 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.
|
-- create a CLsqFit object |
|
-- select basis function number 2, the "Hyperplane". |
|
-- set 5 coefficients and 4 dimensions (variables) |
|
-- add a point with 4 dimensions and observed value 12.5 |
|
-- add another point |
|
-- add more points |
|
-- Fit the basis function |
The 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:
|
-- create a CLsqFit object |
|
-- setup the fit for 3 channel (RGB) data |
|
-- specify a basis function named F |
|
-- set 9 coefficients and 3 independent variables |
|
-- add a point with 3 dimensions and an RGB value |
|
-- add more points |
|
-- Fit the basis function |
For an example that adds data directly from a displayed image, see Using CLsqFit with Image Pixels.