Class BivariateEstimator
- All Implemented Interfaces:
Encodable
A bivariate estimator approximates the value of a function of two variables using a set of known function values. If the function values are given by
f1 = f(x1, y1)
f2 = f(x2, y2)
...
fn = f(xn, yn)
then an estimator is set up based on the function values using a polynomial of user-specified degree. Suppose that the desired polynomial degree is 2 so that the polynomial is a quadratic. Then a series of 9 coefficients
[a0, a1, ... a8]
are calculated using the values, and the estimator will approximate function values using the coefficients as:
f(x, y) = a0 + a1x +
a2x2 + a3y + a4xy +
a5x2y + a6y2 +
a7xy2 +
a8x2y2
.
Note that for estimator constuction where the number of data values is exactly the required number for the polynomial degree, then LU decomposition is used to obtain a least squares solution. In the case where the linear system is overdetermined (there are more data values than are required) then singular value decomposition is used to obtain a least squares solution. The SVD calculation used is detailed in:
Watkins, David S. Fundamentals of Matrix Computations, John Wiley & Sons, Inc., 1991, pp 416-418.
- Since:
- 3.1.0
- Author:
- Peter Hollemans
-
Constructor Summary
ConstructorDescriptionBivariateEstimator
(double[] xVals, double[] yVals, double[] fVals, int degree) Constructs a bivariate estimator using the specified function values and polynomial degree.BivariateEstimator
(Object obj) Constructs an estimator from the specified encoding. -
Method Summary
Modifier and TypeMethodDescriptiondouble
evaluate
(double[] variables) Evalutes a function value with the specified inputs.Gets an encoded representation of this estimator.static void
Tests this class.void
useEncoding
(Object obj) Uses an encoded representation of this estimator to recreate the estimator contents.
-
Constructor Details
-
BivariateEstimator
public BivariateEstimator(double[] xVals, double[] yVals, double[] fVals, int degree) Constructs a bivariate estimator using the specified function values and polynomial degree.- Parameters:
xVals
- the array of x values.yVals
- the array of y values.fVals
- the function values at(x,y)
points.degree
- the desired polynomial degree, minimum 1.- Throws:
RuntimeException
- if the estimator matrix could not be calculated. This occurs for example when the supplied data results in a singular matrix during computation.
-
BivariateEstimator
Constructs an estimator from the specified encoding. The encoding must be a valid encoding of the estimator as created bygetEncoding
.- Parameters:
obj
- the object encoding.- See Also:
-
-
Method Details
-
evaluate
public double evaluate(double[] variables) Description copied from class:Function
Evalutes a function value with the specified inputs. -
getEncoding
Gets an encoded representation of this estimator. The encoding may later be used to recreate the estimator without using the original function data.- Specified by:
getEncoding
in interfaceEncodable
- Overrides:
getEncoding
in classFunction
- Returns:
- the object encoding. The encoding object is a
double[]
array of coefficients. - See Also:
-
useEncoding
Uses an encoded representation of this estimator to recreate the estimator contents.- Specified by:
useEncoding
in interfaceEncodable
- Overrides:
useEncoding
in classFunction
- Parameters:
obj
- the object encoding.- See Also:
-
main
Tests this class.- Parameters:
argv
- the array of command line parameters.
-