CLsqFit:AddPtWt CLsqFit:delete

CLsqFit:AddPt


The AddPt method adds a data point to the fit. The number of coordinate values (independent variables) must match the dimensions of the fit. All points are assigned unit weight. To add points with nonzero weights, use the AddPtWt method.

Syntax

CLsqFit:AddPt( x, val )

CLsqFit:AddPt( x, y, val )

CLsqFit:AddPt( tblX, val )

CLsqFit:AddPt( tblX, tblRgb )

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.

Remarks

The AddPt and AddPtWt methods provide the only way to add sample points. The AddPt method adds points with unit weight (1.0) 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 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, 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.

Examples

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.

L = new_lsqfit()

-- create a CLsqFit object (defaults to polynomial)

L:SetNumCoefs( 2 )

-- set 2 coefficients

L:AddPt( 3.5, 5.15 )

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

L:AddPt( -12, 14 )

-- add a point

L:AddPt( -2, -4.25 )

-- add a point

L:Fit()

-- Fit the line

The next example fits a hyperplane of 4 dimensions (hence 5 coefficients because one coefficient is the constant term). Since more than one dimension is being fit, the dependent variables must be specified using a table with 4 elements.

L = new_lsqfit()

-- create a CLsqFit object (defaults to polynomial)

L:SetBasisFunc("hyperplane")

-- select basis function 2, the "Hyperplane".

L:SetNumCoefs( 5 )

-- set 5 coefficients = 4 dimensions (variables) + constant

L:AddPt( { 1, 17, -3, 41 }, 12.5 )

-- add a point with 4 dimensions and observed value 12.5

L:AddPt( { 3, 4, 12, 7.2 }, 1.275 )

-- add another point

-- add more points to the fit

 

L:Fit()

-- Fit the basis function

The final example below specifies a user-defined basis function named "Func" which fits data for which the dependent variable is a 3-channel RGB value. The fit involves 2 dimensions (independent variables) with 4 coefficients fit to each dimension. The RGB value argument must be passed as a string:

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumChannels( 3 )

-- setup the fit for 3 channel (RGB) data

L:SetBasisFunc( "Func" )

-- specify a basis function named F

L:SetNumCoefs( {4,4} )

-- set 27 coefficients: 3 variables with 3 coefs each

L:AddPt( { 3, 17 }, {0.1, 390.5, 12.2} )

-- pass a table for 2 dimensions plus a table with RGB values

-- add more points to the fit

 

L:Fit()

-- Fit the basis function

For an example that adds pixel data directly from a displayed image, see Using CLsqFit with Image Pixels.

Related Topics

CLsqFit class

GetPt

Using Multiple Independent Variables

AddPtWt

SetPtWt

Using CLsqFit with Image Pixels

 


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