org.jscience.mathematics.algebraic.matrices
Class AbstractDoubleVector

java.lang.Object
  extended by org.jscience.mathematics.algebraic.AbstractHypermatrix
      extended by org.jscience.mathematics.algebraic.AbstractMatrix
          extended by org.jscience.mathematics.algebraic.AbstractVector
              extended by org.jscience.mathematics.algebraic.matrices.AbstractDoubleVector
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, BanachSpace.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Vector, Member
Direct Known Subclasses:
Double2Vector, Double3Vector, DoubleSparseVector, DoubleVector

public abstract class AbstractDoubleVector
extends AbstractVector
implements BanachSpace.Member

The AbstractDoubleVector class encapsulates vectors containing doubles.

See Also:
Serialized Form

Constructor Summary
protected AbstractDoubleVector(int dim)
           
 
Method Summary
 AbstractDoubleVector abs()
          Applies the abs function on all the vector components.
 AbstractDoubleVector add(AbstractDoubleVector v)
          Returns the addition of this vector and another.
 boolean equals(java.lang.Object obj)
          Compares two double vectors for equality.
 boolean equals(java.lang.Object obj, double tol)
           
 AbstractDoubleVector getColumn(int j)
          Returns the ith column.
 Double getElement(int n)
          Returns an element of this vector.
abstract  double getPrimitiveElement(int n)
          Returns an element of this vector (this is the fastest way of getting an element for this kind of matrix).
 AbstractDoubleVector getRow(int i)
          Returns the ith row.
 AbstractDoubleVector getSubVector(int k1, int k2)
          Computes a sub vector from the parameters index.
 int hashCode()
          Returns a hashcode for this NON EMPTY vector.
 double infNorm()
          Returns the linfinity-norm.
 AbstractDoubleVector mapElements(PrimitiveMapping f)
          Applies a function on all the vector components.
 double mass()
          Returns the mass.
 double max()
          Gets the max of the vector components.
 double mean()
          Gets the mean of the vector components.
 double min()
          Gets the min of the vector components.
 Ring.Member multiply(Ring.Member r)
          The multiplication law.
 double norm()
          Returns the l2-norm (magnitude).
 double norm(int n)
          Returns the ln-norm.
 void normalize()
          Makes the norm of this vector equal to one.
static AbstractDoubleVector read(java.io.BufferedReader input)
          Read a vector from a stream.
 AbstractDoubleVector reverse()
          Invert vector elements order from the last to the first.
 AbstractDoubleVector scalarDivide(double x)
          Returns the division of this vector by a scalar.
 AbstractDoubleVector scalarMultiply(double x)
          Returns the multiplication of this vector by a scalar.
 double scalarProduct(AbstractDoubleVector v)
          Returns the scalar product of this vector and another.
 void setAllElements(double r)
          Sets the value of all elements of the vector.
 void setColumn(int j, AbstractDoubleVector v)
          Returns the ith column.
abstract  void setElement(int n, double x)
          Sets the value of an element of this vector.
 void setElement(int n, Double x)
          Sets the value of a component of this vector.
 void setRow(int i, AbstractDoubleVector v)
          Returns the ith row.
 AbstractDoubleVector setSubVector(int k, AbstractDoubleVector v)
          Set a sub vector.
 double standardDeviation()
          Computes the (bias-corrected sample) standard deviation .
 AbstractDoubleVector subtract(AbstractDoubleVector v)
          Returns the subtraction of this vector by another.
 double sumSquares()
          Returns the sum of the squares of the components.
 DoubleMatrix tensorProduct(AbstractDoubleVector v)
          Returns the tensor product of this vector and another.
 AbstractComplexVector toComplexVector()
          Converts this vector to a complex vector.
 AbstractIntegerVector toIntegerVector()
          Converts this vector to a integer vector.
 Matrix toMatrix()
          Projects the vector to the corresponding (n, 1) matrix class.
 double[] toPrimitiveArray()
          Projects the vector to an array.
 java.lang.String toString()
          Returns a comma delimited string representing the value of this vector.
 Matrix transpose()
          Returns the transpose of this matrix.
 double variance()
          Computes the (bias-corrected sample) variance.
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractVector
getDimension, getElement, getInvalidElementMsg, toArray, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractMatrix
getElement, getInvalidElementMsg, numColumns, numRows, print, print, print, print, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.modules.VectorSpace.Member
scalarDivide
 
