程序包 weka.filters

类 Filter

java.lang.Object
weka.filters.Filter
所有已实现的接口:
Serializable, CapabilitiesHandler, RevisionHandler
直接已知子类:
AbstractTimeSeries, Add, AddCluster, AddExpression, AddID, AddNoise, AddValues, AllFilter, AttributeSelection, ChangeDateFormat, ClassOrder, ClusterMembership, Copy, Discretize, FirstOrder, MakeIndicator, MergeTwoValues, MultiInstanceToPropositional, NominalToBinary, NominalToBinary, NominalToString, NonSparseToSparse, Normalize, NumericTransform, Obfuscate, PotentialClassIgnorer, PrincipalComponents, PropositionalToMultiInstance, Randomize, RandomProjection, Remove, RemoveFolds, RemoveFrequentValues, RemoveMisclassified, RemovePercentage, RemoveRange, RemoveType, RemoveUseless, RemoveWithValues, Reorder, Resample, Resample, ReservoirSample, SimpleFilter, SMOTE, SparseToNonSparse, SpreadSubsample, StratifiedRemoveFolds, StringToNominal, StringToWordVector, SwapValues

public abstract class Filter extends Object implements Serializable, CapabilitiesHandler, RevisionHandler
An abstract class for instance filters: objects that take instances as input, carry out some transformation on the instance and then output the instance. The method implementations in this class assume that most of the work will be done in the methods overridden by subclasses.

A simple example of filter use. This example doesn't remove instances from the output queue until all instances have been input, so has higher memory consumption than an approach that uses output instances as they are made available:

  Filter filter = ..some type of filter..
  Instances instances = ..some instances..
  for (int i = 0; i < data.numInstances(); i++) {
    filter.input(data.instance(i));
  }
  filter.batchFinished();
  Instances newData = filter.outputFormat();
  Instance processed;
  while ((processed = filter.output()) != null) {
    newData.add(processed);
  }
  ..do something with newData..
 
