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 |
---|
float
Real value given to equation.
array
Coefficients used in calculation.
float
Value 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)
array
Array of x data points.
array
Array of y data points that correspond to x.
array
Current coefficients to compare against.
float
Real 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.
array
Array of x data points.
array
Array of y data points that correspond to x.
array
Initial or previous guess at coefficients.
array
An array that is the new guess at coefficients.getNumberOfCoefficients() : integer
abstract |
---|
integer
The 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.
float
Value of x to supply to partial-differential function.
integer
Which coefficient to be used in the partial-differential function.
array
Values of the coefficients to be used.
float
p( x ) for the supplied input.getErrorMatrix(float $x, float $y, array $coefficients) : array
float
Array of x-coordinates.
float
Array of known y-coordinates that correspond to $x.
array
Current coefficients to check for error.
array
Matrix of error at each point.multiply(array $matrix, array $multiplicand) : array
[ A ] = [ B ][ C ]
array
array
array
Matrix [ 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 ]. |
---|
array
array
transpose(array $matrix) : array
array
Any matrix.
array
A matrix representing transpose.