public class LinearFunction extends AbstractDifferentiableUnivariateScalarFunction
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_OFFSET
The default offset is 0.0.
|
static double |
DEFAULT_SLOPE
The default slope is 1.0.
|
protected double |
offset
The offset (b).
|
protected double |
slope
The slope (m).
|
Constructor and Description |
---|
LinearFunction()
Creates a new
LinearFunction with a slope of 1 and offset of 0. |
LinearFunction(double slope,
double offset)
Creates a new
LinearFunction with the given slope and offset. |
LinearFunction(LinearFunction other)
Creates a copy of a given
LinearFunction . |
Modifier and Type | Method and Description |
---|---|
LinearFunction |
clone()
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
|
double |
getOffset()
Gets the offset of the function, which is the b term in: f(x) = m*x + b.
|
double |
getSlope()
Gets the slope of the function, which is the m term in: f(x) = m*x + b.
|
void |
setOffset(double offset)
Sets the offset of the function, which is the b term in: f(x) = m*x + b.
|
void |
setSlope(double slope)
Sets the slope of the function, which is the m term in: f(x) = m*x + b.
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
differentiate
evaluate, evaluateAsDouble
public static final double DEFAULT_SLOPE
public static final double DEFAULT_OFFSET
protected double slope
protected double offset
public LinearFunction()
LinearFunction
with a slope of 1 and offset of 0.
This makes f(x) = x.public LinearFunction(double slope, double offset)
LinearFunction
with the given slope and offset.slope
- The slope.offset
- The offset.public LinearFunction(LinearFunction other)
LinearFunction
.other
- The LinearFunction to copy.public LinearFunction clone()
AbstractCloneableSerializable
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.clone
in interface CloneableSerializable
clone
in class AbstractCloneableSerializable
public double evaluate(double input)
UnivariateScalarFunction
input
- Input to the Evaluatorpublic double differentiate(double input)
DifferentiableUnivariateScalarFunction
input
- Input about which to compute the derivative of the function outputpublic double getSlope()
public void setSlope(double slope)
slope
- The slope.public double getOffset()
public void setOffset(double offset)
offset
- The offset.