getFunction()
getR_Squared()
refineCoefficients()
getNumberOfCoefficients()
partialDifferential()
getErrorMatrix()
multiply()
solve()
transpose()
Gauss-Newton non-linear regression.
This class is useful for computing the coefficients for some non-linear equation using the Gauss-Newton algorithm.
Algorithm (see 2): b_n+1 = b_n + (J^T J)^-1 J r( b_n ) Where b is the current guess for the coefficients, n is the current guess J is the Jacobian, and r is the residual (error).
This is an abstract class and can not be used by itself. It requires the the function and function partial differentials to be define.
| package | GaussNewtonRegression |
|---|---|
| abstract |
getFunction(float $x, array $coefficients) : float
Return f( x ) for a given set of coefficients.
| abstract |
|---|
floatReal value given to equation.
arrayCoefficients used in calculation.
floatValue result of equation.getR_Squared(array $x, array $y, array $coefficients) : float
Compute Coefficient of determination (R squared) for a set of coefficients. This is useful for determining how good a fit the coefficients are. (See 5)
arrayArray of x data points.
arrayArray of y data points that correspond to x.
arrayCurrent coefficients to compare against.
floatReal value between 0 and 1.refineCoefficients(array $x, array $y, array $coefficients) : array
Run an iteration of the Gauss-Newton algorithm. Run this as many times as needed to refine coefficients to their best values.
arrayArray of x data points.
arrayArray of y data points that correspond to x.
arrayInitial or previous guess at coefficients.
arrayAn array that is the new guess at coefficients.getNumberOfCoefficients() : integer
| abstract |
|---|
integerThe number of coefficients for the equation being used.partialDifferential(float $x, integer $coefficientIndex, array $coefficients) : float
Compute the partial-differential with respect to a given coefficient for a given value of x. p( x ) = d f( x ) / d c_n Example:
If f( x ) = c_0 e^(c_1 x ), then:
d f( x ) / d c_0 = e^( c_1 x )
d f( x ) / d c_1 = c_0 x e^( c_1 x )
Each function must be defined.
floatValue of x to supply to partial-differential function.
integerWhich coefficient to be used in the partial-differential function.
arrayValues of the coefficients to be used.
floatp( x ) for the supplied input.getErrorMatrix(float $x, float $y, array $coefficients) : array
floatArray of x-coordinates.
floatArray of known y-coordinates that correspond to $x.
arrayCurrent coefficients to check for error.
arrayMatrix of error at each point.multiply(array $matrix, array $multiplicand) : array
[ A ] = [ B ][ C ]
arrayarrayarrayMatrix [ C ].solve(array $matrix, array $answers)
Done by concatenating answer matrix to the left, doing Gaussian elimination (see 3), and returning the last column. [ M ][ C ] = [ A ] ==> [ C ] = [ M ]^1 [ A ]
| output | array Single column matrix [ C ]. |
|---|
arrayarraytranspose(array $matrix) : array
arrayAny matrix.
arrayA matrix representing transpose.