fitpoly2d CLsqFit:AddPt

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. For the observed value (dependent variable), this function can fit both numeric values and RGB data passed as a table. To add points with the default weight of 1.0, use the AddPt method.

Syntax

CLsqFit:AddPtWt( x, val, nWt )

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

CLsqFit:AddPtWt( tblX, val, nWt )

CLsqFit:AddPtWt( tblX, tblRGB, nWt )

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

bullet.gif    tblX 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    val is the numeric value of the observation at the coordinate x or the coordinate vector tblX.

bullet.gif    tblRgb is a table of RGB channel values when fitting RGB data.

bullet.gif    y is the second dimension for fitting numeric data to 2-dimensional (x,y) data. It is just a special form that avoids using a table for (x,y) when fitting the built-in 2-dimensional polynomial.

bullet.gif    nWt is the point weight.

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 ("unit weight"). You can later change a point's weight using SetPtWt.

This method allows both numeric data and multi-channel RGB data for the value parameter. To use multi-channel data, call SetNumChannels and specify 3 or 4 channels, then add points using a able for RGB or RGBa data.

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 at (x,y) 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 at (x,y) 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, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.