|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.matrix.doubles.matrixtype.sparse.SparseVector
public class SparseVector
A sparse vector stores only non-zero values.
| Nested Class Summary | |
|---|---|
static class |
SparseVector.Entry
This is an entry in a SparseVector. |
static class |
SparseVector.Iterator
This wrapper class overrides the Iterator.remove()
method to throw an exception when called. |
| Constructor Summary | |
|---|---|
SparseVector(int size)
Construct a sparse vector. |
|
SparseVector(int size,
int[] indices,
double[] values)
Construct a sparse vector. |
|
SparseVector(SparseVector that)
Copy constructor. |
|
| Method Summary | |
|---|---|
Vector |
add(double c)
Add a constant to all entries in this vector. |
SparseVector |
add(SparseVector that)
|
Vector |
add(Vector that)
\(this + that\) |
double |
angle(Vector that)
Measure the angle, \(\theta\), between this and that. |
SparseVector |
deepCopy()
The implementation returns an instance created from this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
Vector |
divide(Vector that)
Divide this by that, entry-by-entry. |
double |
get(int index)
Get the value at position i. |
double |
innerProduct(SparseVector that)
|
double |
innerProduct(Vector that)
Inner product in the Euclidean space is the dot product. |
java.util.Iterator<SparseVector.Entry> |
iterator()
|
Vector |
minus(double c)
Subtract a constant from all entries in this vector. |
SparseVector |
minus(SparseVector that)
|
Vector |
minus(Vector that)
\(this - that\) |
SparseVector |
multiply(SparseVector that)
|
SparseVector |
multiply(Vector that)
Multiply this by that, entry-by-entry. |
int |
nNonZeros()
Get the number of non-zero entries in the structure. |
double |
norm()
Compute the length or magnitude or Euclidean norm of a vector, namely, \(\|v\|\). |
double |
norm(int p)
Get the norm of a vector. |
SparseVector |
opposite()
Get the opposite of this vector. |
Vector |
pow(double c)
Take the exponentiation of all entries in this vector, entry-by-entry. |
SparseVector |
scaled(double c)
Scale this vector by a constant, entry-by-entry. |
SparseVector |
scaled(Real c)
Scale this vector by a constant, entry-by-entry. |
void |
set(int index,
double value)
Change the value of an entry in this vector. |
int |
size()
Get the length of this vector. |
double[] |
toArray()
Cast this vector into a 1D double[]. |
java.lang.String |
toString()
|
SparseVector |
ZERO()
Get a 0-vector that has the same length as this vector. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SparseVector(int size)
size - the size of the vector
public SparseVector(int size,
int[] indices,
double[] values)
size - the size of the vectorindices - the indices of the non-zero valuesvalues - the non-zero valuespublic SparseVector(SparseVector that)
that - the vector to be copied| Method Detail |
|---|
public int size()
Vector
size in interface Vectorpublic double get(int index)
Vector
get in interface Vectorindex - the position of a vector entry
public void set(int index,
double value)
Vector
set in interface Vectorindex - the index of the entry to change. The indices are counting from 1, NOT 0.value - the value to change topublic java.util.Iterator<SparseVector.Entry> iterator()
iterator in interface java.lang.Iterable<SparseVector.Entry>public Vector add(Vector that)
Vector
add in interface AbelianGroup<Vector>add in interface Vectorthat - a vector
public SparseVector add(SparseVector that)
public Vector minus(Vector that)
Vector
minus in interface AbelianGroup<Vector>minus in interface Vectorthat - a vector
public SparseVector minus(SparseVector that)
public SparseVector multiply(Vector that)
Vectorthis by that, entry-by-entry.
multiply in interface Vectorthat - a vector
public SparseVector multiply(SparseVector that)
public Vector divide(Vector that)
Vectorthis by that, entry-by-entry.
divide in interface Vectorthat - a vector
public Vector add(double c)
Vector
add in interface Vectorc - a constant
public Vector minus(double c)
Vector
minus in interface Vectorc - a constant
public double innerProduct(Vector that)
Vector
innerProduct in interface HilbertSpace<Vector,Real>innerProduct in interface Vectorthat - a vector
public double innerProduct(SparseVector that)
public Vector pow(double c)
Vector
pow in interface Vectorc - a constant
public SparseVector scaled(double c)
Vector
vector.scaled(1. / vector.norm())
scaled in interface Vectorc - a constant
public SparseVector scaled(Real c)
Vector
vector.scaled(1. / vector.norm())
scaled in interface VectorSpace<Vector,Real>scaled in interface Vectorc - a constant
public SparseVector opposite()
Vector
opposite in interface AbelianGroup<Vector>opposite in interface Vectorpublic double norm()
Vector
norm in interface BanachSpace<Vector,Real>norm in interface Vectorpublic double norm(int p)
Vector
norm in interface Vectorp - an integer, Integer.MAX_VALUE, or Integer.MIN_VALUE
public double angle(Vector that)
Vectorthis and that.
That is,
\[
this \cdot that = \|this\| \times \|that\| \times \cos \theta
\]
angle in interface HilbertSpace<Vector,Real>angle in interface Vectorthat - a vector
this and thatpublic SparseVector ZERO()
Vector
ZERO in interface AbelianGroup<Vector>ZERO in interface Vectorpublic double[] toArray()
Vectordouble[].
toArray in interface Vectordouble[]public SparseVector deepCopy()
DeepCopyablethis by the copy
constructor of the class, or just this if the instance itself is
immutable.
deepCopy in interface DeepCopyabledeepCopy in interface Vectorpublic int nNonZeros()
SparseStructure
nNonZeros in interface SparseStructurepublic java.lang.String toString()
toString in class java.lang.Object
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||