|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectweka.core.AbstractInstance
weka.core.SparseInstance
public class SparseInstance
Class for storing an instance as a sparse vector. A sparse instance only requires storage for those attribute values that are non-zero. Since the objective is to reduce storage requirements for datasets with large numbers of default values, this also includes nominal attributes -- the first nominal value (i.e. that which has index 0) will not require explicit storage, so rearrange your nominal attribute value orderings if necessary. Missing values will be stored explicitly.
| Constructor Summary | |
|---|---|
SparseInstance(double weight,
double[] attValues)
Constructor that generates a sparse instance from the given parameters. |
|
SparseInstance(double weight,
double[] attValues,
int[] indices,
int maxNumValues)
Constructor that inititalizes instance variable with given values. |
|
SparseInstance(Instance instance)
Constructor that generates a sparse instance from the given instance. |
|
SparseInstance(int numAttributes)
Constructor of an instance that sets weight to one, all values to be missing, and the reference to the dataset to null. |
|
SparseInstance(SparseInstance instance)
Constructor that copies the info from the given instance. |
|
| 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. |
int |
locateIndex(int index)
Locates the greatest index that is not greater than the given index. |
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 in the sparse vector. |
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 in sparse format. |
double |
value(int attIndex)
Returns an instance's attribute value in internal format. |
| Methods inherited from class weka.core.AbstractInstance |
|---|
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, value, valueSparse, weight |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SparseInstance(Instance instance)
instance - the instance from which the attribute values
and the weight are to be copiedpublic SparseInstance(SparseInstance instance)
instance - the instance from which the attribute
info is to be copied
public SparseInstance(double weight,
double[] attValues)
weight - the instance's weightattValues - a vector of attribute values
public SparseInstance(double weight,
double[] attValues,
int[] indices,
int maxNumValues)
weight - the instance's weightattValues - a vector of attribute values (just the ones to be stored)indices - the indices of the given values in the full vector (need to
be sorted in ascending order)maxNumValues - the maximium number of values that can be storedpublic SparseInstance(int numAttributes)
numAttributes - the size of the instance| Method Detail |
|---|
public Object copy()
new SparseInstance(instance)
public int index(int position)
position - the position
public int locateIndex(int index)
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 unequal
public 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 double value(int attIndex)
attIndex - the attribute's index
public static void main(String[] options)
public String getRevision()
getRevision in interface RevisionHandlergetRevision in class AbstractInstance
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||