public interface Instance extends Copyable
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.
Modifier and Type | Method and Description |
---|---|
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.
|
Instance |
copy(double[] values)
Copies the instance but fills up its values based on the given array
of doubles.
|
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).
|
java.util.Enumeration<Attribute> |
enumerateAttributes()
Returns an enumeration of all the attributes.
|
boolean |
equalHeaders(Instance inst)
Tests if the headers of two instances are equivalent.
|
java.lang.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(java.lang.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,
java.lang.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,
java.lang.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.
|
java.lang.String |
stringValue(Attribute att)
Returns the value of a nominal, string, date, or relational attribute for
the instance as a string.
|
java.lang.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.
|
java.lang.String |
toString(Attribute att)
Returns the description of one value of the instance as a string.
|
java.lang.String |
toString(Attribute att,
int afterDecimalPoint)
Returns the description of one value of the instance as a string.
|
java.lang.String |
toString(int attIndex)
Returns the description of one value of the instance as a string.
|
java.lang.String |
toString(int attIndex,
int afterDecimalPoint)
Returns the description of one value of the instance as a string.
|
java.lang.String |
toStringMaxDecimalDigits(int afterDecimalPoint)
Returns the description of one instance with any numeric values printed at
the supplied maximum number of decimal places.
|
java.lang.String |
toStringNoWeight()
Returns the description of one instance (without weight appended).
|
java.lang.String |
toStringNoWeight(int afterDecimalPoint)
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.
|
Attribute attribute(int index)
index
- the attribute's indexUnassignedDatasetException
- if instance doesn't have access to a
datasetAttribute attributeSparse(int indexOfIndex)
indexOfIndex
- the index of the attribute's indexUnassignedDatasetException
- 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 datasetInstance copy(double[] values)
values
- the array with new valuesInstances dataset()
void deleteAttributeAt(int position)
position
- the attribute's positionjava.lang.RuntimeException
- if the instance has access to a datasetjava.util.Enumeration<Attribute> enumerateAttributes()
UnassignedDatasetException
- if the instance doesn't have access to a
datasetboolean equalHeaders(Instance inst)
inst
- another instanceUnassignedDatasetException
- if instance doesn't have access to any
datasetjava.lang.String equalHeadersMsg(Instance inst)
inst
- another instanceboolean hasMissingValue()
UnassignedDatasetException
- if instance doesn't have access to any
datasetint index(int position)
position
- the positionvoid insertAttributeAt(int position)
position
- the attribute's positionjava.lang.RuntimeException
- if the instance has accesss to a datasetjava.lang.IllegalArgumentException
- if the position is out of rangeboolean isMissing(int attIndex)
attIndex
- the attribute's indexboolean isMissingSparse(int indexOfIndex)
indexOfIndex
- the index of the attribute's indexboolean isMissing(Attribute att)
att
- the attributeInstance mergeInstance(Instance inst)
inst
- the instance to be merged with this oneint numAttributes()
int numClasses()
UnassignedDatasetException
- if instance doesn't have access to any
datasetint numValues()
void replaceMissingValues(double[] array)
array
- containing the means and modesjava.lang.IllegalArgumentException
- if numbers of attributes are unequalvoid setClassMissing()
UnassignedClassException
- if the class is not setUnassignedDatasetException
- 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 setUnassignedDatasetException
- if the instance doesn't have access to a
datasetvoid setClassValue(java.lang.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 setUnassignedDatasetException
- if the dataset is not setjava.lang.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 attributevoid 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, java.lang.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 setjava.lang.IllegalArgumentException
- if the selected attribute is not nominal
or a string, or the supplied value couldn't be found for a
nominal attributevoid 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, java.lang.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).java.lang.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 indexjava.lang.IllegalArgumentException
- if the attribute is not a relation-valued
attributeUnassignedDatasetException
- if the instance doesn't belong to a
dataset.Instances relationalValue(Attribute att)
att
- the attributejava.lang.IllegalArgumentException
- if the attribute is not a relation-valued
attributeUnassignedDatasetException
- if the instance doesn't belong to a
dataset.java.lang.String stringValue(int attIndex)
attIndex
- the attribute's indexjava.lang.IllegalArgumentException
- if the attribute is not a nominal, string,
date, or relation-valued attribute.UnassignedDatasetException
- if the instance doesn't belong to a
dataset.java.lang.String stringValue(Attribute att)
att
- the attributejava.lang.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()
java.lang.String toStringNoWeight(int afterDecimalPoint)
afterDecimalPoint
- maximum number of digits after the decimal point
for numeric valuesjava.lang.String toStringNoWeight()
java.lang.String toStringMaxDecimalDigits(int afterDecimalPoint)
afterDecimalPoint
- the maximum number of digits permitted after the
decimal point for a numeric valuejava.lang.String toString(int attIndex, int afterDecimalPoint)
attIndex
- the attribute's indexafterDecimalPoint
- the maximum number of digits permitted after the
decimal point for numeric valuesjava.lang.String toString(int attIndex)
attIndex
- the attribute's indexjava.lang.String toString(Attribute att, int afterDecimalPoint)
att
- the attributeafterDecimalPoint
- the maximum number of decimal places to printjava.lang.String toString(Attribute att)
att
- the attributedouble value(int attIndex)
attIndex
- the attribute's indexdouble valueSparse(int indexOfIndex)
indexOfIndex
- the index of the attribute's indexdouble value(Attribute att)
att
- the attributedouble weight()