|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.core.AbstractInstance
weka.core.DenseInstance
public class DenseInstance
Class for handling an instance. All values (numeric, date, nominal, string or relational) are internally stored as floating-point numbers. 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 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.
Field Summary |
---|
Fields inherited from class weka.core.AbstractInstance |
---|
s_numericAfterDecimalPoint |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
Object |
copy()
Produces a shallow copy of this instance. |
String |
getRevision()
Returns the revision string. |
int |
index(int position)
Returns the index of the attribute stored at the given position. |
static void |
main(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. |
String |
toStringNoWeight()
Returns the description of one instance (without weight appended). |
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. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
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 instanceMethod Detail |
---|
public Object copy()
new DenseInstance(instance)
public int index(int position)
position
- the position
public Instance mergeInstance(Instance inst)
inst
- the instance to be merged with this one
public int numAttributes()
public int numValues()
public void replaceMissingValues(double[] array)
array
- containing the means and modes
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 String toStringNoWeight()
public String toStringNoWeight(int afterDecimalPoint)
afterDecimalPoint
- maximum number of digits after the decimal point
for numeric values
public double value(int attIndex)
attIndex
- the attribute's index
public static void main(String[] options)
options
- the commandline options - ignoredpublic String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class AbstractInstance
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |