CLsqFit:AddPtWt
The AddPtWt method adds weighted 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. To add points with the default weight of 1.0, use the AddPt method.
CLsqFit:AddPtWt( x, V, nWt ) CLsqFit:AddPtWt( tableX, V, nWt ) CLsqFit:AddPtWt( x, y, V, nWt ) |
The AddPtWt and AddPt methods provide the only way to add points to the sample that will be fit. The AddPtWt method adds points with a specified weight whereas AddPt adds points with a weight of 1.0 (so-called "unit weight"). You can later change a point's 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, a deleted point may be undeleted. 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 AddPtWt or AddPt.
The following example adds points with weights 1.0 and 0.5. The only difference between AddPt and AddPtWt is that AddPtWt specifies the point weight, therefore, you can also use the examples given for AddPt.
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetNumCoefs( 2 ) |
-- set 2 coefficients |
|
-- add a point for x = 3.5, y = 5.15, weight = 1 |
|
-- add a point with a weight of 1 |
|
-- add a point with a weight of 0.5 |
L:Fit() |
-- Fit the line |
Note that you can mix AddPt and AddPtWt, as the only difference between them is the default or specified weight value. Here is the same example but using both AddPt and AddPtWt:
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetNumCoefs( 2 ) |
-- set 2 coefficients |
|
-- add a point for x = 3.5, y = 5.15, weight = 1 |
|
-- add a point with a weight of 1 |
|
-- add a point with a weight of 0.5 |
L:Fit() |
-- Fit the line |
CLsqFit class, Using Multiple Independent Variables, AddPt, SetPtWt