LogFit
- Updated2023-02-21
- 3 minute(s) read
Advanced Analysis Library Only
AnalysisLibErrType LogFit (double arrayX[], double arrayY[], double weight[], ssize_t numberOfElements, double logarithmicBase, int fitMethod, double tolerance, double fittedData[], double *amplitude, double *scale, double *residue);
Purpose
Fits the data set (x, y) to the logarithm model using the Least Square, Least Absolute Residual, or Bisquare method. The following equation represents the logarithm model:
where a is amplitude, b is scale, and base is logarithmicBase. If fitMethod is LEAST_SQUARE, the function finds the amplitude and scale of the logarithm model by minimizing the residue, as follows:
where | n is the numberOfElements |
w i is the i-th element of weight | |
f i is the i-th element of fittedData | |
y i is the i-th element of arrayY |
If fitMethod is LEAST_ABSOLUTE_RESIDUAL, the function finds the amplitude and scale of the logarithm model by minimizing the residue, as follows:
If fitMethod is BISQUARE, the function finds the amplitude and scale of the logarithm model by using reweighted least square fitting iteratively, as shown in the following flowchart:
Parameters
Input | ||
Name | Type | Description |
arrayX | double [] | The x value of the data set (x, y). |
arrayY | double [] | The y value of the data set (x, y). If fittedData is NULL, the best fit array overwrites arrayY. |
weight | double [] | The weight of each data point. If weight is NULL, the function sets all elements in weight to 1. |
numberOfElements | ssize_t | The length of arrayX, arrayY, and weight. |
logarithmicBase | double | The base of the logarithm. If logarithmicBase is less than or equal to 0, the function uses the natural logarithm. |
fitMethod | int | The fitting method. fitMethod must be one of the following values:
|
tolerance | double | The stop criteria. In Least Absolute Residual fitting or Bisquare fitting, the function adjusts the amplitude and scale iteratively. If the relative difference between residue in two successive iterations is less than tolerance, the function returns the resulting amplitude and scale. If tolerance is less than or equal to 0, the function sets tolerance to 0.0001. |
Output | ||
Name | Type | Description |
fittedData | double [] | The y values calculated using the fitted logarithm model. If fittedData is NULL, the best fit array overwrites arrayY. |
amplitude | double | The amplitude of the fitted logarithm model. |
scale | double | The scale of the fitted logarithm model. |
residue | double | The weighted mean error of the logarithm fit. residue is the weighted mean absolute error if fitMethod is LEAST_ABSOLUTE_RESIDUAL, as follows:
residue is the weighted mean square error if fitMethod is LEAST_SQUARE or BISQUARE, as follows:
|
Return Value
Name | Type | Description |
status | AnalysisLibErrType | A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants. |
Additional Information
Library: Advanced Analysis Library
Include file: analysis.h
LabWindows/CVI compatibility: LabWindows/CVI 8.0 and later