|
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.vector.doubles.dense.DenseVector
public class DenseVector
This class implements the standard double dense vector representation.
| Field Summary | |
|---|---|
int |
length
length of this vector |
| Constructor Summary | |
|---|---|
DenseVector(DenseVector vector)
Copy constructor performing a deep copy. |
|
DenseVector(double... data)
Construct a vector from a 1D double array. |
|
DenseVector(int length)
Construct a vector of length length. |
|
DenseVector(int length,
double value)
Construct a vector of length length initialized with value value. |
|
DenseVector(Matrix A)
Construct a vector from a column matrix. |
|
DenseVector(Vector v)
|
|
| Method Summary | |
|---|---|
DenseVector |
add(DenseVector that)
this + that |
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. |
static DenseVector |
as(Vector v)
Convert a vector to type DenseVector. |
DenseVector |
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. |
DenseVector |
divide(DenseVector v)
this / v
Divide this by v, entry-by-entry. |
Vector |
divide(Vector that)
this / that
Divide this by that, entry-by-entry. |
boolean |
equals(java.lang.Object obj)
IsVector the equality of two vectors, i.e., whether all entries are equal. |
double |
get(int index)
Get the value at position index. |
int |
hashCode()
|
double |
innerProduct(Vector that)
Inner product in the Euclidean space is the dot product. |
DenseVector |
minus(DenseVector that)
this - that |
Vector |
minus(double scalar)
v - s
Subtract a scalar from all entries in the vector v. |
Vector |
minus(Vector that)
this - that |
DenseVector |
multiply(DenseVector v)
this * v
Multiply this by v, entry-by-entry. |
Vector |
multiply(Vector v)
this * that
Multiply this by that, entry-by-entry. |
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 from,
DenseVector replacement)
Replace v[from : replacement.length] by a replacement starting at position from. |
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()
|
DenseVector |
ZERO()
Get a 0-vector that has the same length as this vector. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public final int length
| Constructor Detail |
|---|
public DenseVector(int length)
length.
length - length of this vector
public DenseVector(int length,
double value)
length initialized with value value.
length - length of this vectorvalue - initial valuespublic DenseVector(double... data)
data - the 1D array inputpublic DenseVector(Matrix A)
A - a n x 1 column matrixpublic DenseVector(Vector v)
public DenseVector(DenseVector vector)
vector - the vector to be copied| Method Detail |
|---|
public static DenseVector as(Vector v)
v - a vector
public int size()
Vector
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.
index - the entry to changevalue - the value to change to
public void set(int from,
DenseVector replacement)
v[from : replacement.length] by a replacement starting at position from.
from - starting position of the replacementreplacement - an vector to substitute part of this vector
java.lang.IllegalArgumentException - if the replacement length exceeds the end of this vectorpublic double get(int index)
Vectorindex.
index - position of a vector entry
v[index]public Vector add(Vector that)
Vectorthis + that
add in interface AbelianGroup<Vector>add in interface Vectorthat - a vector
this and thatpublic DenseVector add(DenseVector that)
this + that
that - 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 DenseVector minus(DenseVector that)
this - that
that - a vector
this and thatpublic 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 multiply(Vector v)
Vectorthis * that
Multiply this by that, entry-by-entry.
multiply in interface Vectorv - a vector
this * that, entry-by-entrypublic DenseVector multiply(DenseVector v)
this * v
Multiply this by v, entry-by-entry.
v - a vector
this * v, 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 DenseVector divide(DenseVector v)
this / v
Divide this by v, entry-by-entry.
v - a vector
this / v, entry-by-entrypublic Vector add(double scalar)
Vectorv + s
Add a scalar to all entries in the vector v.
scalar - s
v + spublic Vector minus(double scalar)
Vectorv - s
Subtract a scalar from all entries in the vector v.
scalar - s
v - spublic 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 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))
p - an integer, Integer.MAX_VALUE, or Integer.MIN_VALUE
public 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 DenseVector ZERO()
Vector
public double[] toArray()
Vectordouble[] array.
double[]public DenseVector deepCopy()
DeepCopyablethis by the copy
constructor of the class, or just this if the instance itself is
immutable.
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - an vector
true iff all this and obj are equal, entry-by-entrypublic int hashCode()
hashCode in class java.lang.Objectpublic 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 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 double norm()
Vector||v||.
norm in interface BanachSpace<Vector,Real>norm in interface Vector
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||