@CodeReview(reviewer="Kevin R. Dixon", date="2009-07-06", changesNeeded=false, comments={"Made clone() call super.clone().","Otherwise, class looks fine."}) public class LinearVectorScalarFunction extends AbstractRegressor<Vectorizable>
LinearVectorScalarFunction
class implements a scalar
function that is implemented by a linear function. More formally, the
scalar function is parameterized by a weight vector (w) and a bias (b) and
computes the output for a given input (x) as:
f(x) = w * x + bModifier and Type | Field and Description |
---|---|
static double |
DEFAULT_BIAS
The default bias is 0.0.
|
Constructor and Description |
---|
LinearVectorScalarFunction()
Creates a new instance of LinearVectorScalarFunction.
|
LinearVectorScalarFunction(LinearVectorScalarFunction other)
Creates a new copy of a LinearVectorScalarFunction.
|
LinearVectorScalarFunction(Vector weights)
Creates a new instance of LinearVectorScalarFunction.
|
LinearVectorScalarFunction(Vector weights,
double bias)
Creates a new instance of LinearVectorScalarFunction with the given
weights and bias.
|
Modifier and Type | Method and Description |
---|---|
LinearVectorScalarFunction |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
double |
evaluateAsDouble(Vector input)
A convenience method for evaluating a Vector object as a double, thus
avoiding the convertToVector call from Vectorizable.
|
double |
evaluateAsDouble(Vectorizable input)
Evaluate the given input vector as a double by:
weights * input + bias
|
double |
getBias()
Gets the bias term.
|
Vector |
getWeights()
Gets the weight vector.
|
void |
setBias(double bias)
Sets the bias term.
|
void |
setWeights(Vector weights)
Sets the weight vector.
|
java.lang.String |
toString() |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
evaluate
public static final double DEFAULT_BIAS
public LinearVectorScalarFunction()
public LinearVectorScalarFunction(Vector weights)
weights
- The weight vector.public LinearVectorScalarFunction(Vector weights, double bias)
weights
- The weight vector.bias
- The bias term.public LinearVectorScalarFunction(LinearVectorScalarFunction other)
other
- The LinearVectorScalarFunction to copy.public LinearVectorScalarFunction 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 evaluateAsDouble(Vectorizable input)
input
- The input vector to evaluate.public double evaluateAsDouble(Vector input)
input
- The input value to convert to a vector.public Vector getWeights()
public void setWeights(Vector weights)
weights
- The weight vector.public double getBias()
public void setBias(double bias)
bias
- The bias term.public java.lang.String toString()
toString
in class java.lang.Object