程序包 weka.core

类 Capabilities

java.lang.Object
weka.core.Capabilities
所有已实现的接口:
Serializable, Cloneable, RevisionHandler

public class Capabilities extends Object implements Cloneable, Serializable, RevisionHandler
A class that describes the capabilites (e.g., handling certain types of attributes, missing values, types of classes, etc.) of a specific classifier. By default, the classifier is capable of nothing. This ensures that new features have to be enabled explicitly.

A common code fragment for making use of the capabilities in a classifier would be this:

 public void buildClassifier(Instances instances) sthrows Exception {
   // can the classifier handle the data?
   getCapabilities().testWithFail(instances);
   ...
   // possible deletion of instances with missing class labels, etc.
 
For only testing a single attribute, use this:
   ...
   Attribute att = instances.attribute(0);
   getCapabilities().testWithFail(att);
   ...
 
Or for testing the class attribute (uses the capabilities that are especially for the class):
   ...
   Attribute att = instances.classAttribute();
   getCapabilities().testWithFail(att, true);
   ...
 
版本:
$Revision: 9140 $
作者:
FracPete (fracpete at waikato dot ac dot nz)
另请参阅:
  • 字段详细资料

    • PROPERTIES_FILE

      public static final String PROPERTIES_FILE
      the properties file for managing the tests
      另请参阅:
  • 构造器详细资料

    • Capabilities

      public Capabilities(CapabilitiesHandler owner)
      initializes the capabilities for the given owner
      参数:
      owner - the object that produced this Capabilities instance
  • 方法详细资料

    • clone

      public Object clone()
      Creates and returns a copy of this object.
      返回:
      a clone of this object
    • assign

      public void assign(Capabilities c)
      retrieves the data from the given Capabilities object
      参数:
      c - the capabilities object to initialize with
    • and

      public void and(Capabilities c)
      performs an AND conjunction with the capabilities of the given Capabilities object and updates itself
      参数:
      c - the capabilities to AND with
    • or

      public void or(Capabilities c)
      performs an OR conjunction with the capabilities of the given Capabilities object and updates itself
      参数:
      c - the capabilities to OR with
    • supports

      public boolean supports(Capabilities c)
      Returns true if the currently set capabilities support at least all of the capabiliites of the given Capabilities object (checks only the enum!)
      参数:
      c - the capabilities to support at least
      返回:
      true if all the requested capabilities are supported
    • supportsMaybe

      public boolean supportsMaybe(Capabilities c)
      Returns true if the currently set capabilities support (or have a dependency) at least all of the capabilities of the given Capabilities object (checks only the enum!)
      参数:
      c - the capabilities (or dependencies) to support at least
      返回:
      true if all the requested capabilities are supported (or at least have a dependency)
    • setOwner

      public void setOwner(CapabilitiesHandler value)
      sets the owner of this capabilities object
      参数:
      value - the new owner
    • getOwner

      public CapabilitiesHandler getOwner()
      returns the owner of this capabilities object
      返回:
      the current owner of this capabilites object
    • setMinimumNumberInstances

      public void setMinimumNumberInstances(int value)
      sets the minimum number of instances that have to be in the dataset
      参数:
      value - the minimum number of instances
    • getMinimumNumberInstances

      public int getMinimumNumberInstances()
      returns the minimum number of instances that have to be in the dataset
      返回:
      the minimum number of instances
    • capabilities

      public Iterator capabilities()
      Returns an Iterator over the stored capabilities
      返回:
      iterator over the current capabilities
    • dependencies

      public Iterator dependencies()
      Returns an Iterator over the stored dependencies
      返回:
      iterator over the current dependencies
    • enable

      public void enable(Capabilities.Capability c)
      enables the given capability. Enabling NOMINAL_ATTRIBUTES also enables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Enabling BINARY_ATTRIBUTES also enables UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Enabling UNARY_ATTRIBUTES also enables EMPTY_NOMINAL_ATTRIBUTES. But NOMINAL_CLASS only enables BINARY_CLASS, since normal schemes in Weka don't work with datasets that have only 1 class label (or none).
      参数:
      c - the capability to enable
    • enableDependency

      public void enableDependency(Capabilities.Capability c)
      enables the dependency flag for the given capability Enabling NOMINAL_ATTRIBUTES also enables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Enabling BINARY_ATTRIBUTES also enables UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Enabling UNARY_ATTRIBUTES also enables EMPTY_NOMINAL_ATTRIBUTES. But NOMINAL_CLASS only enables BINARY_CLASS, since normal schemes in Weka don't work with datasets that have only 1 class label (or none).
      参数:
      c - the capability to enable the dependency flag for
    • enableAllClasses

      public void enableAllClasses()
      enables all class types
      另请参阅:
    • enableAllClassDependencies

      public void enableAllClassDependencies()
      enables all class type dependencies
      另请参阅:
    • enableAllAttributes

      public void enableAllAttributes()
      enables all attribute types
      另请参阅:
    • enableAllAttributeDependencies

      public void enableAllAttributeDependencies()
      enables all attribute type dependencies
      另请参阅:
    • enableAll

      public void enableAll()
      enables all attribute and class types (including dependencies)
    • disable

      public void disable(Capabilities.Capability c)
      disables the given capability Disabling NOMINAL_ATTRIBUTES also disables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Disabling BINARY_ATTRIBUTES also disables UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Disabling UNARY_ATTRIBUTES also disables EMPTY_NOMINAL_ATTRIBUTES. The same hierarchy applies to the class capabilities.
      参数:
      c - the capability to disable
    • disableDependency

      public void disableDependency(Capabilities.Capability c)
      disables the dependency of the given capability Disabling NOMINAL_ATTRIBUTES also disables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Disabling BINARY_ATTRIBUTES also disables UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Disabling UNARY_ATTRIBUTES also disables EMPTY_NOMINAL_ATTRIBUTES. The same hierarchy applies to the class capabilities.
      参数:
      c - the capability to disable the dependency flag for
    • disableAllClasses

      public void disableAllClasses()
      disables all class types
      另请参阅:
    • disableAllClassDependencies

      public void disableAllClassDependencies()
      disables all class type dependencies
      另请参阅:
    • disableAllAttributes

      public void disableAllAttributes()
      disables all attribute types
      另请参阅:
    • disableAllAttributeDependencies

      public void disableAllAttributeDependencies()
      disables all attribute type dependencies
      另请参阅:
    • disableAll

      public void disableAll()
      disables all attribute and class types (including dependencies)
    • getClassCapabilities

      public Capabilities getClassCapabilities()
      returns all class capabilities
      返回:
      all capabilities regarding the class
      另请参阅:
    • getAttributeCapabilities

      public Capabilities getAttributeCapabilities()
      returns all attribute capabilities
      返回:
      all capabilities regarding attributes
      另请参阅:
    • getOtherCapabilities

      public Capabilities getOtherCapabilities()
      returns all other capabilities, besides class and attribute related ones
      返回:
      all other capabilities, besides class and attribute related ones
    • handles

      public boolean handles(Capabilities.Capability c)
      returns true if the classifier handler has the specified capability
      参数:
      c - the capability to test
      返回:
      true if the classifier handler has the capability
    • hasDependency

      public boolean hasDependency(Capabilities.Capability c)
      returns true if the classifier handler has a dependency for the specified capability
      参数:
      c - the capability to test
      返回:
      true if the classifier handler has a dependency for the capability
    • hasDependencies

      public boolean hasDependencies()
      Checks whether there are any dependencies at all
      返回:
      true if there is at least one dependency for a capability
    • getFailReason

      public Exception getFailReason()
      returns the reason why the tests failed, is null if tests succeeded
      返回:
      the reason why the tests failed
    • test

      public boolean test(Attribute att)
      Test the given attribute, whether it can be processed by the handler, given its capabilities. The method assumes that the specified attribute is not the class attribute.
      参数:
      att - the attribute to test
      返回:
      true if all the tests succeeded
      另请参阅:
    • test

      public boolean test(Attribute att, boolean isClass)
      Test the given attribute, whether it can be processed by the handler, given its capabilities.
      参数:
      att - the attribute to test
      isClass - whether this attribute is the class attribute
      返回:
      true if all the tests succeeded
      另请参阅:
      • m_AttributeTest
    • test

      public boolean test(Instances data)
      Tests the given data, whether it can be processed by the handler, given its capabilities. Classifiers implementing the MultiInstanceCapabilitiesHandler interface are checked automatically for their multi-instance Capabilities (if no bags, then only the bag-structure, otherwise only the first bag).
      参数:
      data - the data to test
      返回:
      true if all the tests succeeded
      另请参阅:
    • test

      public boolean test(Instances data, int fromIndex, int toIndex)
      Tests a certain range of attributes of the given data, whether it can be processed by the handler, given its capabilities. Classifiers implementing the MultiInstanceCapabilitiesHandler interface are checked automatically for their multi-instance Capabilities (if no bags, then only the bag-structure, otherwise only the first bag).
      参数:
      data - the data to test
      fromIndex - the range of attributes - start (incl.)
      toIndex - the range of attributes - end (incl.)
      返回:
      true if all the tests succeeded
      另请参阅:
    • testWithFail

      public void testWithFail(Attribute att) throws Exception
      tests the given attribute by calling the test(Attribute,boolean) method and throws an exception if the test fails. The method assumes that the specified attribute is not the class attribute.
      参数:
      att - the attribute to test
      抛出:
      Exception - in case the attribute doesn't pass the tests
      另请参阅:
    • testWithFail

      public void testWithFail(Attribute att, boolean isClass) throws Exception
      tests the given attribute by calling the test(Attribute,boolean) method and throws an exception if the test fails.
      参数:
      att - the attribute to test
      isClass - whether this attribute is the class attribute
      抛出:
      Exception - in case the attribute doesn't pass the tests
      另请参阅:
    • testWithFail

      public void testWithFail(Instances data, int fromIndex, int toIndex) throws Exception
      tests the given data by calling the test(Instances,int,int) method and throws an exception if the test fails.
      参数:
      data - the data to test
      fromIndex - the range of attributes - start (incl.)
      toIndex - the range of attributes - end (incl.)
      抛出:
      Exception - in case the data doesn't pass the tests
      另请参阅:
    • testWithFail

      public void testWithFail(Instances data) throws Exception
      tests the given data by calling the test(Instances) method and throws an exception if the test fails.
      参数:
      data - the data to test
      抛出:
      Exception - in case the data doesn't pass the tests
      另请参阅:
    • toString

      public String toString()
      returns a string representation of the capabilities
      覆盖:
      toString 在类中 Object
      返回:
      a string representation of this object
    • toSource

      public String toSource(String objectname)
      turns the capabilities object into source code. The returned source code is a block that creates a Capabilities object named 'objectname' and enables all the capabilities of this Capabilities object.
      参数:
      objectname - the name of the Capabilities object being instantiated
      返回:
      the generated source code
    • toSource

      public String toSource(String objectname, int indent)
      turns the capabilities object into source code. The returned source code is a block that creates a Capabilities object named 'objectname' and enables all the capabilities of this Capabilities object.
      参数:
      objectname - the name of the Capabilities object being instantiated
      indent - the number of blanks to indent
      返回:
      the generated source code
    • forInstances

      public static Capabilities forInstances(Instances data) throws Exception
      returns a Capabilities object specific for this data. The multi-instance capability is not checked as well as the minimum number of instances is not set.
      参数:
      data - the data to base the capabilities on
      返回:
      a data-specific capabilities object
      抛出:
      Exception - in case an error occurrs, e.g., an unknown attribute type
    • forInstances

      public static Capabilities forInstances(Instances data, boolean multi) throws Exception
      returns a Capabilities object specific for this data. The minimum number of instances is not set, the check for multi-instance data is optional.
      参数:
      data - the data to base the capabilities on
      multi - if true then the structure is checked, too
      返回:
      a data-specific capabilities object
      抛出:
      Exception - in case an error occurrs, e.g., an unknown attribute type
    • main

      public static void main(String[] args) throws Exception
      loads the given dataset and prints the Capabilities necessary to process it.

      Valid parameters:

      -file filename
      the file to load -c index the explicit index of the class attribute (default: none)

      参数:
      args - the commandline arguments
      抛出:
      Exception - if something goes wrong
    • getRevision

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