weka.classifiers.functions.supportVector.CachedKernel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weka-dev Show documentation
Show all versions of weka-dev Show documentation
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.
/*
* 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 .
*/
/*
* CachedKernel.java
* Copyright (C) 2005-2012 University of Waikato, Hamilton, New Zealand
*/
package weka.classifiers.functions.supportVector;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.Utils;
/**
* Base class for RBFKernel and PolyKernel that implements a simple LRU.
* (least-recently-used) cache if the cache size is set to a value > 0.
* Otherwise it uses a full cache.
*
* @author Eibe Frank ([email protected])
* @author Shane Legg ([email protected]) (sparse vector code)
* @author Stuart Inglis ([email protected]) (sparse vector code)
* @author J. Lindgren (jtlindgr{at}cs.helsinki.fi) (RBF kernel)
* @author Steven Hugg ([email protected]) (refactored, LRU cache)
* @author Bernhard Pfahringer ([email protected]) (full cache)
* @version $Revision: 10169 $
*/
public abstract class CachedKernel extends Kernel {
/** for serialization */
private static final long serialVersionUID = 702810182699015136L;
/** Counts the number of kernel evaluations. */
protected int m_kernelEvals;
/** Counts the number of kernel cache hits. */
protected int m_cacheHits;
/** The size of the cache (a prime number) */
protected int m_cacheSize = 250007;
/** Kernel cache */
protected double[] m_storage;
protected long[] m_keys;
/** The kernel matrix if full cache is used (i.e. size is set to 0) */
protected double[][] m_kernelMatrix;
/** The number of instance in the dataset */
protected int m_numInsts;
/** number of cache slots in an entry */
protected int m_cacheSlots = 4;
/**
* default constructor - does nothing.
*/
public CachedKernel() {
super();
}
/**
* Initializes the kernel cache. The actual size of the cache in bytes is (64
* * cacheSize).
*
* @param data the data to use
* @param cacheSize the cache size
* @throws Exception if something goes wrong
*/
protected CachedKernel(Instances data, int cacheSize) throws Exception {
super();
setCacheSize(cacheSize);
buildKernel(data);
}
/**
* Returns an enumeration describing the available options.
*
* @return an enumeration of all the available options.
*/
@Override
public Enumeration
© 2015 - 2024 Weber Informatics LLC | Privacy Policy