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 specified using the SetNumCoefs method. For the observed value V, this function can use both numeric data and RGB data passed as a string. All points are assigned unit weight. To add points with weights that are non-zero, use the AddPtWt method.

Syntax

CLsqFit:AddPt( x, V )

CLsqFit:AddPt( tableX, V )

CLsqFit:AddPt( x, y, V )

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 AddPt and AddPtWt methods provide the only way to add points to the sample that will be fit. The AddPt method adds points with unit weight 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 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, 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 variables and 5 coefficients (one coefficient is the constant term). Notice that the basis is multi-dimensional, so the coordinate values, x, are passed as a table.

L = new_lsqfit()

-- create a CLsqFit object (defaults to polynomial)

L:SetBasisFunc( 2 )

-- 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 selects a user-defined basis function of 3 variables with 3 coefficients each, and fits RGB data. The value argument is passed as a string:

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumChannels( 3 )

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

L:SetBasisFunc( F )

-- specify a basis function named F

L:SetNumCoefs( {3,3,3} )

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

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

-- add a point with 3 dimensions and an RGB value

-- add more points to the fit

 

L:Fit()

-- Fit the basis function

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

Related Topics

CLsqFit class, Using Multiple Independent Variables, AddPtWt, SetPtWt, Using CLsqFit with Image Pixels


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