Package weka.core
Class BinarySparseInstance
java.lang.Object
weka.core.AbstractInstance
weka.core.SparseInstance
weka.core.BinarySparseInstance
- All Implemented Interfaces:
Serializable
,Copyable
,Instance
,RevisionHandler
Class for storing a binary-data-only 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 are not supported, and will be treated as 1 (true).
- Version:
- $Revision: 12472 $
- See Also:
-
Field Summary
Fields inherited from class weka.core.AbstractInstance
s_numericAfterDecimalPoint
-
Constructor Summary
ConstructorDescriptionBinarySparseInstance
(double weight, double[] attValues) Constructor that generates a sparse instance from the given parameters.BinarySparseInstance
(double weight, int[] indices, int maxNumValues) Constructor that inititalizes instance variable with given values.BinarySparseInstance
(int numAttributes) Constructor of an instance that sets weight to one, all values to 1, and the reference to the dataset to null.BinarySparseInstance
(Instance instance) Constructor that generates a sparse instance from the given instance.BinarySparseInstance
(SparseInstance instance) Constructor that copies the info from the given instance. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Produces a shallow copy of this instance.copy
(double[] values) Copies the instance but fills up its values based on the given array of doubles.Returns the revision string.static void
Main method for testing this class.mergeInstance
(Instance inst) Merges this instance with the given instance and returns the result.void
replaceMissingValues
(double[] array) Does nothing, since we don't support missing values.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[]
Returns the values of each attribute as an array of doubles.toString()
Returns the description of one instance in sparse format.double
value
(int attIndex) Returns an instance's attribute value in internal format.final double
valueSparse
(int indexOfIndex) Returns an instance's attribute value in internal format.Methods inherited from class weka.core.SparseInstance
index, locateIndex, numAttributes, numValues, toStringNoWeight, toStringNoWeight
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, toString, toStringMaxDecimalDigits, value, weight
-
Constructor Details
-
BinarySparseInstance
Constructor that generates a sparse instance from the given instance. Reference to the dataset is set to null. (ie. the instance doesn't have access to information about the attribute types)- Parameters:
instance
- the instance from which the attribute values and the weight are to be copied
-
BinarySparseInstance
Constructor that copies the info from the given instance. Reference to the dataset is set to null. (ie. the instance doesn't have access to information about the attribute types)- Parameters:
instance
- the instance from which the attribute info is to be copied
-
BinarySparseInstance
public BinarySparseInstance(double weight, double[] attValues) Constructor that generates a sparse instance from the given parameters. Reference to the dataset is set to null. (ie. the instance doesn't have access to information about the attribute types)- Parameters:
weight
- the instance's weightattValues
- a vector of attribute values
-
BinarySparseInstance
public BinarySparseInstance(double weight, int[] indices, int maxNumValues) Constructor that inititalizes instance variable with given values. Reference to the dataset is set to null. (ie. the instance doesn't have access to information about the attribute types)- Parameters:
weight
- the instance's weightindices
- the indices of the given values in the full vectormaxNumValues
- the maximium number of values that can be stored
-
BinarySparseInstance
public BinarySparseInstance(int numAttributes) Constructor of an instance that sets weight to one, all values to 1, and the reference to the dataset to null. (ie. the instance doesn't have access to information about the attribute types)- Parameters:
numAttributes
- the size of the instance
-
-
Method Details
-
copy
Produces a shallow copy of this instance. The copy has access to the same dataset. (if you want to make a copy that doesn't have access to the dataset, usenew BinarySparseInstance(instance)
- Specified by:
copy
in interfaceCopyable
- Overrides:
copy
in classSparseInstance
- Returns:
- the shallow copy
-
copy
Copies the instance but fills up its values based on the given array of doubles. The copy has access to the same dataset.- Specified by:
copy
in interfaceInstance
- Overrides:
copy
in classSparseInstance
- Parameters:
values
- the array with new values- Returns:
- the new instance
-
mergeInstance
Merges this instance with the given instance and returns the result. Dataset is set to null.- Specified by:
mergeInstance
in interfaceInstance
- Overrides:
mergeInstance
in classSparseInstance
- Parameters:
inst
- the instance to be merged with this one- Returns:
- the merged instances
-
replaceMissingValues
public void replaceMissingValues(double[] array) Does nothing, since we don't support missing values.- Specified by:
replaceMissingValues
in interfaceInstance
- Overrides:
replaceMissingValues
in classSparseInstance
- Parameters:
array
- containing the means and modes
-
setValue
public void setValue(int attIndex, double value) Sets a specific value in the instance to the given value (internal floating-point format). Performs a deep copy of the vector of attribute values before the value is set.- Specified by:
setValue
in interfaceInstance
- Overrides:
setValue
in classSparseInstance
- Parameters:
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).
-
setValueSparse
public void setValueSparse(int indexOfIndex, double value) Sets a specific value in the instance to the given value (internal floating-point format). Performs a deep copy of the vector of attribute values before the value is set.- Specified by:
setValueSparse
in interfaceInstance
- Overrides:
setValueSparse
in classSparseInstance
- Parameters:
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).
-
toDoubleArray
public double[] toDoubleArray()Returns the values of each attribute as an array of doubles.- Specified by:
toDoubleArray
in interfaceInstance
- Overrides:
toDoubleArray
in classSparseInstance
- Returns:
- an array containing all the instance attribute values
-
toString
Returns the description of one instance in sparse format. If the instance doesn't have access to a dataset, it returns the internal floating-point values. Quotes string values that contain whitespace characters.- Overrides:
toString
in classAbstractInstance
- Returns:
- the instance's description as a string
-
value
public double value(int attIndex) Returns an instance's attribute value in internal format.- Specified by:
value
in interfaceInstance
- Overrides:
value
in classSparseInstance
- Parameters:
attIndex
- the attribute's index- Returns:
- the specified value as a double (If the corresponding attribute is nominal (or a string) then it returns the value's index as a double).
-
valueSparse
public final double valueSparse(int indexOfIndex) Returns an instance's attribute value in internal format. Does exactly the same thing as value() if applied to an Instance.- Specified by:
valueSparse
in interfaceInstance
- Overrides:
valueSparse
in classAbstractInstance
- Parameters:
indexOfIndex
- the index of the attribute's index- Returns:
- the specified value as a double (If the corresponding attribute is nominal (or a string) then it returns the value's index as a double).
-
main
Main method for testing this class.- Parameters:
options
- the command line options - ignored
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classSparseInstance
- Returns:
- the revision
-