SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.vector.doubles
Interface Vector

All Superinterfaces:
AbelianGroup<Vector>, BanachSpace<Vector,Real>, DeepCopyable, HilbertSpace<Vector,Real>, VectorSpace<Vector,Real>
All Known Implementing Classes:
Basis, DenseVector, ImmutableVector, SparseVector

public interface Vector
extends HilbertSpace<Vector,Real>, DeepCopyable

A Euclidean vector is a geometric object that has both a magnitude/length and direction. The mathematical structure of a collection of vectors is a Hilbert space, c.f., HilbertSpace.

We do not dictate how a vector should be implemented. Different implementations of the mathematical concept 'vector' implements this interface.

This interface is made minimal so that we do not list 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 by set(int, double). Other operations that "change" the vector actually creates a new and independent copy.

See Also:

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.
 Vector 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.
 double get(int index)
          Get the value at position index.
 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)
          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.
 Vector ZERO()
          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 length of this vector

get

double get(int index)
Get the value at position index.

Parameters:
index - position of a vector entry
Returns:
v[index]

set

void set(int index,
         double value)
Change the value of an entry in this vector.

The 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.

Parameters:
index - the entry to change
value - the value to change to

add

Vector add(Vector that)
this + that

Specified by:
add in interface AbelianGroup<Vector>
Parameters:
that - a vector
Returns:
a vector which is the sum of this and that

minus

Vector minus(Vector that)
this - that

Specified by:
minus in interface AbelianGroup<Vector>
Parameters:
that - a vector
Returns:
a vector which is the difference between this and that

multiply

Vector multiply(Vector that)
this * that

Multiply this by that, entry-by-entry.

Parameters:
that - a vector
Returns:
this * that, entry-by-entry

divide

Vector divide(Vector that)
this / that

Divide this by that, entry-by-entry.

Parameters:
that - a vector
Returns:
this / that, entry-by-entry

add

Vector add(double scalar)
v + s

Add a scalar to all entries in the vector v.

Parameters:
scalar - s
Returns:
v + s

minus

Vector minus(double scalar)
v - s

Subtract a scalar from all entries in the vector v.

Parameters:
scalar - s
Returns:
v - s

innerProduct

double innerProduct(Vector that)
Inner product in the Euclidean space is the dot product.

Dot product is an operation which takes two vectors over the real numbers R and returns a real-valued scalar quantity.

Specified by:
innerProduct in interface HilbertSpace<Vector,Real>
Parameters:
that - a vector
Returns:
dot product of two vectors, this and that, i.e.,
this ∙ that
See Also:
Wikipedia: Dot product

pow

Vector pow(double scalar)
v ^ s

Take the exponentiation of all entries in the vector v by a scalar.

Parameters:
scalar - s
Returns:
v ^ s

scaled

Vector scaled(double scalar)
scalar * this

Here is a way to get a unit version of the vector:

vector.scaled(1. / vector.norm())

Parameters:
scalar - a double scalar
Returns:
a vector which is scaled by scalar

scaled

Vector scaled(Real scalar)
scalar * 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())

Specified by:
scaled in interface VectorSpace<Vector,Real>
Parameters:
scalar - a Real number scalar
Returns:
a vector which is scaled by scalar
See Also:
Wikipedia: Scalar multiplication

norm

double norm()
Compute the length or magnitude or Euclidean norm of a vector, namely, ||v||.

Specified by:
norm in interface BanachSpace<Vector,Real>
Returns:
the Euclidean norm
See Also:
Wikipedia: Norm (mathematics)

norm

double norm(int p)
Compute the norm of a vector. When p 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))
 

Parameters:
p - an integer, Integer.MAX_VALUE, or Integer.MIN_VALUE
Returns:
|v|p

angle

double angle(Vector that)
Measure the angle between this and that.

That is,

this ∙ that = ||this|| * ||that|| cos(angle)

Specified by:
angle in interface HilbertSpace<Vector,Real>
Parameters:
that - a vector
Returns:
the angle between this and that

opposite

Vector opposite()
Get the opposite of this vector.

Specified by:
opposite in interface AbelianGroup<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:
ZERO in interface AbelianGroup<Vector>
Returns:
a 0-vector, which has the same length as this vector

toArray

double[] toArray()
Get a copy of all vector entries in the form of a 1D double[] array.

Returns:
a copy of all vector entries as a double[]

deepCopy

Vector deepCopy()
Description copied from interface: DeepCopyable
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.

Specified by:
deepCopy in interface DeepCopyable
Returns:
an independent (deep) copy of the instance

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.