CLsqFit:AddPtWt


The AddPtWt method adds weighted data points to the sample used in the fit. The number of coordinate values (independent variables) must match the dimensions of the fit specified using the SetNumCoefs method. For the observed value (dependent variable), this function can use both numeric data and RGB data passed as a string. 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 )

bullet.gif    x is the coordinate for dimension 1 of the point when fitting 1-dimension.

bullet.gif    tableX is a 1-dimensional array containing n elements equal to the number of dimensions in the fit. Use this form when the basis function takes more than one independent variable.

bullet.gif    V is the observed value at the coordinate x or coordinate vector tableX. When fitting numeric data, this is a number. When fitting RGB data, this is a string with the 3 channel values separated by commas, like "255, 14, 25.75".

bullet.gif    y is the coordinate for dimension 2 when using the built-in 2-dimensional polynomial. This is just a special syntax for 2-dimensional fitting.

Remarks

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 = new_lsqfit()

-- create a CLsqFit object (defaults to polynomial)

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 = new_lsqfit()

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

CLsqFit class, Using Multiple Independent Variables, AddPt, SetPtWt


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.