Methods inherited from interface org.jscience.mathematics.algebraic.modules.Module.Member
scalarMultiply
 
Methods inherited from interface org.jscience.mathematics.algebraic.groups.AbelianGroup.Member
add, negate, subtract
 
Methods inherited from interface org.jscience.mathematics.algebraic.Matrix
numColumns, numRows, toArray
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, getElement, numDimensions, numElements, numElements, toArray
 

Constructor Detail

AbstractDoubleVector

protected AbstractDoubleVector(int dim)
Method Detail

toString

public java.lang.String toString()
Returns a comma delimited string representing the value of this vector.

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns a hashcode for this NON EMPTY vector.

Overrides:
hashCode in class java.lang.Object

toIntegerVector

public AbstractIntegerVector toIntegerVector()
Converts this vector to a integer vector.

Returns:
a integer vector

toComplexVector

public AbstractComplexVector toComplexVector()
Converts this vector to a complex vector.

Returns:
a complex vector

getPrimitiveElement

public abstract double getPrimitiveElement(int n)
Returns an element of this vector (this is the fastest way of getting an element for this kind of matrix).

Parameters:
n - index of the vector element.
Throws:
IllegalDimensionException - If attempting to access an invalid element.

getElement

public Double getElement(int n)
Returns an element of this vector.

Specified by:
getElement in interface Vector
Specified by:
getElement in class AbstractVector
Parameters:
n - index of the vector element.
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If attempting to access an invalid element.

getRow

public AbstractDoubleVector getRow(int i)
Returns the ith row.

Specified by:
getRow in interface Matrix
Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!

getColumn

public AbstractDoubleVector getColumn(int j)
Returns the ith column.

Specified by:
getColumn in interface Matrix
Parameters:
j - DOCUMENT ME!
Returns:
DOCUMENT ME!

setRow

public void setRow(int i,
                   AbstractDoubleVector v)
Returns the ith row.


setColumn

public void setColumn(int j,
                      AbstractDoubleVector v)
Returns the ith column.


setElement

public abstract void setElement(int n,
                                double x)
Sets the value of an element of this vector.

Parameters:
n - index of the vector element.
x - a number.
Throws:
IllegalDimensionException - If attempting to access an invalid element.

setElement

public void setElement(int n,
                       Double x)
Sets the value of a component of this vector.

Parameters:
n - index of the vector component
x - an double
Throws:
IllegalDimensionException - If attempting to access an invalid component.

setAllElements

public void setAllElements(double r)
Sets the value of all elements of the vector.

Parameters:
r - a ring element

equals

public boolean equals(java.lang.Object obj)
Compares two double vectors for equality. Two vectors are considered to be equal if the norm of their difference is within the tolerance.

Overrides:
equals in class java.lang.Object
Parameters:
obj - a double vector

equals

public boolean equals(java.lang.Object obj,
                      double tol)

sumSquares

public double sumSquares()
Returns the sum of the squares of the components.

Returns:
DOCUMENT ME!

mass

public double mass()
Returns the mass.

Returns:
DOCUMENT ME!

norm

public double norm(int n)
Returns the ln-norm.


norm

public double norm()
Returns the l2-norm (magnitude).

Specified by:
norm in interface BanachSpace.Member
Returns:
DOCUMENT ME!

normalize

public void normalize()
Makes the norm of this vector equal to one.


infNorm

