gov.sandia.cognition.learning.function.kernel
Class PolynomialKernel

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.function.kernel.PolynomialKernel
All Implemented Interfaces:
Kernel<Vectorizable>, CloneableSerializable, Serializable, Cloneable

@CodeReview(reviewer="Kevin R. Dixon",
            date="2009-07-08",
            changesNeeded=false,
            comments="Looks fine.")
public class PolynomialKernel
extends AbstractCloneableSerializable
implements Kernel<Vectorizable>

The PolynomialKernel class implements a kernel for two given vectors that is the polynomial function:
(x dot y + c)^d
d is the degree of the polynomial, which must be a positive integer. c is the constant that is used, which should be a non-negative number. Normally c is either 0.0 or 1.0.

Since:
2.0
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
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 Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DEGREE

public static final int DEFAULT_DEGREE
The default degree is 2.

See Also:
Constant Field Values

DEFAULT_CONSTANT

public static final double DEFAULT_CONSTANT
The default constant is 1.0.

See Also:
Constant Field Values

degree

protected int degree
The degree of the polynomial. Must be positive.


constant

protected double constant
The constant for the polynomial.

Constructor Detail

PolynomialKernel

public PolynomialKernel()
Creates a new instance of PolynomialKernel with a degree of 2 and a constant of 1.0.


PolynomialKernel

public PolynomialKernel(int degree)
Creates a new instance of PolynomialKernel with the given degree and a constant of 1.0.

Parameters:
degree - The degree of the kernel. Must be positive.

PolynomialKernel

public PolynomialKernel(int degree,
                        double constant)
Creates a new instance of PolynomialKernel with the given degree and constant.

Parameters:
degree - The degree of the kernel. Must be positive.
constant - The constant of the kernel. Must be non-negative.

PolynomialKernel

public PolynomialKernel(PolynomialKernel other)
Creates a new copy of a PolynomialKernel.

Parameters:
other - The PolynomialKernel to copy.
Method Detail

clone

public PolynomialKernel 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 AbstractCloneableSerializable
Returns:
A clone of this object.

evaluate

public 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.

Specified by:
evaluate in interface Kernel<Vectorizable>
Parameters:
x - The first vector.
y - The second vector.
Returns:
The result of the polynomial kernel: (x dot y + c)^d

getDegree

public int getDegree()
Gets the degree of the polynomial.

Returns:
The degree of the polynomial.

setDegree

public void setDegree(int degree)
Sets the degree of the polynomial.

Parameters:
degree - The degree of the polynomial. Must be positive.

getConstant

public double getConstant()
Gets the constant of the polynomial.

Returns:
The constant of the polynomial.

setConstant

public void setConstant(double constant)
Gets the constant of the polynomial.

Parameters:
constant - The constant of the polynomial. Must be non-negative.