shared
Class Instance

java.lang.Object
  |
  +--shared.Instance

public class Instance
extends java.lang.Object

The class Instance provides instances with or without label and support for describing instances, iterating through values, and looking at the instance label. Most effort was directed at categorization of labelled instances for supervised learning. Has been extended to tree-structured attributes.


Field Summary
 AttrValue[] values
          The values for each Attribute stored in this Instance.
 
Constructor Summary
Instance(Instance source)
          Copy constructor for the Instance class.
Instance(Schema newSchema)
          Constructor for the Instance class.
 
Method Summary
 AttrInfo attr_info(int attrNum)
          Returns the information about the attribute specified.
 java.lang.String attr_name(int attrNum)
          Returns the attribute name.
 java.lang.Object clone()
          Cloning function for the Instance class.
 void copy(Instance other)
          Copies the supplied Instance object into this Instance object.
 java.lang.String display_unlabelled_out(boolean displayWeight, boolean normalizeReal)
          Returns a String representation of the Instance.
 void display_unlabelled(boolean displayWeight, boolean normalizeReal)
          Displays the Instance without labels.
 void display(boolean displayWeight, boolean normalizeReals)
          Displays the Instance with labels.
 boolean equals(Instance i_instance)
          Checks if this Instance is equal to the specified Instance.
 AttrValue get_label()
          Returns the label this Instance is categorized as.
 Schema get_schema()
          Returns the Schema of attributes for this Instance.
 AttrValue get_value(int index)
          Returns the attribute value at the specified attribute.
 double get_weight()
          Returns the weight for this Instance.
 AttrValue index(int index)
          Returns the AttrValue at the specified index number.
 boolean is_labelled()
          Checks if this Instance is labelled.
 boolean is_labelled(boolean fatalOnFalse)
          Checks if this Instance is labelled.
 AttrInfo label_info()
          Returns the information about the label this Instance is categorized as.
 NominalAttrInfo nominal_label_info()
          Returns the information on the label attribute.
 int num_attr_values(int attrNum)
          Returns the number of values for the specified attribute.
 int num_attr()
          Returns the number of attributes for data in this Instance.
 int num_label_values()
          Returns the number of possible label values in the Schema of this Instance.
 java.lang.String out(boolean displayWeight, boolean normalizeReals)
          Returns a String representation of the Instance.
 Instance project(Schema shortSchema, boolean[] attrMask)
          Returns a copy with only the attributes included that are are indicated by the mask.
 Instance remove_attr(int attrNum)
          Remove an Attribute from an Instance.
 Instance remove_attr(int attrNum, Schema schemaWithDelAttr)
          Remove an Attribute from an Instance.
 void set_label(AttrValue lvalue)
          Sets the label for this Instance.
 void set_schema(Schema schemaRC)
          Sets the Schema for this Instance.
 void set_weight(double wt)
          Sets the weight for this Instance.
 java.lang.String toString()
          Transfers this Instance to a String value.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

values

public AttrValue[] values
The values for each Attribute stored in this Instance.
Constructor Detail

Instance

public Instance(Schema newSchema)
Constructor for the Instance class.
Parameters:
newSchema - The Schema for the data stored in this Instance.

Instance

public Instance(Instance source)
Copy constructor for the Instance class.
Parameters:
source - The original Instance to be copied.
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Cloning function for the Instance class. Provides a deep copy.
Overrides:
clone in class java.lang.Object
Returns:
A copy of the Object.
Throws:
java.lang.CloneNotSupportedException - if the cloning process for contained data members encounters a CloneNotSupportedException.

get_schema

public Schema get_schema()
Returns the Schema of attributes for this Instance.
Returns:
The Schema for this Instance.

num_attr

public int num_attr()
Returns the number of attributes for data in this Instance.
Returns:
The number of attributes in this Instance.

get_label

public AttrValue get_label()
Returns the label this Instance is categorized as.
Returns:
The labelValue for this Instance.

project

public Instance project(Schema shortSchema,
                        boolean[] attrMask)
Returns a copy with only the attributes included that are are indicated by the mask. Schema.project() should be called to create the new Schema for the Instance.
Parameters:
shortSchema - The Schema for the new Instance created.
attrMask - An array of boolean values equal in length to the original number of attributes. Each element relates to an attribute of the original instance. If the element is set TRUE, the corresponding attribute is included in the new Instance.
Returns:
The new Instance with the attributes specified.

get_value

public AttrValue get_value(int index)
Returns the attribute value at the specified attribute.
Parameters:
index - The index number for the specified attribute.
Returns:
The attribute value stored for the attribute at that index.

set_schema

public void set_schema(Schema schemaRC)
Sets the Schema for this Instance.
Parameters:
schemaRC - The new Schema for this Instance.

set_weight

public void set_weight(double wt)
Sets the weight for this Instance.
Parameters:
wt - The new weight for this Instance.

set_label

public void set_label(AttrValue lvalue)
Sets the label for this Instance.
Parameters:
lvalue - The new label value for this Instance.

get_weight

public double get_weight()
Returns the weight for this Instance.
Returns:
The weight for this Instance.

display

public void display(boolean displayWeight,
                    boolean normalizeReals)
Displays the Instance with labels.
Parameters:
displayWeight - TRUE if the weight for this Instance should be shown, FALSE otherwise.
normalizeReals - TRUE if the attribute values should be normalized, FALSE otherwise.

display_unlabelled

public void display_unlabelled(boolean displayWeight,
                               boolean normalizeReal)
Displays the Instance without labels.
Parameters:
normalizeReal - TRUE if the attribute values should be normalized, FALSE otherwise.
displayWeight - TRUE if the weight for this Instance should be shown, FALSE otherwise.

is_labelled

public boolean is_labelled()
Checks if this Instance is labelled.
Returns:
TRUE if the Instance contains a label value, FALSE otherwise.

is_labelled

public boolean is_labelled(boolean fatalOnFalse)
Checks if this Instance is labelled.
Parameters:
fatalOnFalse - TRUE if an Error message should be displayed if there is no label for this Instance, FALSE otherwise.
Returns:
TRUE if the Instance is labelled, FALSE otherwise.

label_info

public AttrInfo label_info()
Returns the information about the label this Instance is categorized as.
Returns:
The information about the label value.

toString

public java.lang.String toString()
Transfers this Instance to a String value.
Overrides:
toString in class java.lang.Object
Returns:
A String with representations of the data stored in this Instance.

attr_info

public AttrInfo attr_info(int attrNum)
Returns the information about the attribute specified.
Parameters:
attrNum - The index of the attribute specified.
Returns:
The information about the attribute.

equals

public boolean equals(Instance i_instance)
Checks if this Instance is equal to the specified Instance. Compares the attributes values, the weight, and the label of this Instance.
Parameters:
i_instance - The Instance to be compared to.
Returns:
TRUE if these Instances are equal, FALSE otherwise.

out

public java.lang.String out(boolean displayWeight,
                            boolean normalizeReals)
Returns a String representation of the Instance.
Parameters:
displayWeight - TRUE if the Instance weight is to be displayed, FALSE otherwise.
normalizeReals - TRUE if the real values in the Instance are to be normalized, FALSE otherwise.
Returns:
A String representation of the Instance.

display_unlabelled_out

public java.lang.String display_unlabelled_out(boolean displayWeight,
                                               boolean normalizeReal)
Returns a String representation of the Instance.
Parameters:
displayWeight - TRUE if the Instance weight is to be displayed, FALSE otherwise.
normalizeReal - TRUE if the real values in the Instance are to be normalized, FALSE otherwise.
Returns:
A String representation of the Instance.

index

public AttrValue index(int index)
Returns the AttrValue at the specified index number.
Parameters:
index - The index specified.
Returns:
The AttrValue at the specified index.

copy

public void copy(Instance other)
          throws java.lang.CloneNotSupportedException
Copies the supplied Instance object into this Instance object.
Parameters:
other - The Instance object to be copied.
Throws:
java.lang.CloneNotSupportedException - if the cloning process for contained data members encounters a CloneNotSupportedException.

remove_attr

public Instance remove_attr(int attrNum,
                            Schema schemaWithDelAttr)
Remove an Attribute from an Instance. When doing many projections, it is more efficient to supply a Schema with the deleted attribute.
Parameters:
attrNum - The number of the attribute to be removed from this InstanceObject.
schemaWithDelAttr - Schema with the attribute deleted.
Returns:
The modified Instance.

remove_attr

public Instance remove_attr(int attrNum)
Remove an Attribute from an Instance. When doing many projections, it is more efficient to supply a Schema with the deleted attribute.
Parameters:
attrNum - The number of the attribute to be removed from this InstanceObject.
Returns:
The modified Instance.

num_attr_values

public int num_attr_values(int attrNum)
Returns the number of values for the specified attribute.
Parameters:
attrNum - The number of the attribute for which the number of values is requested.
Returns:
The number of attribute values.

num_label_values

public int num_label_values()
Returns the number of possible label values in the Schema of this Instance.
Returns:
The number of possible label values.

nominal_label_info

public NominalAttrInfo nominal_label_info()
Returns the information on the label attribute.
Returns:
Information on the label attribute.

attr_name

public java.lang.String attr_name(int attrNum)
Returns the attribute name.
Parameters:
attrNum - The number of the attribute.
Returns:
The name of the attribute.