org.jscience.mathematics.algebraic.matrices
Class AbstractIntegerVector

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.AbstractIntegerVector
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Vector, Member
Direct Known Subclasses:
Integer2Vector, Integer3Vector, IntegerSparseVector, IntegerVector

public abstract class AbstractIntegerVector
extends AbstractVector

The AbstractIntegerVector class encapsulates vectors containing integers.

See Also:
Serialized Form

Constructor Summary
protected AbstractIntegerVector(int dim)
          Creates a new AbstractIntegerVector object.
 
Method Summary
 AbstractDoubleVector abs()
          Applies the abs function on all the vector components.
 AbstractIntegerVector add(AbstractIntegerVector v)
          Returns the addition of this vector and another.
 boolean equals(java.lang.Object obj)
          Compares two Integer vectors for equality.
 boolean equals(java.lang.Object obj, double tol)
           
 AbstractIntegerVector getColumn(int j)
          Returns the ith column.
 Integer getElement(int n)
          Returns an element of this vector.
abstract  int getPrimitiveElement(int n)
          Returns an element of this vector (this is the fastest way of getting an element for this kind of matrix).
 AbstractIntegerVector getRow(int i)
          Returns the ith row.
 AbstractIntegerVector getSubVector(int k1, int k2)
          Computes a sub vector from the parameters index.
 int hashCode()
          Returns a hashcode for this NON EMPTY vector.
 int infNorm()
          Returns the linfinity-norm.
 AbstractDoubleVector mapElements(PrimitiveMapping f)
          Applies a function on all the vector components.
 int 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.
static AbstractIntegerVector read(java.io.BufferedReader input)
          Read a vector from a stream.
 AbstractIntegerVector reverse()
          Invert vector elements order from the last to the first.
 VectorSpace.Member scalarDivide(Field.Member x)
          Returns the division of this vector by a scalar.
 AbstractIntegerVector scalarMultiply(int x)
          Returns the multiplication of this vector by a scalar.
 int scalarProduct(AbstractIntegerVector v)
          Returns the scalar product of this vector and another.
 void setAllElements(int r)
          Sets the value of all elements of the vector.
 void setColumn(int j, AbstractIntegerVector v)
          Returns the ith column.
abstract  void setElement(int n, int x)
          Sets the value of an element of this vector.
 void setElement(int n, Integer x)
          Sets the value of a component of this vector.
 void setRow(int i, AbstractIntegerVector v)
          Returns the ith row.
 AbstractIntegerVector setSubVector(int k, AbstractIntegerVector v)
          Set a sub vector.
 double standardDeviation()
          Computes the (bias-corrected sample) standard deviation .
 AbstractIntegerVector subtract(AbstractIntegerVector v)
          Returns the subtraction of this vector by another.
 int sumSquares()
          Returns the sum of the squares of the components.
 IntegerMatrix tensorProduct(AbstractIntegerVector v)
          Returns the tensor product of this vector and another.
 AbstractComplexVector toComplexVector()
          Converts this vector to a complex vector.
 AbstractDoubleVector toDoubleVector()
          Converts this vector to a double vector.
 Matrix toMatrix()
          Projects the vector to the corresponding (n, 1) matrix class.
 int[] toPrimitiveArray()
          Projects the vector to an array.
 java.lang.String toString()
          Returns a comma delimited string representing the value of this vector.
 Matrix transpose()
          DOCUMENT ME!
 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.Matrix
numColumns, numRows, toArray
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, getElement, numDimensions, numElements, numElements, toArray
 
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
 

Constructor Detail

AbstractIntegerVector

protected AbstractIntegerVector(int dim)
Creates a new AbstractIntegerVector object.

Parameters:
dim - DOCUMENT ME!
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
Returns:
DOCUMENT ME!

hashCode

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

Overrides:
hashCode in class java.lang.Object
Returns:
DOCUMENT ME!

toDoubleVector

public AbstractDoubleVector toDoubleVector()
Converts this vector to a double vector.

Returns:
a double vector

toComplexVector

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

Returns:
a complex vector

getPrimitiveElement

public abstract int 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.
Returns:
DOCUMENT ME!

getElement

public Integer 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!

getRow

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

Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

getColumn

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

Parameters:
j - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - DOCUMENT ME!

setRow

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


setColumn

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


setElement

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

Parameters:
n - index of the vector element
x - an integer

setElement

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

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

setAllElements

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

Parameters:
r - a int element

equals

public boolean equals(java.lang.Object obj)
Compares two Integer 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 Integer vector

equals

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

sumSquares

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

Returns:
DOCUMENT ME!

mass

public int mass()
Returns the mass.

Returns:
DOCUMENT ME!

norm

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

Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!

norm

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

Returns:
DOCUMENT ME!

infNorm

public int infNorm()
Returns the linfinity-norm.

Returns:
DOCUMENT ME!

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()
DOCUMENT ME!

Returns:
DOCUMENT ME!

multiply

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

Parameters:
r - a ring member
Returns:
DOCUMENT ME!

scalarDivide

public VectorSpace.Member scalarDivide(Field.Member x)
Returns the division of this vector by a scalar.

Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

add

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

Parameters:
v - an integer vector
Returns:
DOCUMENT ME!

subtract

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

Parameters:
v - an integer vector
Returns:
DOCUMENT ME!

scalarMultiply

public AbstractIntegerVector scalarMultiply(int x)
Returns the multiplication of this vector by a scalar.

Parameters:
x - an integer
Returns:
DOCUMENT ME!

scalarProduct

public int scalarProduct(AbstractIntegerVector v)
Returns the scalar product of this vector and another.

Parameters:
v - an integer vector
Returns:
DOCUMENT ME!

tensorProduct

public IntegerMatrix tensorProduct(AbstractIntegerVector v)
Returns the tensor product of this vector and another.

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

reverse

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


getSubVector

public AbstractIntegerVector 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 AbstractIntegerVector setSubVector(int k,
                                          AbstractIntegerVector 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. We assume that the mapping is from int to int.

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

toPrimitiveArray

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

Returns:
an integer array.

toMatrix

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

Returns:
an int matrix.

read

public static AbstractIntegerVector 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