Package org.biojava.stats.svm
Class SparseVector
- java.lang.Object
-
- org.biojava.stats.svm.SparseVector
-
- All Implemented Interfaces:
Serializable
public class SparseVector extends Object implements Serializable
An implementation of a sparse vector.Memory is only allocated for dimensions that have non-zero values.
- Author:
- Thomas Down, Matthew Pocock
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSparseVector.NormalizingKernelA version of the standard dot-product kernel that scales each column independently.
-
Constructor Summary
Constructors Constructor Description SparseVector()SparseVector(int capacity)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleget(int dim)Retrieve the value at dimension dim.intgetDimAtIndex(int indx)Retrieve the dimension at a specific index.doublegetValueAtIndex(int indx)Retrieve the value at a specific index.intmaxIndex()static SparseVectornormalLengthVector(SparseVector v, double length)voidput(int dim, double value)Set the value at a particular dimension.intsize()The number of used dimensions.
-
-
-
Constructor Detail
-
SparseVector
public SparseVector()
-
SparseVector
public SparseVector(int capacity)
-
-
Method Detail
-
size
public int size()
The number of used dimensions.This is the total number of non-zero dimensions. It is not equal to the number of the highest indexed dimension.
- Returns:
- the number of non-zero dimensions
-
put
public void put(int dim, double value)
Set the value at a particular dimension.This silently handles the case when previously there was no value at dim. It does not contract the sparse array if you set a value to zero.
- Parameters:
dim- the dimension to altervalue- the new value
-
get
public double get(int dim)
Retrieve the value at dimension dim.- Parameters:
dim- the dimension to retrieve a value for- Returns:
- the value at that dimension
-
getDimAtIndex
public int getDimAtIndex(int indx)
Retrieve the dimension at a specific index.E.g., if the sparse vector had dimensions 5, 11, 12, 155 set to non-zero values then
sv.getDimAtIndex(2)would return 12.- Parameters:
indx- the index- Returns:
- the dimension stoored at that index
- Throws:
ArrayIndexOutOfBoundsException- if index >= size.
-
getValueAtIndex
public double getValueAtIndex(int indx)
Retrieve the value at a specific index.E.g., if the sparse vector contained the data 5->0.1, 11->100, 12->8.5, 155->-10 then
sv.geValueAtIndex(2)would return 8.5.- Parameters:
indx- the index- Returns:
- the value stoored at that index
- Throws:
ArrayIndexOutOfBoundsException- if index >= size.
-
maxIndex
public int maxIndex()
-
normalLengthVector
public static SparseVector normalLengthVector(SparseVector v, double length)
-
-