|
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
This class represents sparse vector which stores the non-zero values only.
| Nested Class Summary | |
|---|---|
static class |
SparseVector.Entry
This class represents an entry in a SparseVector. |
static class |
SparseVector.Iterator
This wrapper class overrides the Iterator.remove()
method for throwing exception when it is called. |
| Constructor Summary | |
|---|---|
SparseVector(int size)
Create an instance of sparse vector of the specified size. |
|
SparseVector(int size,
int[] indices,
double[] values)
Create an instance of sparse vector with non-zero values. |
|
SparseVector(SparseVector that)
Copy constructor. |
|
| Method Summary | |
|---|---|
Vector |
add(double scalar)
v + s
Add a scalar to all entries in the vector v. |
Vector |
add(Vector that)
this + that |
double |
angle(Vector that)
Measure the angle between this and that. |
SparseVector |
deepCopy()
The implementation can return 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)
this / that
Divide this by that, entry-by-entry. |
int |
dropTolerance(double tolerance)
Remove non-zero entries x whose magnitude is less than or equal to the tolerance, i.e., ( |x| <= tolerance). |
double |
get(int index)
Get the value at position index. |
double |
innerProduct(Vector that)
Inner product in the Euclidean space is the dot product. |
java.util.Iterator<SparseVector.Entry> |
iterator()
|
Vector |
minus(double scalar)
v - s
Subtract a scalar from all entries in the vector v. |
Vector |
minus(Vector that)
this - that |
Vector |
multiply(Vector v)
this * that
Multiply this by that, entry-by-entry. |
int |
nnz()
Get the number of non-zero entries in the matrix. |
double |
norm()
Compute the length or magnitude or Euclidean norm of a vector, namely, ||v||. |
double |
norm(int p)
Compute the norm of a vector. |
Vector |
opposite()
Get the opposite of this vector. |
Vector |
pow(double scalar)
v ^ s
Take the exponentiation of all entries in the vector v by a scalar. |
Vector |
scaled(double scalar)
scalar * this
Here is a way to get a unit version of the vector:
vector.scaled(1. / vector.norm()) |
Vector |
scaled(Real scalar)
scalar * that
If scalar is 1, it simply returns itself. |
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()
Get a copy of all vector entries in the form of a 1D double[] array. |
java.lang.String |
toString()
|
Vector |
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.
size - the size of the vector
public SparseVector(int size,
int[] indices,
double[] values)
size - the size of the vectorindices - the indices of the input 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)
Vectorindex.
get in interface Vectorindex - position of a vector entry
v[index]
public void set(int index,
double value)
VectorThe indices are, for example,: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ......
Note that we count from 1, NOT 0.
This is the only method that may change the entries of a vector.
set in interface Vectorindex - the entry to changevalue - the value to change topublic java.util.Iterator<SparseVector.Entry> iterator()
iterator in interface java.lang.Iterable<SparseVector.Entry>public Vector add(Vector that)
Vectorthis + that
add in interface AbelianGroup<Vector>add in interface Vectorthat - a vector
this and thatpublic Vector minus(Vector that)
Vectorthis - that
minus in interface AbelianGroup<Vector>minus in interface Vectorthat - a vector
this and thatpublic Vector multiply(Vector v)
Vectorthis * that
Multiply this by that, entry-by-entry.
multiply in interface Vectorv - a vector
this * that, entry-by-entrypublic Vector divide(Vector that)
Vectorthis / that
Divide this by that, entry-by-entry.
divide in interface Vectorthat - a vector
this / that, entry-by-entrypublic Vector add(double scalar)
Vectorv + s
Add a scalar to all entries in the vector v.
add in interface Vectorscalar - s
v + spublic Vector minus(double scalar)
Vectorv - s
Subtract a scalar from all entries in the vector v.
minus in interface Vectorscalar - s
v - spublic double innerProduct(Vector that)
Vector
Dot product is an operation which takes two vectors over the real numbers R
and returns a real-valued scalar quantity.
innerProduct in interface HilbertSpace<Vector,Real>innerProduct in interface Vectorthat - a vector
this and that,
i.e., this ∙ thatpublic Vector pow(double scalar)
Vectorv ^ s
Take the exponentiation of all entries in the vector v by a scalar.
pow in interface Vectorscalar - s
v ^ spublic Vector scaled(double scalar)
Vectorscalar * this
Here is a way to get a unit version of the vector:
vector.scaled(1. / vector.norm())
scaled in interface Vectorscalar - a double scalar
scalarpublic Vector scaled(Real scalar)
Vectorscalar * that
If scalar is 1, it simply returns itself.
So, here is a way to get a unit version of the vector:
vector.scaled(1. / vector.norm())
scaled in interface VectorSpace<Vector,Real>scaled in interface Vectorscalar - a Real number scalar
scalarpublic Vector opposite()
Vector
opposite in interface AbelianGroup<Vector>opposite in interface Vector-vpublic double norm()
Vector||v||.
norm in interface BanachSpace<Vector,Real>norm in interface Vectorpublic double norm(int p)
Vectorp is finite,
|v|p = ∑ [(abs(vi)^p)]^(1/p)
When p is +∞ (Integer.MAX_VALUE),
|v|p = max(abs(vi))
When p is -∞ (Integer.MIN_VALUE),
|v|p = min(abs(vi))
norm in interface Vectorp - an integer, Integer.MAX_VALUE, or Integer.MIN_VALUE
public double angle(Vector that)
Vectorthis and that.
That is,
this ∙ that = ||this|| * ||that|| cos(angle)
angle in interface HilbertSpace<Vector,Real>angle in interface Vectorthat - a vector
this and thatpublic Vector ZERO()
Vector
ZERO in interface AbelianGroup<Vector>ZERO in interface Vectorpublic double[] toArray()
Vectordouble[] array.
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 nnz()
SparseStructure
nnz in interface SparseStructurepublic int dropTolerance(double tolerance)
SparseStructure|x| <= tolerance).
dropTolerance in interface SparseStructuretolerance - the tolerance for non-zeros
public 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 | |||||||