java.lang.Object
gov.sandia.cognition.util.AbstractCloneableSerializable
gov.sandia.cognition.math.AbstractScalarFunction<Double>
gov.sandia.cognition.math.AbstractUnivariateScalarFunction
gov.sandia.cognition.math.AbstractDifferentiableUnivariateScalarFunction
gov.sandia.cognition.learning.function.scalar.PolynomialFunction.Linear
All Implemented Interfaces:
Evaluator<Double,Double>, PolynomialFunction.ClosedForm, DifferentiableEvaluator<Double,Double,Double>, DifferentiableUnivariateScalarFunction, ScalarFunction<Double>, UnivariateScalarFunction, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
PolynomialFunction.Cubic
Enclosing class:
PolynomialFunction

extends PolynomialFunction.Linear

Utilities for algebraic treatment of a quadratic polynomial of the form y(x) = q0 + q1*x + q2*x^2.

Serialized Form

Field Summary

Fields inherited from class gov.sandia.cognition.learning.function.scalar.PolynomialFunction.Linear
COLLINEAR_TOLERANCE

Constructor Summary
PolynomialFunction.Quadratic(double q0, double q1, double q2)
Creates a new instance of Quadratic
Copy constructor

Method Summary
This makes public the clone method on the Object class and removes the exception that it throws.
double differentiate(double input)
Differentiates the output of the function about the given input
double evaluate(double input)
Produces a double output for the given double input
static double evaluate(double x, double q0, double q1, double q2)
Evaluates a quadratic polynomial of the form y(x) = q0 + q1*x + q2*x^2 for a given value of "x"
static PolynomialFunction.Quadratic fit(InputOutputPair<Double,Double> p0, InputOutputPair<Double,Double> p1, InputOutputPair<Double,Double> p2)
Fits a quadratic to three points
static PolynomialFunction.Quadratic fit(InputOutputSlopeTriplet p0, InputOutputPair<Double,Double> p1)
Fits a quadratic to two points, one of which has slope information.
double getQ2()
Getter for q2
Double[] roots()
Finds the roots (zero-crossings) of the quadratic, which has at most two, but possibly one or zero
static Double[] roots(double q0, double q1, double q2)
void setQ2(double q2)
Setter for q2
Double[] stationaryPoints()
Finds the real-valued stationary points (zero-derivatives) of the quadratic.
static Double[] stationaryPoints(double q0, double q1, double q2)
Finds the stationary point of the quadratic equation.
String toString()

Methods inherited from class gov.sandia.cognition.learning.function.scalar.PolynomialFunction.Linear
fit, fit, getQ0, getQ1, setQ0, setQ1

Methods inherited from class gov.sandia.cognition.math.AbstractDifferentiableUnivariateScalarFunction
differentiate

Methods inherited from class gov.sandia.cognition.math.AbstractUnivariateScalarFunction
evaluate, evaluateAsDouble

Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Methods inherited from interface gov.sandia.cognition.math.ScalarFunction
evaluateAsDouble

Methods inherited from interface gov.sandia.cognition.evaluator.Evaluator
evaluate

Methods inherited from interface gov.sandia.cognition.math.DifferentiableEvaluator
differentiate

Constructor Detail

double q1,
double q2)
Creates a new instance of Quadratic

Parameters:
q0 - Constant (zeroth-order) coefficient
q1 - Linear (first-order) coefficient

Copy constructor

Parameters:
Method Detail

### clone

Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class PolynomialFunction.Linear
Returns:
A clone of this object.

### toString

public String toString()
Overrides:
toString in class PolynomialFunction.Linear

### evaluate

public double evaluate(double input)
Description copied from interface: UnivariateScalarFunction
Produces a double output for the given double input

Specified by:
evaluate in interface UnivariateScalarFunction
Overrides:
evaluate in class PolynomialFunction.Linear
Parameters:
input - Input to the Evaluator
Returns:
output at the given input

### differentiate

public double differentiate(double input)
Description copied from interface: DifferentiableUnivariateScalarFunction
Differentiates the output of the function about the given input

Specified by:
differentiate in interface DifferentiableUnivariateScalarFunction
Overrides:
differentiate in class PolynomialFunction.Linear
Parameters:
input - Input about which to compute the derivative of the function output
Returns:
Derivative of the output with respect to the input

### roots

public Double[] roots()
Finds the roots (zero-crossings) of the quadratic, which has at most two, but possibly one or zero

Specified by:
roots in interface PolynomialFunction.ClosedForm
Overrides:
roots in class PolynomialFunction.Linear
Returns:
Array of roots

### stationaryPoints

public Double[] stationaryPoints()
Finds the real-valued stationary points (zero-derivatives) of the quadratic. A quadratic has at most one stationary point, it may be a minimum or maximum.

Specified by:
stationaryPoints in interface PolynomialFunction.ClosedForm
Overrides:
stationaryPoints in class PolynomialFunction.Linear
Returns:
Zero- or One-length array of stationary points

### evaluate

public static double evaluate(double x,
double q0,
double q1,
double q2)
Evaluates a quadratic polynomial of the form y(x) = q0 + q1*x + q2*x^2 for a given value of "x"

Parameters:
x - Value at which to evaluate the polynomial
q0 - Constant-term coefficient
q1 - Linear-term coefficient
Returns:
Value of the polynomial at "x"

### fit

InputOutputPair<Double,Double> p1,
InputOutputPair<Double,Double> p2)
Fits a quadratic to three points

Parameters:
p0 - First point
p1 - Second point
p2 - Third point
Returns:

### fit

InputOutputPair<Double,Double> p1)
Fits a quadratic to two points, one of which has slope information.

Parameters:
p0 -
p1 -
Returns:

### roots

@PublicationReference(author="Wikipedia",
type=WebPage,
year=2008,
public static Double[] roots(double q0,
double q1,
double q2)
Finds the roots of the quadratic equation using the quadratic formula. That is, finding the values of "x" such that y(x) = q0 + q1*x + q2*x^2 = 0.0. There will be at most two roots, but there can also be a single root, or no roots. In the case of two roots, the return Pair will have the "x" value for value. In the case of a single root, the Pair will have an "x" value for the First, but null for the second. In the case when there are no REAL roots, the return value will be null.

Parameters:
q0 - Constant-term coefficient
q1 - Linear-term coefficient
Returns:
In the case of two roots, the return Pair will have the "x" value for value. In the case of a single root, the Pair will have an "x" value for the First, but null for the second. In the case when there are no REAL roots, the return value will be a zero-length array.

### stationaryPoints

public static Double[] stationaryPoints(double q0,
double q1,
double q2)
Finds the stationary point of the quadratic equation. That is, the point when the derivative f'(x)=0.0

Parameters:
q0 - Constant-term coefficient
q1 - Linear-term coefficient
Returns:
Value of "x" when the derivative is zero, null when none is found

### getQ2

public double getQ2()
Getter for q2

Returns:
Second-order coefficient

### setQ2

public void setQ2(double q2)
Setter for q2

Parameters:
q2 - Second-order coefficient