BinarySparseInstance (original) (raw)
java.lang.Object
- weka.core.Instance
- weka.core.SparseInstance
- weka.core.BinarySparseInstance
- weka.core.SparseInstance
All Implemented Interfaces:
java.io.Serializable, Copyable, RevisionHandler
public class BinarySparseInstance
extends SparseInstance
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:1.13Revision: 1.13 Revision:1.13
See Also:
Serialized Form
Constructor Summary
Constructors
Constructor and Description BinarySparseInstance(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(Instance instance) Constructor that generates a sparse instance from the given instance. 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(SparseInstance instance) Constructor that copies the info from the given instance. Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type Method and Description java.lang.Object copy() Produces a shallow copy of this instance. java.lang.String getRevision() Returns the revision string. 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. 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[] toDoubleArray() Returns the values of each attribute as an array of doubles. java.lang.String toString() Returns the description of one instance in sparse format. double value(int attIndex) Returns an instance's attribute value in internal format. double valueSparse(int indexOfIndex) Returns an instance's attribute value in internal format. * ### Methods inherited from class weka.core.[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core") `[attributeSparse](../../weka/core/SparseInstance.html#attributeSparse-int-), [index](../../weka/core/SparseInstance.html#index-int-), [isMissing](../../weka/core/SparseInstance.html#isMissing-int-), [locateIndex](../../weka/core/SparseInstance.html#locateIndex-int-), [numAttributes](../../weka/core/SparseInstance.html#numAttributes--), [numValues](../../weka/core/SparseInstance.html#numValues--)` * ### Methods inherited from class weka.core.[Instance](../../weka/core/Instance.html "class in weka.core") `[attribute](../../weka/core/Instance.html#attribute-int-), [classAttribute](../../weka/core/Instance.html#classAttribute--), [classIndex](../../weka/core/Instance.html#classIndex--), [classIsMissing](../../weka/core/Instance.html#classIsMissing--), [classValue](../../weka/core/Instance.html#classValue--), [dataset](../../weka/core/Instance.html#dataset--), [deleteAttributeAt](../../weka/core/Instance.html#deleteAttributeAt-int-), [enumerateAttributes](../../weka/core/Instance.html#enumerateAttributes--), [equalHeaders](../../weka/core/Instance.html#equalHeaders-weka.core.Instance-), [hasMissingValue](../../weka/core/Instance.html#hasMissingValue--), [insertAttributeAt](../../weka/core/Instance.html#insertAttributeAt-int-), [isMissing](../../weka/core/Instance.html#isMissing-weka.core.Attribute-), [isMissingSparse](../../weka/core/Instance.html#isMissingSparse-int-), [isMissingValue](../../weka/core/Instance.html#isMissingValue-double-), [missingValue](../../weka/core/Instance.html#missingValue--), [numClasses](../../weka/core/Instance.html#numClasses--), [relationalValue](../../weka/core/Instance.html#relationalValue-weka.core.Attribute-), [relationalValue](../../weka/core/Instance.html#relationalValue-int-), [setClassMissing](../../weka/core/Instance.html#setClassMissing--), [setClassValue](../../weka/core/Instance.html#setClassValue-double-), [setClassValue](../../weka/core/Instance.html#setClassValue-java.lang.String-), [setDataset](../../weka/core/Instance.html#setDataset-weka.core.Instances-), [setMissing](../../weka/core/Instance.html#setMissing-weka.core.Attribute-), [setMissing](../../weka/core/Instance.html#setMissing-int-), [setValue](../../weka/core/Instance.html#setValue-weka.core.Attribute-double-), [setValue](../../weka/core/Instance.html#setValue-weka.core.Attribute-java.lang.String-), [setValue](../../weka/core/Instance.html#setValue-int-java.lang.String-), [setWeight](../../weka/core/Instance.html#setWeight-double-), [stringValue](../../weka/core/Instance.html#stringValue-weka.core.Attribute-), [stringValue](../../weka/core/Instance.html#stringValue-int-), [toString](../../weka/core/Instance.html#toString-weka.core.Attribute-), [toString](../../weka/core/Instance.html#toString-int-), [value](../../weka/core/Instance.html#value-weka.core.Attribute-), [weight](../../weka/core/Instance.html#weight--)` * ### Methods inherited from class java.lang.Object `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`
Constructor Detail
* #### BinarySparseInstance public BinarySparseInstance([Instance](../../weka/core/Instance.html "class in weka.core") instance) 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 public BinarySparseInstance([SparseInstance](../../weka/core/SparseInstance.html "class in weka.core") instance) 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 weight `attValues` \- 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 weight `indices` \- the indices of the given values in the full vector `maxNumValues` \- 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 Detail
* #### copy public java.lang.Object copy() Produces a shallow copy of this instance. The copy doesn't have access to a dataset. Specified by: `[copy](../../weka/core/Copyable.html#copy--)` in interface `[Copyable](../../weka/core/Copyable.html "interface in weka.core")` Overrides: `[copy](../../weka/core/SparseInstance.html#copy--)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` Returns: the shallow copy * #### mergeInstance public [Instance](../../weka/core/Instance.html "class in weka.core") mergeInstance([Instance](../../weka/core/Instance.html "class in weka.core") inst) Merges this instance with the given instance and returns the result. Dataset is set to null. Overrides: `[mergeInstance](../../weka/core/SparseInstance.html#mergeInstance-weka.core.Instance-)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` 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. Overrides: `[replaceMissingValues](../../weka/core/SparseInstance.html#replaceMissingValues-double:A-)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` 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. Overrides: `[setValue](../../weka/core/SparseInstance.html#setValue-int-double-)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` Parameters: `attIndex` \- the attribute's index `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). * #### 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. Overrides: `[setValueSparse](../../weka/core/SparseInstance.html#setValueSparse-int-double-)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` Parameters: `indexOfIndex` \- the index of the attribute's index `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). * #### toDoubleArray public double[] toDoubleArray() Returns the values of each attribute as an array of doubles. Overrides: `[toDoubleArray](../../weka/core/SparseInstance.html#toDoubleArray--)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` Returns: an array containing all the instance attribute values * #### toString public java.lang.String 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](../../weka/core/SparseInstance.html#toString--)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` Returns: the instance's description as a string * #### value public double value(int attIndex) Returns an instance's attribute value in internal format. Overrides: `[value](../../weka/core/SparseInstance.html#value-int-)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` 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. Overrides: `[valueSparse](../../weka/core/Instance.html#valueSparse-int-)` in class `[Instance](../../weka/core/Instance.html "class in weka.core")` 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 public static void main(java.lang.String[] options) Main method for testing this class. Parameters: `options` \- the command line options - ignored * #### getRevision public java.lang.String getRevision() Returns the revision string. Specified by: `[getRevision](../../weka/core/RevisionHandler.html#getRevision--)` in interface `[RevisionHandler](../../weka/core/RevisionHandler.html "interface in weka.core")` Overrides: `[getRevision](../../weka/core/SparseInstance.html#getRevision--)` in class `[SparseInstance](../../weka/core/SparseInstance.html "class in weka.core")` Returns: the revision