[Home] DMelt member access. Java source code: weka.filters.unsupervised.instance.ReservoirSample
/*
* 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 .
*/
/*
* ReservoirSample.java
* Copyright (C) 2007-2012 University of Waikato, Hamilton, New Zealand
*
*/
package weka.filters.unsupervised.instance;
import weka.core.*;
import weka.core.Capabilities.Capability;
import weka.filters.Filter;
import weka.filters.StreamableFilter;
import weka.filters.UnsupervisedFilter;
import weka.gui.ProgrammaticProperty;
import java.io.IOException;
import java.io.StringReader;
import java.util.Enumeration;
import java.util.Random;
import java.util.Vector;
/**
* Produces a random subsample of a dataset using the
* reservoir sampling Algorithm "R" by Vitter. The original data set does not
* have to fit into main memory, but the reservoir does.
*
*
*
* BibTeX:
*
*
* @article{Vitter1985,
* author = {J. S. Vitter},
* journal = {ACM Transactions on Mathematical Software},
* number = {1}
* volume = {11}
* pages = {37-57},
* title = {Random Sampling with a Reservoir},
* year = {1985}
* }
*
*
*
* Valid options are:
*
*
*
* -S <num>
* Specify the random number seed (default 1)
*
*
*
* -Z <num>
* The size of the output dataset - number of instances
* (default 100)
*
*
*
*
* @author Mark Hall (mhall{[at]}pentaho{[dot]}org)
* @version $Revision: 14508 $
*/
public class ReservoirSample extends Filter implements UnsupervisedFilter,
OptionHandler, StreamableFilter, Randomizable, WeightedAttributesHandler {
/** for serialization */
static final long serialVersionUID = 3119607037607101160L;
/** The subsample size, number of instances% */
protected int m_SampleSize = 100;
/** Holds the sub-sample (reservoir) */
protected Object[] m_subSample;
/** The current instance being processed */
protected int m_currentInst;
/** The random number generator seed */
protected int m_RandomSeed = 1;
/** The random number generator */
protected Random m_random;
/** True if the incoming data contains string attributes */
protected boolean m_containsStringAtts;
/**
* Returns a string describing this filter
*
* @return a description of the classifier suitable for displaying in the
* explorer/experimenter gui
*/
public String globalInfo() {
return "Produces a random subsample of a dataset using the reservoir sampling "
+ "Algorithm \"R\" by Vitter. The original data set does not have to fit "
+ "into main memory, but the reservoir does. ";
}
/**
* Returns an enumeration describing the available options.
*
* @return an enumeration of all the available options.
*/
@Override
public Enumeration