public class M5Instance
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected double[] |
m_AttValues
The instance's attribute values.
|
protected M5Instances |
m_Dataset
The dataset the instance has access to.
|
protected double |
m_Weight
The instance's weight.
|
protected static double |
MISSING_VALUE
Constant representing a missing value.
|
Modifier | Constructor and Description |
---|---|
protected |
M5Instance()
Private constructor for subclasses.
|
|
M5Instance(double weight,
double[] attValues)
Constructor that inititalizes instance variable with given
values.
|
|
M5Instance(int numAttributes)
Constructor of an instance that sets weight to one, all values to
be missing, and the reference to the dataset to null.
|
|
M5Instance(M5Instance instance)
Constructor that copies the attribute values and the weight from
the given instance.
|
Modifier and Type | Method and Description |
---|---|
M5Attribute |
attribute(int index)
Returns the attribute with the given index.
|
M5Attribute |
attributeSparse(int indexOfIndex)
Returns the attribute with the given index.
|
M5Attribute |
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 in internal format.
|
java.lang.Object |
copy()
Produces a shallow copy of this instance.
|
M5Instances |
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 |
enumerateAttributes()
Returns an enumeration of all the attributes.
|
boolean |
equalHeaders(M5Instance inst)
Tests if the headers of two instances are equivalent.
|
int |
index(int position)
Returns the index of the attribute stored at the given position.
|
void |
insertAttributeAt(int position)
Inserts an attribute at the given position (0 to
numAttributes()).
|
boolean |
isMissing(int attIndex)
Tests if a specific value is "missing".
|
boolean |
isMissing(M5Attribute att)
Tests if a specific value is "missing".
|
boolean |
isMissingSparse(int indexOfIndex)
Tests if a specific value is "missing".
|
static boolean |
isMissingValue(double val)
Tests if the given value codes "missing".
|
M5Instance |
mergeInstance(M5Instance inst)
Merges this instance with the given instance and returns
the result.
|
static double |
missingValue()
Returns the double that codes "missing".
|
int |
numAttributes()
Returns the number of attributes.
|
int |
numClasses()
Returns the number of class labels.
|
int |
numValues()
Returns the number of values present.
|
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(M5Instances instances)
Sets the reference to the dataset.
|
void |
setMissing(int attIndex)
Sets a specific value to be "missing".
|
void |
setMissing(M5Attribute att)
Sets a specific value to be "missing".
|
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 |
setValue(M5Attribute att,
double value)
Sets a specific value in the instance to the given value
(internal floating-point format).
|
void |
setValue(M5Attribute att,
java.lang.String value)
Sets a value of an 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).
|
void |
setWeight(double weight)
Sets the weight of an instance.
|
java.lang.String |
stringValue(int attIndex)
Returns the value of a nominal (or string) attribute
for the instance.
|
java.lang.String |
stringValue(M5Attribute att)
Returns the value of a nominal (or string) attribute
for the instance.
|
double[] |
toDoubleArray()
Returns the values of each attribute as an array of doubles.
|
java.lang.String |
toString()
Returns the description of one instance.
|
java.lang.String |
toString(int attIndex)
Returns the description of one value of the instance as a
string.
|
java.lang.String |
toString(M5Attribute att)
Returns the description of one value of the instance as a
string.
|
double |
value(int attIndex)
Returns an instance's attribute value in internal format.
|
double |
value(M5Attribute att)
Returns an instance's attribute value in internal format.
|
double |
valueSparse(int indexOfIndex)
Returns an instance's attribute value in internal format.
|
double |
weight()
Returns the instance's weight.
|
protected static final double MISSING_VALUE
protected M5Instances m_Dataset
protected double[] m_AttValues
protected double m_Weight
public M5Instance(M5Instance instance)
instance
- the instance from which the attribute
values and the weight are to be copiedpublic M5Instance(double weight, double[] attValues)
weight
- the instance's weightattValues
- a vector of attribute valuespublic M5Instance(int numAttributes)
numAttributes
- the size of the instanceprotected M5Instance()
public M5Attribute attribute(int index) throws java.lang.Exception
index
- the attribute's indexjava.lang.Exception
- if instance doesn't have access to a
datasetpublic M5Attribute attributeSparse(int indexOfIndex) throws java.lang.Exception
indexOfIndex
- the index of the attribute's indexjava.lang.Exception
- if instance doesn't have access to a
datasetpublic M5Attribute classAttribute() throws java.lang.Exception
java.lang.Exception
- if the class is not set or the
instance doesn't have access to a datasetpublic int classIndex() throws java.lang.Exception
java.lang.Exception
- if instance doesn't have access to a datasetpublic boolean classIsMissing() throws java.lang.Exception
java.lang.Exception
- if the class is not set or the instance doesn't
have access to a datasetpublic double classValue() throws java.lang.Exception
java.lang.Exception
- if the class is not set or the instance doesn't
have access to a datasetpublic java.lang.Object copy()
new M5Instace(instance)
public M5Instances dataset()
public void deleteAttributeAt(int position)
position
- the attribute's positionjava.lang.RuntimeException
- if the instance has access to a
datasetpublic java.util.Enumeration enumerateAttributes() throws java.lang.Exception
java.lang.Exception
- if the instance doesn't
have access to a datasetpublic boolean equalHeaders(M5Instance inst) throws java.lang.Exception
inst
- another instancejava.lang.Exception
- if instance doesn't have access to any
datasetpublic int index(int position)
position
- the positionpublic void insertAttributeAt(int position)
position
- the attribute's positionpublic boolean isMissing(int attIndex)
attIndex
- the attribute's indexpublic boolean isMissingSparse(int indexOfIndex)
indexOfIndex
- the index of the attribute's indexpublic boolean isMissing(M5Attribute att)
att
- the attributepublic static boolean isMissingValue(double val)
val
- the value to be testedpublic M5Instance mergeInstance(M5Instance inst)
inst
- the instance to be merged with this onepublic static double missingValue()
public int numAttributes()
public int numClasses() throws java.lang.Exception
java.lang.Exception
- if instance doesn't have access to any
datasetpublic int numValues()
public void replaceMissingValues(double[] array)
array
- containing the means and modesjava.lang.IllegalArgumentException
- if numbers of attributes are unequalpublic void setClassMissing() throws java.lang.Exception
java.lang.Exception
- if the class is not set or if the instance doesn't
have access to a datasetpublic void setClassValue(double value) throws java.lang.Exception
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).java.lang.Exception
- if the class is not set or if the instance doesn't
have access to a datasetpublic final void setClassValue(java.lang.String value) throws java.lang.Exception
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).java.lang.Exception
- if the class is not set, if the dataset is not set or if the attribute is not
nominal or a string, or the value couldn't be found for a nominal
attributepublic final void setDataset(M5Instances instances)
instances
- the reference to the datasetpublic final void setMissing(int attIndex)
attIndex
- the attribute's indexpublic final void setMissing(M5Attribute att)
att
- the attributepublic 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).public 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).public final void setValue(int attIndex, java.lang.String value) throws java.lang.Exception
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).java.lang.Exception
- if the dataset is not set or if the selected
attribute is not nominal or a string, or the supplied value couldn't
be found for a nominal attributepublic final void setValue(M5Attribute 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).public final void setValue(M5Attribute 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
attributepublic final void setWeight(double weight)
weight
- the weightpublic final java.lang.String stringValue(int attIndex) throws java.lang.Exception
attIndex
- the attribute's indexjava.lang.Exception
- if the attribute is not a nominal
(or string) attribute or if the instance doesn't belong
to a dataset.public final java.lang.String stringValue(M5Attribute att) throws java.lang.Exception
att
- the attributejava.lang.Exception
- if the attribute is not a nominal
(or string) attribute or if the instance doesn't belong
to a dataset.public double[] toDoubleArray()
public java.lang.String toString()
toString
in class java.lang.Object
public final java.lang.String toString(int attIndex) throws java.lang.Exception
attIndex
- the attribute's indexjava.lang.Exception
public final java.lang.String toString(M5Attribute att) throws java.lang.Exception
att
- the attributejava.lang.Exception
public double value(int attIndex)
attIndex
- the attribute's indexpublic double valueSparse(int indexOfIndex)
indexOfIndex
- the index of the attribute's indexpublic double value(M5Attribute att)
att
- the attributepublic final double weight()