All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.classifiers.functions.supportVector.NormalizedPolyKernel Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This version represents the developer version, the "bleeding edge" of development, you could say. New functionality gets added to this version.

There is a newer version: 3.9.6
Show newest version
/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 *    NormalizedPolyKernel.java
 *    Copyright (C) 1999-2012 University of Waikato, Hamilton, New Zealand
 *
 */

package weka.classifiers.functions.supportVector;

import weka.core.Instance;
import weka.core.Instances;
import weka.core.RevisionUtils;

/**
 
 * The normalized polynomial kernel.
* K(x,y) = <x,y>/sqrt(<x,x><y,y>) where <x,y> = PolyKernel(x,y) *

* * Valid options are:

* *

 -D
 *  Enables debugging output (if available) to be printed.
 *  (default: off)
* *
 -C <num>
 *  The size of the cache (a prime number), 0 for full cache and 
 *  -1 to turn it off.
 *  (default: 250007)
* *
 -E <num>
 *  The Exponent to use.
 *  (default: 1.0)
* *
 -L
 *  Use lower-order terms.
 *  (default: no)
* * * @author Eibe Frank ([email protected]) * @version $Revision: 14512 $ */ public class NormalizedPolyKernel extends PolyKernel { /** for serialization */ static final long serialVersionUID = 1248574185532130851L; /** * default constructor - does nothing */ public NormalizedPolyKernel() { super(); setExponent(2.0); } /** * Creates a new NormalizedPolyKernel instance. * * @param dataset the training dataset used. * @param cacheSize the size of the cache (a prime number) * @param exponent the exponent to use * @param lowerOrder whether to use lower-order terms * @throws Exception if something goes wrong */ public NormalizedPolyKernel(Instances dataset, int cacheSize, double exponent, boolean lowerOrder) throws Exception { super(dataset, cacheSize, exponent, lowerOrder); } /** * Returns a string describing the kernel * * @return a description suitable for displaying in the * explorer/experimenter gui */ public String globalInfo() { return "The normalized polynomial kernel.\n" + "K(x,y) = /sqrt() where = PolyKernel(x,y)"; } /** * Computes the result of the kernel function for two instances. * If id1 == -1, eval use inst1 instead of an instance in the dataset. * Redefines the eval function of PolyKernel. * * @param id1 the index of the first instance in the dataset * @param id2 the index of the second instance in the dataset * @param inst1 the instance corresponding to id1 (used if id1 == -1) * @return the result of the kernel function * @throws Exception if something goes wrong */ public double eval(int id1, int id2, Instance inst1) throws Exception { double div = Math.sqrt(super.eval(id1, id1, inst1) * ((m_keys != null) ? super.eval(id2, id2, m_data.instance(id2)) : super.eval(-1, -1, m_data.instance(id2)))); if(div != 0){ return super.eval(id1, id2, inst1) / div; } else { return 0; } } /** * Sets the exponent value (must be different from 1.0). * * @param value the exponent value */ public void setExponent(double value) { if (value != 1.0) super.setExponent(value); else System.out.println("A linear kernel, i.e., Exponent=1, is not possible!"); } /** * returns a string representation for the Kernel * * @return a string representaiton of the kernel */ public String toString() { String result; if (getUseLowerOrder()) result = "Normalized Poly Kernel with lower order: K(x,y) = (+1)^" + getExponent() + "/" + "((+1)^" + getExponent() + "*" + "(+1)^" + getExponent() + ")^(1/2)"; else result = "Normalized Poly Kernel: K(x,y) = ^" + getExponent() + "/" + "(^" + getExponent() + "*" + "^" + getExponent() + ")^(1/2)"; return result; } /** * Returns the revision string. * * @return the revision */ public String getRevision() { return RevisionUtils.extract("$Revision: 14512 $"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy