Java Doc for Instance.java in  » Science » weka » weka » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » weka » weka.core 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   weka.core.Instance

All known Subclasses:   weka.associations.tertius.IndividualInstance,  weka.core.SparseInstance,
Instance
public class Instance implements Copyable,Serializable(Code)
Class for handling an instance. All values (numeric, date, nominal, string or relational) are internally stored as floating-point numbers. If an attribute is nominal (or a string or relational), the stored value is the index of the corresponding nominal (or string or relational) value in the attribute's definition. We have chosen this approach in favor of a more elegant object-oriented approach because it is much faster.

Typical usage (code from the main() method of this class):

...
// Create empty instance with three attribute values
Instance inst = new Instance(3);

// Set instance's values for the attributes "length", "weight", and "position"
inst.setValue(length, 5.3);
inst.setValue(weight, 300);
inst.setValue(position, "first");

// Set instance's dataset to be the dataset "race"
inst.setDataset(race);

// Print the instance
System.out.println("The instance: " + inst);
...

All methods that change an instance are safe, ie. a change of an instance does not affect any other instances. All methods that change an instance's attribute values clone the attribute value vector before it is changed. If your application heavily modifies instance values, it may be faster to create a new instance from scratch.
author:
   Eibe Frank (eibe@cs.waikato.ac.nz)
version:
   $Revision: 1.25 $



Field Summary
final protected static  doubleMISSING_VALUE
     Constant representing a missing value.
protected  double[]m_AttValues
     The instance's attribute values.
protected  Instancesm_Dataset
     The dataset the instance has access to.
protected  doublem_Weight
     The instance's weight.
final static  longserialVersionUID
    

Constructor Summary
public  Instance(Instance instance)
     Constructor that copies the attribute values and the weight from the given instance.
public  Instance(double weight, double[] attValues)
     Constructor that inititalizes instance variable with given values.
public  Instance(int numAttributes)
     Constructor of an instance that sets weight to one, all values to be missing, and the reference to the dataset to null.
protected  Instance()
     Private constructor for subclasses.

Method Summary
public  Attributeattribute(int index)
     Returns the attribute with the given index.
public  AttributeattributeSparse(int indexOfIndex)
     Returns the attribute with the given index.
public  AttributeclassAttribute()
     Returns class attribute.
public  intclassIndex()
     Returns the class attribute's index.
public  booleanclassIsMissing()
     Tests if an instance's class is missing.
public  doubleclassValue()
     Returns an instance's class value in internal format.
public  Objectcopy()
     Produces a shallow copy of this instance.
public  Instancesdataset()
     Returns the dataset this instance has access to.
public  voiddeleteAttributeAt(int position)
     Deletes an attribute at the given position (0 to numAttributes() - 1).
public  EnumerationenumerateAttributes()
     Returns an enumeration of all the attributes.
public  booleanequalHeaders(Instance inst)
     Tests if the headers of two instances are equivalent.
 voidforceDeleteAttributeAt(int position)
     Deletes an attribute at the given position (0 to numAttributes() - 1).
 voidforceInsertAttributeAt(int position)
     Inserts an attribute at the given position (0 to numAttributes()) and sets its value to be missing.
public  booleanhasMissingValue()
     Tests whether an instance has a missing value.
public  intindex(int position)
     Returns the index of the attribute stored at the given position.
public  voidinsertAttributeAt(int position)
     Inserts an attribute at the given position (0 to numAttributes()).
public  booleanisMissing(int attIndex)
     Tests if a specific value is "missing".
public  booleanisMissing(Attribute att)
     Tests if a specific value is "missing".
public  booleanisMissingSparse(int indexOfIndex)
     Tests if a specific value is "missing".
public static  booleanisMissingValue(double val)
     Tests if the given value codes "missing".
public static  voidmain(String[] options)
     Main method for testing this class.
public  InstancemergeInstance(Instance inst)
     Merges this instance with the given instance and returns the result.
public static  doublemissingValue()
     Returns the double that codes "missing".
public  intnumAttributes()
     Returns the number of attributes.
public  intnumClasses()
     Returns the number of class labels.
public  intnumValues()
     Returns the number of values present.
final public  InstancesrelationalValue(int attIndex)
     Returns the relational value of a relational attribute.
final public  InstancesrelationalValue(Attribute att)
     Returns the relational value of a relational attribute.
public  voidreplaceMissingValues(double[] array)
     Replaces all missing values in the instance with the values contained in the given array.
public  voidsetClassMissing()
     Sets the class value of an instance to be "missing".
public  voidsetClassValue(double value)
     Sets the class value of an instance to the given value (internal floating-point format).
final public  voidsetClassValue(String value)
     Sets the class value of an instance to the given value.
final public  voidsetDataset(Instances instances)
     Sets the reference to the dataset.
final public  voidsetMissing(int attIndex)
     Sets a specific value to be "missing".
final public  voidsetMissing(Attribute att)
     Sets a specific value to be "missing".
public  voidsetValue(int attIndex, double value)
     Sets a specific value in the instance to the given value (internal floating-point format).
final public  voidsetValue(int attIndex, String value)
     Sets a value of a nominal or string attribute to the given value.
final public  voidsetValue(Attribute att, double value)
     Sets a specific value in the instance to the given value (internal floating-point format).
final public  voidsetValue(Attribute att, String value)
     Sets a value of an nominal or string attribute to the given value.
public  voidsetValueSparse(int indexOfIndex, double value)
     Sets a specific value in the instance to the given value (internal floating-point format).
final public  voidsetWeight(double weight)
     Sets the weight of an instance.
final public  StringstringValue(int attIndex)
     Returns the value of a nominal, string, date, or relational attribute for the instance as a string.
final public  StringstringValue(Attribute att)
     Returns the value of a nominal, string, date, or relational attribute for the instance as a string.
public  double[]toDoubleArray()
     Returns the values of each attribute as an array of doubles.
public  StringtoString()
     Returns the description of one instance.
final public  StringtoString(int attIndex)
     Returns the description of one value of the instance as a string.
final public  StringtoString(Attribute att)
     Returns the description of one value of the instance as a string.
public  doublevalue(int attIndex)
     Returns an instance's attribute value in internal format.
public  doublevalue(Attribute att)
     Returns an instance's attribute value in internal format.
public  doublevalueSparse(int indexOfIndex)
     Returns an instance's attribute value in internal format.
final public  doubleweight()
     Returns the instance's weight.

Field Detail
MISSING_VALUE
final protected static double MISSING_VALUE(Code)
Constant representing a missing value.



m_AttValues
protected double[] m_AttValues(Code)
The instance's attribute values.



m_Dataset
protected Instances m_Dataset(Code)
The dataset the instance has access to. Null if the instance doesn't have access to any dataset. Only if an instance has access to a dataset, it knows about the actual attribute types.



m_Weight
protected double m_Weight(Code)
The instance's weight.



serialVersionUID
final static long serialVersionUID(Code)
for serialization




Constructor Detail
Instance
public Instance(Instance instance)(Code)
Constructor that copies the attribute values and the weight from the given instance. Reference to the dataset is set to null. (ie. the instance doesn't have access to information about the attribute types)
Parameters:
  instance - the instance from which the attributevalues and the weight are to be copied



Instance
public Instance(double weight, double[] attValues)(Code)
Constructor that inititalizes instance variable with given values. Reference to the dataset is set to null. (ie. the instance doesn't have access to information about the attribute types)
Parameters:
  weight - the instance's weight
Parameters:
  attValues - a vector of attribute values



Instance
public Instance(int numAttributes)(Code)
Constructor of an instance that sets weight to one, all values to be missing, and the reference to the dataset to null. (ie. the instance doesn't have access to information about the attribute types)
Parameters:
  numAttributes - the size of the instance



Instance
protected Instance()(Code)
Private constructor for subclasses. Does nothing.




Method Detail
attribute
public Attribute attribute(int index)(Code)
Returns the attribute with the given index.
Parameters:
  index - the attribute's index the attribute at the given position
throws:
  UnassignedDatasetException - if instance doesn't have access to adataset



attributeSparse
public Attribute attributeSparse(int indexOfIndex)(Code)
Returns the attribute with the given index. Does the same thing as attribute().
Parameters:
  indexOfIndex - the index of the attribute's index the attribute at the given position
throws:
  UnassignedDatasetException - if instance doesn't have access to adataset



classAttribute
public Attribute classAttribute()(Code)
Returns class attribute. the class attribute
throws:
  UnassignedDatasetException - if the class is not set or theinstance doesn't have access to a dataset



classIndex
public int classIndex()(Code)
Returns the class attribute's index. the class index as an integer
throws:
  UnassignedDatasetException - if instance doesn't have access to a dataset



classIsMissing
public boolean classIsMissing()(Code)
Tests if an instance's class is missing. true if the instance's class is missing
throws:
  UnassignedClassException - if the class is not set or the instance doesn'thave access to a dataset



classValue
public double classValue()(Code)
Returns an instance's class value in internal format. (ie. as a floating-point number) the corresponding value as a double (If the corresponding attribute is nominal (or a string) then it returns the value's index as a double).
throws:
  UnassignedClassException - if the class is not set or the instance doesn'thave access to a dataset



copy
public Object copy()(Code)
Produces a shallow copy of this instance. The copy has access to the same dataset. (if you want to make a copy that doesn't have access to the dataset, use new Instance(instance) the shallow copy



dataset
public Instances dataset()(Code)
Returns the dataset this instance has access to. (ie. obtains information about attribute types from) Null if the instance doesn't have access to a dataset. the dataset the instance has accesss to



deleteAttributeAt
public void deleteAttributeAt(int position)(Code)
Deletes an attribute at the given position (0 to numAttributes() - 1). Only succeeds if the instance does not have access to any dataset because otherwise inconsistencies could be introduced.
Parameters:
  position - the attribute's position
throws:
  RuntimeException - if the instance has access to adataset



enumerateAttributes
public Enumeration enumerateAttributes()(Code)
Returns an enumeration of all the attributes. enumeration of all the attributes
throws:
  UnassignedDatasetException - if the instance doesn'thave access to a dataset



equalHeaders
public boolean equalHeaders(Instance inst)(Code)
Tests if the headers of two instances are equivalent.
Parameters:
  inst - another instance true if the header of the given instance is equivalent to this instance's header
throws:
  UnassignedDatasetException - if instance doesn't have access to anydataset



forceDeleteAttributeAt
void forceDeleteAttributeAt(int position)(Code)
Deletes an attribute at the given position (0 to numAttributes() - 1).
Parameters:
  position - the attribute's position



forceInsertAttributeAt
void forceInsertAttributeAt(int position)(Code)
Inserts an attribute at the given position (0 to numAttributes()) and sets its value to be missing.
Parameters:
  position - the attribute's position



hasMissingValue
public boolean hasMissingValue()(Code)
Tests whether an instance has a missing value. Skips the class attribute if set. true if instance has a missing value.
throws:
  UnassignedDatasetException - if instance doesn't have access to anydataset



index
public int index(int position)(Code)
Returns the index of the attribute stored at the given position. Just returns the given value.
Parameters:
  position - the position the index of the attribute stored at the given position



insertAttributeAt
public void insertAttributeAt(int position)(Code)
Inserts an attribute at the given position (0 to numAttributes()). Only succeeds if the instance does not have access to any dataset because otherwise inconsistencies could be introduced.
Parameters:
  position - the attribute's position
throws:
  RuntimeException - if the instance has accesss to adataset
throws:
  IllegalArgumentException - if the position is out of range



isMissing
public boolean isMissing(int attIndex)(Code)
Tests if a specific value is "missing".
Parameters:
  attIndex - the attribute's index true if the value is "missing"



isMissing
public boolean isMissing(Attribute att)(Code)
Tests if a specific value is "missing". The given attribute has to belong to a dataset.
Parameters:
  att - the attribute true if the value is "missing"



isMissingSparse
public boolean isMissingSparse(int indexOfIndex)(Code)
Tests if a specific value is "missing". Does the same thing as isMissing() if applied to an Instance.
Parameters:
  indexOfIndex - the index of the attribute's index true if the value is "missing"



isMissingValue
public static boolean isMissingValue(double val)(Code)
Tests if the given value codes "missing".
Parameters:
  val - the value to be tested true if val codes "missing"



main
public static void main(String[] options)(Code)
Main method for testing this class.
Parameters:
  options - the commandline options - ignored



mergeInstance
public Instance mergeInstance(Instance inst)(Code)
Merges this instance with the given instance and returns the result. Dataset is set to null.
Parameters:
  inst - the instance to be merged with this one the merged instances



missingValue
public static double missingValue()(Code)
Returns the double that codes "missing". the double that codes "missing"



numAttributes
public int numAttributes()(Code)
Returns the number of attributes. the number of attributes as an integer



numClasses
public int numClasses()(Code)
Returns the number of class labels. the number of class labels as an integer if the class attribute is nominal, 1 otherwise.
throws:
  UnassignedDatasetException - if instance doesn't have access to anydataset



numValues
public int numValues()(Code)
Returns the number of values present. Always the same as numAttributes(). the number of values



relationalValue
final public Instances relationalValue(int attIndex)(Code)
Returns the relational value of a relational attribute.
Parameters:
  attIndex - the attribute's index the corresponding relation as an Instances object
throws:
  IllegalArgumentException - if the attribute is not arelation-valued attribute
throws:
  UnassignedDatasetException - if the instance doesn't belongto a dataset.



relationalValue
final public Instances relationalValue(Attribute att)(Code)
Returns the relational value of a relational attribute.
Parameters:
  att - the attribute the corresponding relation as an Instances object
throws:
  IllegalArgumentException - if the attribute is not arelation-valued attribute
throws:
  UnassignedDatasetException - if the instance doesn't belongto a dataset.



replaceMissingValues
public void replaceMissingValues(double[] array)(Code)
Replaces all missing values in the instance with the values contained in the given array. A deep copy of the vector of attribute values is performed before the values are replaced.
Parameters:
  array - containing the means and modes
throws:
  IllegalArgumentException - if numbers of attributes are unequal



setClassMissing
public void setClassMissing()(Code)
Sets the class value of an instance to be "missing". A deep copy of the vector of attribute values is performed before the value is set to be missing.
throws:
  UnassignedClassException - if the class is not set
throws:
  UnassignedDatasetException - if the instance doesn'thave access to a dataset



setClassValue
public void setClassValue(double value)(Code)
Sets the class value of an instance to the given value (internal floating-point format). A deep copy of the vector of attribute values is performed before the value is set.
Parameters:
  value - the new attribute value (If the correspondingattribute is nominal (or a string) then this is the new value'sindex as a double).
throws:
  UnassignedClassException - if the class is not set
throws:
  UnaddignedDatasetException - if the instance doesn'thave access to a dataset



setClassValue
final public void setClassValue(String value)(Code)
Sets the class value of an instance to the given value. A deep copy of the vector of attribute values is performed before the value is set.
Parameters:
  value - the new class value (If the classis a string attribute and the value can't be found,the value is added to the attribute).
throws:
  UnassignedClassException - if the class is not set
throws:
  UnassignedDatasetException - if the dataset is not set
throws:
  IllegalArgumentException - if the attribute is notnominal or a string, or the value couldn't be found for a nominalattribute



setDataset
final public void setDataset(Instances instances)(Code)
Sets the reference to the dataset. Does not check if the instance is compatible with the dataset. Note: the dataset does not know about this instance. If the structure of the dataset's header gets changed, this instance will not be adjusted automatically.
Parameters:
  instances - the reference to the dataset



setMissing
final public void setMissing(int attIndex)(Code)
Sets a specific value to be "missing". Performs a deep copy of the vector of attribute values before the value is set to be missing.
Parameters:
  attIndex - the attribute's index



setMissing
final public void setMissing(Attribute att)(Code)
Sets a specific value to be "missing". Performs a deep copy of the vector of attribute values before the value is set to be missing. The given attribute has to belong to a dataset.
Parameters:
  att - the attribute



setValue
public void setValue(int attIndex, double value)(Code)
Sets a specific value in the instance to the given value (internal floating-point format). Performs a deep copy of the vector of attribute values before the value is set.
Parameters:
  attIndex - the attribute's index
Parameters:
  value - the new attribute value (If the correspondingattribute is nominal (or a string) then this is the new value'sindex as a double).



setValue
final public void setValue(int attIndex, String value)(Code)
Sets a value of a nominal or string attribute to the given value. Performs a deep copy of the vector of attribute values before the value is set.
Parameters:
  attIndex - the attribute's index
Parameters:
  value - the new attribute value (If the attributeis a string attribute and the value can't be found,the value is added to the attribute).
throws:
  UnassignedDatasetException - if the dataset is not set
throws:
  IllegalArgumentException - if the selectedattribute is not nominal or a string, or the supplied value couldn't be found for a nominal attribute



setValue
final public void setValue(Attribute att, double value)(Code)
Sets a specific value in the instance to the given value (internal floating-point format). Performs a deep copy of the vector of attribute values before the value is set, so if you are planning on calling setValue many times it may be faster to create a new instance using toDoubleArray. The given attribute has to belong to a dataset.
Parameters:
  att - the attribute
Parameters:
  value - the new attribute value (If the correspondingattribute is nominal (or a string) then this is the new value'sindex as a double).



setValue
final public void setValue(Attribute att, String value)(Code)
Sets a value of an nominal or string attribute to the given value. Performs a deep copy of the vector of attribute values before the value is set, so if you are planning on calling setValue many times it may be faster to create a new instance using toDoubleArray. The given attribute has to belong to a dataset.
Parameters:
  att - the attribute
Parameters:
  value - the new attribute value (If the attributeis a string attribute and the value can't be found,the value is added to the attribute).
throws:
  IllegalArgumentException - if the the attribute is notnominal or a string, or the value couldn't be found for a nominalattribute



setValueSparse
public void setValueSparse(int indexOfIndex, double value)(Code)
Sets a specific value in the instance to the given value (internal floating-point format). Performs a deep copy of the vector of attribute values before the value is set. Does exactly the same thing as setValue().
Parameters:
  indexOfIndex - the index of the attribute's index
Parameters:
  value - the new attribute value (If the correspondingattribute is nominal (or a string) then this is the new value'sindex as a double).



setWeight
final public void setWeight(double weight)(Code)
Sets the weight of an instance.
Parameters:
  weight - the weight



stringValue
final public String stringValue(int attIndex)(Code)
Returns the value of a nominal, string, date, or relational attribute for the instance as a string.
Parameters:
  attIndex - the attribute's index the value as a string
throws:
  IllegalArgumentException - if the attribute is not a nominal,string, date, or relation-valued attribute.
throws:
  UnassignedDatasetException - if the instance doesn't belongto a dataset.



stringValue
final public String stringValue(Attribute att)(Code)
Returns the value of a nominal, string, date, or relational attribute for the instance as a string.
Parameters:
  att - the attribute the value as a string
throws:
  IllegalArgumentException - if the attribute is not a nominal,string, date, or relation-valued attribute.
throws:
  UnassignedDatasetException - if the instance doesn't belongto a dataset.



toDoubleArray
public double[] toDoubleArray()(Code)
Returns the values of each attribute as an array of doubles. an array containing all the instance attribute values



toString
public String toString()(Code)
Returns the description of one instance. If the instance doesn't have access to a dataset, it returns the internal floating-point values. Quotes string values that contain whitespace characters. the instance's description as a string



toString
final public String toString(int attIndex)(Code)
Returns the description of one value of the instance as a string. If the instance doesn't have access to a dataset, it returns the internal floating-point value. Quotes string values that contain whitespace characters, or if they are a question mark.
Parameters:
  attIndex - the attribute's index the value's description as a string



toString
final public String toString(Attribute att)(Code)
Returns the description of one value of the instance as a string. If the instance doesn't have access to a dataset it returns the internal floating-point value. Quotes string values that contain whitespace characters, or if they are a question mark. The given attribute has to belong to a dataset.
Parameters:
  att - the attribute the value's description as a string



value
public double value(int attIndex)(Code)
Returns an instance's attribute value in internal format.
Parameters:
  attIndex - the attribute's index the specified value as a double (If the correspondingattribute is nominal (or a string) then it returns the value's index as a double).



value
public double value(Attribute att)(Code)
Returns an instance's attribute value in internal format. The given attribute has to belong to a dataset.
Parameters:
  att - the attribute the specified value as a double (If the correspondingattribute is nominal (or a string) then it returns the value's index as adouble).



valueSparse
public double valueSparse(int indexOfIndex)(Code)
Returns an instance's attribute value in internal format. Does exactly the same thing as value() if applied to an Instance.
Parameters:
  indexOfIndex - the index of the attribute's index the specified value as a double (If the correspondingattribute is nominal (or a string) then it returns the value's index as a double).



weight
final public double weight()(Code)
Returns the instance's weight. the instance's weight as a double



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.