001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022
023package org.biojava.stats.svm;
024
025/**
026 * This kernel computes all possible products of order features in feature
027 * space. This is done by computing (a.k(i,j) + c)^order for some other kernel k
028 * that defines a dot product in some feature space.
029 *
030 * @author Thomas Down
031 * @author Matthew Pocock
032 */
033public class PolynomialKernel extends NestedKernel {
034    private double order;
035    private double a;
036    private double c;
037
038    public PolynomialKernel() {
039      this(null, 3.0, 1.0, 1.0);
040    }
041
042    public PolynomialKernel(SVMKernel nested, double order, double a, double c) {
043      super(nested);
044      this.order = order;
045      this.a = a;
046      this.c = c;
047    }
048    
049    public double evaluate(Object a, Object b) {
050      return Math.pow(getMultiplier()*getNestedKernel().evaluate(a, b)
051                      + getConstant(),
052                      getOrder());
053    }
054
055    public double getOrder() {
056      return order;
057    }
058
059    public void setOrder(double o) {
060      this.order = o;
061    }
062
063    public double getConstant() {
064      return c;
065    }
066
067    public void setConstant(double c) {
068      this.c = c;
069    }
070    
071    public double getMultiplier() {
072      return a;
073    }
074    
075    public void setMultiplier(double m) {
076      this.a = m;
077    }
078
079    public String toString() {
080      return "Polynomial kernel K(x, y | k) = ("
081        + getMultiplier() + " * k(x, y) + " + c + ")^" + order
082        + ". k = " + getNestedKernel().toString();
083    }
084}