|
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.ImmutableVector
public class ImmutableVector
A read-only view of a Vector instance. The only constructor of this
class takes a Vector instance. This class keeps the reference to the
instance, delegates all operations to the instance except for
set(int, double) which will always result in an
IsVector.VectorAccessException.
That means, a user can still modify the vector via the reference of the
original Vector. If an independent copy is required, a copy of the
instance can be passed into the constructor of this class, e.g.,
ImmutableVector immutable = new ImmutableVector(v.deepCopy());
Note that the returned values of all operations (e.g., add()) remain
the same types as the original ones.
The usage of this class could be, e.g., the final member of a class, the return value of a method.
| Constructor Summary | |
|---|---|
ImmutableVector(Vector vector)
Construct a read-only version of vector. |
|
| 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. |
ImmutableVector |
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. |
boolean |
equals(java.lang.Object obj)
|
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. |
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 that)
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 index,
double value)
This method is overridden to always throw UnsupportedOperationException. |
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, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ImmutableVector(Vector vector)
vector.
Note that changing the original vector changes the "immutable" version as well.
vector - a vector| Method Detail |
|---|
public final void set(int index,
double value)
UnsupportedOperationException.
set in interface Vectorindex - the entry to changevalue - the value to change to
IsVector.VectorAccessException - alwayspublic int size()
Vector
size in interface Vectorpublic double get(int index)
Vectorindex.
get in interface Vectorindex - 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 Vector minus(Vector that)
Vectorthis - that
minus in interface AbelianGroup<Vector>minus in interface Vectorthat - a vector
this and thatpublic Vector multiply(Vector that)
Vectorthis * that
Multiply this by that, entry-by-entry.
multiply in interface Vectorthat - 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 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 opposite()
Vector
opposite in interface AbelianGroup<Vector>opposite in interface Vector-vpublic Vector ZERO()
Vector
ZERO in interface AbelianGroup<Vector>ZERO in interface Vectorpublic double[] toArray()
Vectordouble[] array.
toArray in interface Vectordouble[]public ImmutableVector 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 java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode 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 | |||||||