public double infNorm()
Returns the linfinity-norm.


abs

public AbstractDoubleVector abs()
Applies the abs function on all the vector components.


min

public double min()
Gets the min of the vector components.

Returns:
the min.

max

public double max()
Gets the max of the vector components.

Returns:
the max.

mean

public double mean()
Gets the mean of the vector components.

Returns:
the mean.

variance

public double variance()
Computes the (bias-corrected sample) variance.

Returns:
the variance.

standardDeviation

public double standardDeviation()
Computes the (bias-corrected sample) standard deviation .

Returns:
the standard deviation.

transpose

public Matrix transpose()
Description copied from interface: Matrix
Returns the transpose of this matrix.

Specified by:
transpose in interface Matrix
Returns:
DOCUMENT ME!

multiply

public Ring.Member multiply(Ring.Member r)
Description copied from interface: Ring.Member
The multiplication law.

Specified by:
multiply in interface Ring.Member
Parameters:
r - a ring member
Returns:
DOCUMENT ME!

add

public AbstractDoubleVector add(AbstractDoubleVector v)
Returns the addition of this vector and another.

Parameters:
v - a double vector.
Throws:
IllegalDimensionException - If the vectors are different sizes.

subtract

public AbstractDoubleVector subtract(AbstractDoubleVector v)
Returns the subtraction of this vector by another.

Parameters:
v - a double vector.
Throws:
IllegalDimensionException - If the vectors are different sizes.

scalarMultiply

public AbstractDoubleVector scalarMultiply(double x)
Returns the multiplication of this vector by a scalar.

Parameters:
x - a double.

scalarDivide

public AbstractDoubleVector scalarDivide(double x)
Returns the division of this vector by a scalar.

Parameters:
x - a double.
Throws:
java.lang.ArithmeticException - If divide by zero.

scalarProduct

public double scalarProduct(AbstractDoubleVector v)
Returns the scalar product of this vector and another.

Parameters:
v - a double vector.
Throws:
IllegalDimensionException - If the vectors are different sizes.

tensorProduct

public DoubleMatrix tensorProduct(AbstractDoubleVector v)
Returns the tensor product of this vector and another.

Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!

reverse

public AbstractDoubleVector reverse()
Invert vector elements order from the last to the first.


getSubVector

public AbstractDoubleVector getSubVector(int k1,
                                         int k2)
Computes a sub vector from the parameters index. If k1<0 k1 elements are added at the beginning of the returned vector If k2>getDimension() k2-getDimension() elements are added at the end of the returned vector Finally, if k1>k2 the vector is returned inverted.

Parameters:
k1 - the beginning index
k2 - the finishing index
Returns:
the sub vector.

setSubVector

public AbstractDoubleVector setSubVector(int k,
                                         AbstractDoubleVector v)
Set a sub vector. If k<0 the elements are added at the beginning of the returned vector If k+v.getDimension()>getDimension() k+v.getDimension()-getDimension() elements are added at the end of the returned vector

Parameters:
k - Initial row index to offset the patching vector
v - the patching vector

mapElements

public AbstractDoubleVector mapElements(PrimitiveMapping f)
Applies a function on all the vector components.

Parameters:
f - a user-defined function.
Returns:
a double vector.

toPrimitiveArray

public double[] toPrimitiveArray()
Projects the vector to an array.

Returns:
an double array.

toMatrix

public Matrix toMatrix()
Projects the vector to the corresponding (n, 1) matrix class.

Returns:
an double matrix.

read

public static AbstractDoubleVector read(java.io.BufferedReader input)
                                 throws java.io.IOException
Read a vector from a stream. The format is DIFFERENT from the print method, so printed vector can be read back in (provided they were printed using US Locale). Elements are separated by whitespace, all the elements appear on a single line NOT a single column (use matrix.read() if you want this behavior).

Parameters:
input - the input stream.
Throws:
java.io.IOException