@CodeReview(reviewer="Kevin R. Dixon", date="2009-07-08", changesNeeded=false, comments="Looks fine.") public class PolynomialKernel extends AbstractCloneableSerializable implements Kernel<Vectorizable>
PolynomialKernel
class implements a kernel for two given
vectors that is the polynomial function:
Modifier and Type | Field and Description |
---|---|
protected double |
constant
The constant for the polynomial.
|
static double |
DEFAULT_CONSTANT
The default constant is 1.0.
|
static int |
DEFAULT_DEGREE
The default degree is 2.
|
protected int |
degree
The degree of the polynomial.
|
Constructor and Description |
---|
PolynomialKernel()
Creates a new instance of PolynomialKernel with a degree of 2 and a
constant of 1.0.
|
PolynomialKernel(int degree)
Creates a new instance of PolynomialKernel with the given degree and
a constant of 1.0.
|
PolynomialKernel(int degree,
double constant)
Creates a new instance of PolynomialKernel with the given degree and
constant.
|
PolynomialKernel(PolynomialKernel other)
Creates a new copy of a PolynomialKernel.
|
Modifier and Type | Method and Description |
---|---|
PolynomialKernel |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
double |
evaluate(Vectorizable x,
Vectorizable y)
This kernel just evaluates the polynomial kernel between the two given
vectors, which is: (x dot y + c)^d.
|
double |
getConstant()
Gets the constant of the polynomial.
|
int |
getDegree()
Gets the degree of the polynomial.
|
void |
setConstant(double constant)
Gets the constant of the polynomial.
|
void |
setDegree(int degree)
Sets the degree of the polynomial.
|
public static final int DEFAULT_DEGREE
public static final double DEFAULT_CONSTANT
protected int degree
protected double constant
public PolynomialKernel()
public PolynomialKernel(int degree)
degree
- The degree of the kernel. Must be positive.public PolynomialKernel(int degree, double constant)
degree
- The degree of the kernel. Must be positive.constant
- The constant of the kernel. Must be non-negative.public PolynomialKernel(PolynomialKernel other)
other
- The PolynomialKernel to copy.public PolynomialKernel 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(Vectorizable x, Vectorizable y)
evaluate
in interface Kernel<Vectorizable>
x
- The first vector.y
- The second vector.public int getDegree()
public void setDegree(int degree)
degree
- The degree of the polynomial. Must be positive.public double getConstant()
public void setConstant(double constant)
constant
- The constant of the polynomial. Must be non-negative.