|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Instance
Interface representing an instance. All values (numeric, date, nominal, string or relational) are internally stored as floating-point numbers in the original concrete class implementations (now called DenseInstance.java and SparseInstance.java), and the methods in this interface reflect this. 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 DenseInstance(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's attribute values must be safe, ie. a change of an instance's attribute values must not affect any other instances.
| Method Summary | |
|---|---|
Attribute |
attribute(int index)
Returns the attribute with the given index. |
Attribute |
attributeSparse(int indexOfIndex)
Returns the attribute with the given index in the sparse representation. |
Attribute |
classAttribute()
Returns class attribute. |
int |
classIndex()
Returns the class attribute's index. |
boolean |
classIsMissing()
Tests if an instance's class is missing. |
double |
classValue()
Returns an instance's class value as a floating-point number. |
Instances |
dataset()
Returns the dataset this instance has access to. |
void |
deleteAttributeAt(int position)
Deletes an attribute at the given position (0 to numAttributes() - 1). |
Enumeration |
enumerateAttributes()
Returns an enumeration of all the attributes. |
boolean |
equalHeaders(Instance inst)
Tests if the headers of two instances are equivalent. |
String |
equalHeadersMsg(Instance inst)
Checks if the headers of two instances are equivalent. |
boolean |
hasMissingValue()
Tests whether an instance has a missing value. |
int |
index(int position)
Returns the index of the attribute stored at the given position in the sparse representation. |
void |
insertAttributeAt(int position)
Inserts an attribute at the given position (0 to numAttributes()). |
boolean |
isMissing(Attribute att)
Tests if a specific value is "missing". |
boolean |
isMissing(int attIndex)
Tests if a specific value is "missing". |
boolean |
isMissingSparse(int indexOfIndex)
Tests if a specific value is "missing" in the sparse representation. |
Instance |
mergeInstance(Instance inst)
Merges this instance with the given instance and returns the result. |
int |
numAttributes()
Returns the number of attributes. |
int |
numClasses()
Returns the number of class labels. |
int |
numValues()
Returns the number of values present in a sparse representation. |
Instances |
relationalValue(Attribute att)
Returns the relational value of a relational attribute. |
Instances |
relationalValue(int attIndex)
Returns the relational value of a relational attribute. |
void |
replaceMissingValues(double[] array)
Replaces all missing values in the instance with the values contained in the given array. |
void |
setClassMissing()
Sets the class value of an instance to be "missing". |
void |
setClassValue(double value)
Sets the class value of an instance to the given value (internal floating-point format). |
void |
setClassValue(String value)
Sets the class value of an instance to the given value. |
void |
setDataset(Instances instances)
Sets the reference to the dataset. |
void |
setMissing(Attribute att)
Sets a specific value to be "missing". |
void |
setMissing(int attIndex)
Sets a specific value to be "missing". |
void |
setValue(Attribute att,
double value)
Sets a specific value in the instance to the given value (internal floating-point format). |
void |
setValue(Attribute att,
String value)
Sets a value of an nominal or string attribute to the given value. |
void |
setValue(int attIndex,
double value)
Sets a specific value in the instance to the given value (internal floating-point format). |
void |
setValue(int attIndex,
String value)
Sets a value of a nominal or string attribute to the given value. |
void |
setValueSparse(int indexOfIndex,
double value)
Sets a specific value in the instance to the given value (internal floating-point format), given an index into the sparse representation. |
void |
setWeight(double weight)
Sets the weight of an instance. |
String |
stringValue(Attribute att)
Returns the value of a nominal, string, date, or relational attribute for the instance as a string. |
String |
stringValue(int attIndex)
Returns the value of a nominal, string, date, or relational attribute for the instance as a string. |
double[] |
toDoubleArray()
Returns the values of each attribute as an array of doubles. |
String |
toString(Attribute att)
Returns the description of one value of the instance as a string. |
String |
toString(int attIndex)
Returns the description of one value of the instance as a string. |
String |
toStringNoWeight()
Returns the description of one instance (without weight appended). |
double |
value(Attribute att)
Returns an instance's attribute value in internal format. |
double |
value(int attIndex)
Returns an instance's attribute value in internal format. |
double |
valueSparse(int indexOfIndex)
Returns an instance's attribute value in internal format, given an index in the sparse representation. |
double |
weight()
Returns the instance's weight. |
| Methods inherited from interface weka.core.Copyable |
|---|
copy |
| Method Detail |
|---|
Attribute attribute(int index)
index - the attribute's index
UnassignedDatasetException - if instance doesn't have access to a
datasetAttribute attributeSparse(int indexOfIndex)
indexOfIndex - the index of the attribute's index
UnassignedDatasetException - if instance doesn't have access to a
datasetAttribute classAttribute()
UnassignedDatasetException - if the class is not set or the
instance doesn't have access to a datasetint classIndex()
UnassignedDatasetException - if instance doesn't have access to a datasetboolean classIsMissing()
UnassignedClassException - if the class is not set or the instance doesn't
have access to a datasetdouble classValue()
UnassignedClassException - if the class is not set or the instance doesn't
have access to a datasetInstances dataset()
void deleteAttributeAt(int position)
position - the attribute's position
RuntimeException - if the instance has access to a
datasetEnumeration enumerateAttributes()
UnassignedDatasetException - if the instance doesn't
have access to a datasetboolean equalHeaders(Instance inst)
inst - another instance
UnassignedDatasetException - if instance doesn't have access to any
datasetString equalHeadersMsg(Instance inst)
dataset - another instance
boolean hasMissingValue()
UnassignedDatasetException - if instance doesn't have access to any
datasetint index(int position)
position - the position
void insertAttributeAt(int position)
position - the attribute's position
RuntimeException - if the instance has accesss to a
dataset
IllegalArgumentException - if the position is out of rangeboolean isMissing(int attIndex)
attIndex - the attribute's index
boolean isMissingSparse(int indexOfIndex)
indexOfIndex - the index of the attribute's index
boolean isMissing(Attribute att)
att - the attribute
Instance mergeInstance(Instance inst)
inst - the instance to be merged with this one
int numAttributes()
int numClasses()
UnassignedDatasetException - if instance doesn't have access to any
datasetint numValues()
void replaceMissingValues(double[] array)
array - containing the means and modes
IllegalArgumentException - if numbers of attributes are unequalvoid setClassMissing()
UnassignedClassException - if the class is not set
UnassignedDatasetException - if the instance doesn't
have access to a datasetvoid setClassValue(double value)
value - the new attribute value (If the corresponding
attribute is nominal (or a string) then this is the new value's
index as a double).
UnassignedClassException - if the class is not set
UnaddignedDatasetException - if the instance doesn't
have access to a datasetvoid setClassValue(String value)
value - the new class value (If the class
is a string attribute and the value can't be found,
the value is added to the attribute).
UnassignedClassException - if the class is not set
UnassignedDatasetException - if the dataset is not set
IllegalArgumentException - if the attribute is not
nominal or a string, or the value couldn't be found for a nominal
attributevoid setDataset(Instances instances)
instances - the reference to the datasetvoid setMissing(int attIndex)
attIndex - the attribute's indexvoid setMissing(Attribute att)
att - the attribute
void setValue(int attIndex,
double value)
attIndex - the attribute's indexvalue - the new attribute value (If the corresponding
attribute is nominal (or a string) then this is the new value's
index as a double).
void setValueSparse(int indexOfIndex,
double value)
indexOfIndex - the index of the attribute's indexvalue - the new attribute value (If the corresponding
attribute is nominal (or a string) then this is the new value's
index as a double).
void setValue(int attIndex,
String value)
attIndex - the attribute's indexvalue - the new attribute value (If the attribute
is a string attribute and the value can't be found,
the value is added to the attribute).
UnassignedDatasetException - if the dataset is not set
IllegalArgumentException - if the selected
attribute is not nominal or a string, or the supplied value couldn't
be found for a nominal attribute
void setValue(Attribute att,
double value)
att - the attributevalue - the new attribute value (If the corresponding
attribute is nominal (or a string) then this is the new value's
index as a double).
void setValue(Attribute att,
String value)
att - the attributevalue - the new attribute value (If the attribute
is a string attribute and the value can't be found,
the value is added to the attribute).
IllegalArgumentException - if the the attribute is not
nominal or a string, or the value couldn't be found for a nominal
attributevoid setWeight(double weight)
weight - the weightInstances relationalValue(int attIndex)
attIndex - the attribute's index
IllegalArgumentException - if the attribute is not a
relation-valued attribute
UnassignedDatasetException - if the instance doesn't belong
to a dataset.Instances relationalValue(Attribute att)
att - the attribute
IllegalArgumentException - if the attribute is not a
relation-valued attribute
UnassignedDatasetException - if the instance doesn't belong
to a dataset.String stringValue(int attIndex)
attIndex - the attribute's index
IllegalArgumentException - if the attribute is not a nominal,
string, date, or relation-valued attribute.
UnassignedDatasetException - if the instance doesn't belong
to a dataset.String stringValue(Attribute att)
att - the attribute
IllegalArgumentException - if the attribute is not a nominal,
string, date, or relation-valued attribute.
UnassignedDatasetException - if the instance doesn't belong
to a dataset.double[] toDoubleArray()
String toStringNoWeight()
String toString(int attIndex)
attIndex - the attribute's index
String toString(Attribute att)
att - the attribute
double value(int attIndex)
attIndex - the attribute's index
double valueSparse(int indexOfIndex)
indexOfIndex - the index of the attribute's index
double value(Attribute att)
att - the attribute
double weight()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||