Interface Vector
-
- All Superinterfaces:
AbelianGroup<Vector>,BanachSpace<Vector,Real>,DeepCopyable,HilbertSpace<Vector,Real>,VectorSpace<Vector,Real>
- All Known Implementing Classes:
Basis,CombinedVectorByRef,DenseVector,Gradient,ImmutableVector,SparseVector,SubVectorRef,SVEC
public interface Vector extends HilbertSpace<Vector,Real>, DeepCopyable
An Euclidean vector is a geometric object that has both a magnitude/length and a direction. The mathematical structure of a collection of vectors is a Hilbert space. This interface is made minimal to avoid listing all possible vector operations. Instead, vector operations are grouped into packages and classes by their properties. This is to avoid interface "pollution", lengthy and cumbersome design. The only way to change a vector is byset(int, double). Other operations that "change" the vector actually creates a new and independent copy.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Vectoradd(double c)Add a constant to all entries in this vector.Vectoradd(Vector that)\(this + that\)doubleangle(Vector that)Measure the angle, \(\theta\), betweenthisandthat.VectordeepCopy()The implementation returns an instance created fromthisby the copy constructor of the class, or justthisif the instance itself is immutable.Vectordivide(Vector that)Dividethisbythat, entry-by-entry.doubleget(int i)Get the value at position i.doubleinnerProduct(Vector that)Inner product in the Euclidean space is the dot product.Vectorminus(double c)Subtract a constant from all entries in this vector.Vectorminus(Vector that)\(this - that\)Vectormultiply(Vector that)Multiplythisbythat, entry-by-entry.doublenorm()Compute the length or magnitude or Euclidean norm of a vector, namely, \(\|v\|\).doublenorm(double p)Gets the \(L^p\)-norm \(\|v\|_p\) of this vector.Vectoropposite()Get the opposite of this vector.Vectorpow(double c)Take the exponentiation of all entries in this vector, entry-by-entry.Vectorscaled(double c)Scale this vector by a constant, entry-by-entry.Vectorscaled(Real c)Scale this vector by a constant, entry-by-entry.voidset(int i, double value)Change the value of an entry in this vector.intsize()Get the length of this vector.double[]toArray()Cast this vector into a 1Ddouble[].VectorZERO()Get a 0-vector that has the same length as this vector.
-
-
-
Method Detail
-
size
int size()
Get the length of this vector.- Returns:
- the vector length
-
get
double get(int i)
Get the value at position i.- Parameters:
i- the position of a vector entry- Returns:
- v[i]
-
set
void set(int i, double value)Change the value of an entry in this vector. This is the only method that may change the entries of a vector.- Parameters:
i- the index of the entry to change. The indices are counting from 1, NOT 0.value- the value to change to
-
add
Vector add(Vector that)
\(this + that\)- Specified by:
addin interfaceAbelianGroup<Vector>- Parameters:
that- a vector- Returns:
- \(this + that\)
-
minus
Vector minus(Vector that)
\(this - that\)- Specified by:
minusin interfaceAbelianGroup<Vector>- Parameters:
that- a vector- Returns:
- \(this - that\)
-
multiply
Vector multiply(Vector that)
Multiplythisbythat, entry-by-entry.- Parameters:
that- a vector- Returns:
- \(this \cdot that\)
-
divide
Vector divide(Vector that)
Dividethisbythat, entry-by-entry.- Parameters:
that- a vector- Returns:
- \(this / that\)
-
add
Vector add(double c)
Add a constant to all entries in this vector.- Parameters:
c- a constant- Returns:
- \(v + c\)
-
minus
Vector minus(double c)
Subtract a constant from all entries in this vector.- Parameters:
c- a constant- Returns:
- \(v - c\)
-
innerProduct
double innerProduct(Vector that)
Inner product in the Euclidean space is the dot product.- Specified by:
innerProductin interfaceHilbertSpace<Vector,Real>- Parameters:
that- a vector- Returns:
- \(this \cdot that\)
- See Also:
- Wikipedia: Dot product
-
pow
Vector pow(double c)
Take the exponentiation of all entries in this vector, entry-by-entry.- Parameters:
c- a constant- Returns:
- \(v ^ c\)
-
scaled
Vector scaled(double c)
Scale this vector by a constant, entry-by-entry. Here is a way to get a unit version of the vector:vector.scaled(1. / vector.norm())- Parameters:
c- a constant- Returns:
- \(c \times this\)
-
scaled
Vector scaled(Real c)
Scale this vector by a constant, entry-by-entry. Here is a way to get a unit version of the vector:vector.scaled(1. / vector.norm())- Specified by:
scaledin interfaceVectorSpace<Vector,Real>- Parameters:
c- a constant- Returns:
- \(c \times this\)
- See Also:
- Wikipedia: Scalar multiplication
-
norm
double norm()
Compute the length or magnitude or Euclidean norm of a vector, namely, \(\|v\|\).- Specified by:
normin interfaceBanachSpace<Vector,Real>- Returns:
- the Euclidean norm
- See Also:
- Wikipedia: Norm (mathematics)
-
norm
double norm(double p)
Gets the \(L^p\)-norm \(\|v\|_p\) of this vector.- When p is finite, \(\|v\|_p = \sum_{i}|v_i^p|^\frac{1}{p}\).
- When p is \(+\infty\) (
Double.POSITIVE_INFINITY), \(\|v\|_p = \max|v_i|\). - When p is \(-\infty\) (
Double.NEGATIVE_INFINITY), \(\|v\|_p = \min|v_i|\).
- Parameters:
p- p ≥ 1, orDouble.POSITIVE_INFINITYorDouble.NEGATIVE_INFINITY- Returns:
- \(\|v\|_p\)
- See Also:
- Wikipedia: Norm (mathematics)
-
angle
double angle(Vector that)
Measure the angle, \(\theta\), betweenthisandthat. That is, \[ this \cdot that = \|this\| \times \|that\| \times \cos \theta \]- Specified by:
anglein interfaceHilbertSpace<Vector,Real>- Parameters:
that- a vector- Returns:
- the angle, \(\theta\), between
thisandthat
-
opposite
Vector opposite()
Get the opposite of this vector.- Specified by:
oppositein interfaceAbelianGroup<Vector>- Returns:
- -v
- See Also:
- Wikipedia: Additive inverse
-
ZERO
Vector ZERO()
Get a 0-vector that has the same length as this vector.- Specified by:
ZEROin interfaceAbelianGroup<Vector>- Returns:
- the 0-vector
-
toArray
double[] toArray()
Cast this vector into a 1Ddouble[].- Returns:
- a copy of all vector entries as a
double[]
-
deepCopy
Vector deepCopy()
Description copied from interface:DeepCopyableThe implementation returns an instance created fromthisby the copy constructor of the class, or justthisif the instance itself is immutable.- Specified by:
deepCopyin interfaceDeepCopyable- Returns:
- an independent (deep) copy of the instance
-
-