weka.classifiers.mi.supportVector.MIPolyKernel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multiInstanceLearning Show documentation
Show all versions of multiInstanceLearning Show documentation
A collection of multi-instance learning classifiers. Includes the Citation KNN method, several variants of the diverse density method, support vector machines for multi-instance learning, simple wrappers for applying standard propositional learners to multi-instance data, decision tree and rule learners, and some other methods.
The 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 .
*/
/*
* MIPolyKernel.java
* Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
*
*/
package weka.classifiers.mi.supportVector;
import weka.classifiers.functions.supportVector.PolyKernel;
import weka.core.Capabilities;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.MultiInstanceCapabilitiesHandler;
import weka.core.RevisionUtils;
import weka.core.Capabilities.Capability;
/**
* The polynomial kernel : K(x, y) = <x, y>^p or K(x, y) = (<x, y>+1)^p
*
*
* Valid options are:
*
* -D
* Enables debugging output (if available) to be printed.
* (default: off)
*
* -no-checks
* Turns off all checks - use with caution!
* (default: checks on)
*
* -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])
* @author Shane Legg ([email protected]) (sparse vector code)
* @author Stuart Inglis ([email protected]) (sparse vector code)
* @author Lin Dong ([email protected]) (MIkernel)
* @version $Revision: 9142 $
*/
public class MIPolyKernel
extends PolyKernel
implements MultiInstanceCapabilitiesHandler {
/** for serialiation */
private static final long serialVersionUID = 7926421479341051777L;
/**
* default constructor - does nothing.
*/
public MIPolyKernel() {
super();
}
/**
* Creates a new MIPolyKernel
instance.
*
* @param data 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 MIPolyKernel(Instances data, int cacheSize, double exponent,
boolean lowerOrder) throws Exception {
super(data, cacheSize, exponent, lowerOrder);
}
/**
*
* @param id1 the index of instance 1
* @param id2 the index of instance 2
* @param inst1 the instance 1 object
* @return the dot product
* @throws Exception if something goes wrong
*/
protected double evaluate(int id1, int id2, Instance inst1)
throws Exception {
double result, res;
Instances data1= new Instances(inst1.relationalValue(1));
Instances data2;
if(id1==id2)
data2= new Instances(data1);
else
data2 = new Instances (m_data.instance(id2).relationalValue(1));
res=0;
for(int i=0; i