|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractMap<K,V> java.util.HashMap<java.lang.Integer,java.lang.Double> org.knowceans.mcl.SparseVector
public class SparseVector
SparseVector represents a sparse vector.
Conventions: except for the inherited methods and normalise(double), operations leave this ummodified (immutable) if there is a return value. Within operations, no pruning of values close to zero is done. Pruning can be controlled via the prune() method.
Field Summary | |
---|---|
private int |
length
|
private static long |
serialVersionUID
|
Constructor Summary | |
---|---|
SparseVector()
create empty vector |
|
SparseVector(double[] x)
create vector from dense vector |
|
SparseVector(int i)
create empty vector with length |
|
SparseVector(SparseVector v)
copy constructor |
Method Summary | |
---|---|
void |
add(int i,
double a)
mutable add |
void |
add(SparseVector v)
mutable add |
SparseVector |
copy()
copy the contents of the sparse vector |
double |
expSum(int p)
exponential sum, i.e., sum (elements^p) |
void |
factor(double a)
mutable factorisation |
java.lang.Double |
get(java.lang.Object key)
get ensures it returns 0 for empty hash values or if index exceeds length. |
double[] |
getDense()
get dense represenation |
int |
getLength()
get the length of the vector |
void |
hadamardPower(double s)
mutable Hadamard power |
void |
hadamardProduct(SparseVector v)
mutable Hadamard product (elementwise multiplication) |
double |
max()
maximum element value |
void |
mult(int i,
double a)
mutable mult |
void |
normalise()
normalises the vector to 1. |
double |
normalise(double newsum)
normalises the vector to newsum |
void |
prune(double threshold)
remove all elements whose magnitude is < threshold |
java.lang.Double |
put(java.lang.Integer key,
java.lang.Double value)
put increases the matrix size if the index exceeds the current size. |
void |
setLength(int length)
set the new length of the vector (regardless of the maximum index). |
private double |
sum()
sum of the elements |
double |
sum(double s)
power sum of the elements |
double |
times(SparseVector v)
immutable scalar product |
java.lang.String |
toString()
|
java.lang.String |
toStringDense()
create string representation of dense equivalent. |
Methods inherited from class java.util.HashMap |
---|
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Field Detail |
---|
private static final long serialVersionUID
private int length
Constructor Detail |
---|
public SparseVector()
public SparseVector(int i)
public SparseVector(double[] x)
x
- public SparseVector(SparseVector v)
v
- Method Detail |
---|
public java.lang.Double get(java.lang.Object key)
get
in interface java.util.Map<java.lang.Integer,java.lang.Double>
get
in class java.util.HashMap<java.lang.Integer,java.lang.Double>
key
-
public java.lang.Double put(java.lang.Integer key, java.lang.Double value)
put
in interface java.util.Map<java.lang.Integer,java.lang.Double>
put
in class java.util.HashMap<java.lang.Integer,java.lang.Double>
key
- value
-
public void normalise()
public double normalise(double newsum)
the
- value to which the element sum
private double sum()
public double sum(double s)
public void add(SparseVector v)
v
- public void mult(int i, double a)
i
- indexa
- valuepublic void factor(double a)
a
- public double times(SparseVector v)
v
-
public void hadamardProduct(SparseVector v)
v
- public void hadamardPower(double s)
s
- public void add(int i, double a)
i
- a
- public final int getLength()
public final void setLength(int length)
length
- public SparseVector copy()
public java.lang.String toString()
toString
in class java.util.AbstractMap<java.lang.Integer,java.lang.Double>
public java.lang.String toStringDense()
public double[] getDense()
public double max()
public double expSum(int p)
p
-
public void prune(double threshold)
threshold
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |