public class DenseInstance extends AbstractInstance
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 are safe, ie. a change of an instance's attribute values 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.
s_numericAfterDecimalPoint
Constructor and Description |
---|
DenseInstance(double weight,
double[] attValues)
Constructor that inititalizes instance variable with given values.
|
DenseInstance(Instance instance)
Constructor that copies the attribute values and the weight from the given
instance.
|
DenseInstance(int numAttributes)
Constructor of an instance that sets weight to one, all values to be
missing, and the reference to the dataset to null.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
copy()
Produces a shallow copy of this instance.
|
Instance |
copy(double[] values)
Copies the instance but fills up its values based on the given array
of doubles.
|
java.lang.String |
getRevision()
Returns the revision string.
|
int |
index(int position)
Returns the index of the attribute stored at the given position.
|
static void |
main(java.lang.String[] options)
Main method for testing this class.
|
Instance |
mergeInstance(Instance inst)
Merges this instance with the given instance and returns the result.
|
int |
numAttributes()
Returns the number of attributes.
|
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 |
setValue(int attIndex,
double value)
Sets a specific value in the instance to the given value (internal
floating-point format).
|
void |
setValueSparse(int indexOfIndex,
double value)
Sets a specific value in the instance to the given value (internal
floating-point format).
|
double[] |
toDoubleArray()
Returns the values of each attribute as an array of doubles.
|
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(int attIndex)
Returns an instance's attribute value in internal format.
|
attribute, attributeSparse, classAttribute, classIndex, classIsMissing, classValue, dataset, deleteAttributeAt, enumerateAttributes, equalHeaders, equalHeadersMsg, hasMissingValue, insertAttributeAt, isMissing, isMissing, isMissingSparse, numClasses, relationalValue, relationalValue, setClassMissing, setClassValue, setClassValue, setDataset, setMissing, setMissing, setValue, setValue, setValue, setWeight, stringValue, stringValue, toString, toString, toString, toString, toString, toStringMaxDecimalDigits, value, valueSparse, weight
public DenseInstance(Instance instance)
instance
- the instance from which the attribute values and the weight
are to be copiedpublic DenseInstance(double weight, double[] attValues)
weight
- the instance's weightattValues
- a vector of attribute valuespublic DenseInstance(int numAttributes)
numAttributes
- the size of the instancepublic java.lang.Object copy()
new DenseInstance(instance)
public Instance copy(double[] values)
values
- the array with new valuespublic int index(int position)
position
- the positionpublic Instance mergeInstance(Instance inst)
inst
- the instance to be merged with this onepublic int numAttributes()
public int numValues()
public void replaceMissingValues(double[] array)
array
- containing the means and modesjava.lang.IllegalArgumentException
- if numbers of attributes are unequalpublic 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 double[] toDoubleArray()
public java.lang.String toStringNoWeight()
public java.lang.String toStringNoWeight(int afterDecimalPoint)
afterDecimalPoint
- maximum number of digits after the decimal point
for numeric valuespublic double value(int attIndex)
attIndex
- the attribute's indexpublic static void main(java.lang.String[] options)
options
- the commandline options - ignoredpublic java.lang.String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class AbstractInstance