版本:
$Revision: 7880 $
作者:
Len Trigg (trigg@cs.waikato.ac.nz)
另请参阅:
  • 构造器详细资料

    • Filter

      public Filter()
  • 方法详细资料

    • isNewBatch

      public boolean isNewBatch()
      Returns true if the a new batch was started, either a new instance of the filter was created or the batchFinished() method got called.
      返回:
      true if a new batch has been initiated
      另请参阅:
    • isFirstBatchDone

      public boolean isFirstBatchDone()
      Returns true if the first batch of instances got processed. Necessary for supervised filters, which "learn" from the first batch and then shouldn't get updated with subsequent calls of batchFinished().
      返回:
      true if the first batch has been processed
      另请参阅:
    • getCapabilities

      public Capabilities getCapabilities()
      Returns the Capabilities of this filter. Derived filters have to override this method to enable capabilities.
      指定者:
      getCapabilities 在接口中 CapabilitiesHandler
      返回:
      the capabilities of this object
      另请参阅:
    • getRevision

      public String getRevision()
      Returns the revision string.
      指定者:
      getRevision 在接口中 RevisionHandler
      返回:
      the revision
    • getCapabilities

      public Capabilities getCapabilities(Instances data)
      Returns the Capabilities of this filter, customized based on the data. I.e., if removes all class capabilities, in case there's not class attribute present or removes the NO_CLASS capability, in case that there's a class present.
      参数:
      data - the data to use for customization
      返回:
      the capabilities of this object, based on the data
      另请参阅:
    • setInputFormat

      public boolean setInputFormat(Instances instanceInfo) throws Exception
      Sets the format of the input instances. If the filter is able to determine the output format before seeing any input instances, it does so here. This default implementation clears the output format and output queue, and the new batch flag is set. Overriders should call super.setInputFormat(Instances)
      参数:
      instanceInfo - an Instances object containing the input instance structure (any instances contained in the object are ignored - only the structure is required).
      返回:
      true if the outputFormat may be collected immediately
      抛出:
      Exception - if the inputFormat can't be set successfully
    • getOutputFormat

      public Instances getOutputFormat()
      Gets the format of the output instances. This should only be called after input() or batchFinished() has returned true. The relation name of the output instances should be changed to reflect the action of the filter (eg: add the filter name and options).
      返回:
      an Instances object containing the output instance structure only.
      抛出:
      NullPointerException - if no input structure has been defined (or the output format hasn't been determined yet)
    • input

      public boolean input(Instance instance) throws Exception
      Input an instance for filtering. Ordinarily the instance is processed and made available for output immediately. Some filters require all instances be read before producing output, in which case output instances should be collected after calling batchFinished(). If the input marks the start of a new batch, the output queue is cleared. This default implementation assumes all instance conversion will occur when batchFinished() is called.
      参数:
      instance - the input instance
      返回:
      true if the filtered instance may now be collected with output().
      抛出:
      NullPointerException - if the input format has not been defined.
      Exception - if the input instance was not of the correct format or if there was a problem with the filtering.
    • batchFinished

      public boolean batchFinished() throws Exception
      Signify that this batch of input to the filter is finished. If the filter requires all instances prior to filtering, output() may now be called to retrieve the filtered instances. Any subsequent instances filtered should be filtered based on setting obtained from the first batch (unless the inputFormat has been re-assigned or new options have been set). This default implementation assumes all instance processing occurs during inputFormat() and input().
      返回:
      true if there are instances pending output
      抛出:
      NullPointerException - if no input structure has been defined,
      Exception - if there was a problem finishing the batch.
    • output

      public Instance output()
      Output an instance after filtering and remove from the output queue.
      返回:
      the instance that has most recently been filtered (or null if the queue is empty).
      抛出:
      NullPointerException - if no output structure has been defined
    • outputPeek

      public Instance outputPeek()
      Output an instance after filtering but do not remove from the output queue.
      返回:
      the instance that has most recently been filtered (or null if the queue is empty).
      抛出:
      NullPointerException - if no input structure has been defined
    • numPendingOutput

      public int numPendingOutput()
      Returns the number of instances pending output
      返回:
      the number of instances pending output
      抛出:
      NullPointerException - if no input structure has been defined
    • isOutputFormatDefined

      public boolean isOutputFormatDefined()
      Returns whether the output format is ready to be collected
      返回:
      true if the output format is set
    • makeCopy

      public static Filter makeCopy(Filter model) throws Exception
      Creates a deep copy of the given filter using serialization.
      参数:
      model - the filter to copy
      返回:
      a deep copy of the filter
      抛出:
      Exception - if an error occurs
    • makeCopies

      public static Filter[] makeCopies(Filter model, int num) throws Exception
      Creates a given number of deep copies of the given filter using serialization.
      参数:
      model - the filter to copy
      num - the number of filter copies to create.
      返回:
      an array of filters.
      抛出:
      Exception - if an error occurs
    • useFilter

      public static Instances useFilter(Instances data, Filter filter) throws Exception
      Filters an entire set of instances through a filter and returns the new set.
      参数:
      data - the data to be filtered
      filter - the filter to be used
      返回:
      the filtered set of data
      抛出:
      Exception - if the filter can't be used successfully
    • toString

      public String toString()
      Returns a description of the filter, by default only the classname.
      覆盖:
      toString 在类中 Object
      返回:
      a string describing the filter
    • wekaStaticWrapper

      public static String wekaStaticWrapper(Sourcable filter, String className, Instances input, Instances output) throws Exception
      generates source code from the filter
      参数:
      filter - the filter to output as source
      className - the name of the generated class
      input - the input data the header is generated for
      output - the output data the header is generated for
      返回:
      the generated source code
      抛出:
      Exception - if source code cannot be generated
    • filterFile

      public static void filterFile(Filter filter, String[] options) throws Exception
      Method for testing filters.
      参数:
      filter - the filter to use
      options - should contain the following arguments:
      -i input_file
      -o output_file
      -c class_index
      -z classname (for filters implementing weka.filters.Sourcable)
      or -h for help on options
      抛出:
      Exception - if something goes wrong or the user requests help on command options
    • batchFilterFile

      public static void batchFilterFile(Filter filter, String[] options) throws Exception
      Method for testing filters ability to process multiple batches.
      参数:
      filter - the filter to use
      options - should contain the following arguments:
      -i (first) input file
      -o (first) output file
      -r (second) input file
      -s (second) output file
      -c class_index
      -z classname (for filters implementing weka.filters.Sourcable)
      or -h for help on options
      抛出:
      Exception - if something goes wrong or the user requests help on command options
    • main

      public static void main(String[] args)
      Main method for testing this class.
      参数:
      args - should contain arguments to the filter: use -h for help