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.

Syntax

CLsqFit:AddPtWt( x, V, nWt )

CLsqFit:AddPtWt( tableX, V, nWt )

CLsqFit:AddPtWt( x, y, V, nWt )

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.

    nWt is the weight to assign the point.

    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 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.

Examples

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

L:AddPtWt( 3.5, 5.15, 1 )

-- add a point for x = 3.5, y = 5.15, weight = 1

L:AddPtWt( -12, 14, 1 )

-- add a point with a weight of 1

L:AddPtWt( -2, -4.25, 0.5 )

-- 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

L:AddPt( 3.5, 5.15 )

-- add a point for x = 3.5, y = 5.15, weight = 1

L:AddPt( -12, 14 )

-- add a point with a weight of 1

L:AddPtWt( -2, -4.25, 0.5 )

-- add a point with a weight of 0.5

L:Fit()

-- Fit the line

Related Topics

Using Multiple Independent Variables

AddPt

SetPtWt

CLsqFit class