org.jscience.mathematics.algebraic.matrices
Class DoubleSparseVector

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
                  extended by org.jscience.mathematics.algebraic.matrices.DoubleSparseVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Algebra.Member, BanachSpace.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Vector, Member

public class DoubleSparseVector
extends AbstractDoubleVector
implements java.lang.Cloneable, java.io.Serializable

The DoubleSparseVector class encapsulates sparse vectors. Uses Morse-coding.

See Also:
Serialized Form

Constructor Summary
DoubleSparseVector(AbstractDoubleVector vec)
          Constructs a vector by copying a vector.
DoubleSparseVector(double[] array)
          Constructs a vector from an array.
DoubleSparseVector(int dim)
          Constructs an empty vector.
 
Method Summary
 AbelianGroup.Member add(AbelianGroup.Member v)
          Returns the addition of this vector and another.
 AbstractDoubleVector add(AbstractDoubleVector v)
          Returns the addition of this vector and another.
 DoubleSparseVector add(DoubleSparseVector v)
          Returns the addition of this vector and another.
 DoubleVector add(DoubleVector v)
          DOCUMENT ME!
 java.lang.Object clone()
          Clone vector into a new vector.
 boolean equals(java.lang.Object obj, double tol)
          Compares two vectors for equality.
 double getPrimitiveElement(int n)
          Returns a component of this vector.
 AbstractDoubleVector mapElements(PrimitiveMapping f)
          Applies a function on all the vector components.
 double mass()
          Returns the mass.
 AbelianGroup.Member negate()
          Returns the negative of this vector.
 double norm()
          Returns the l2-norm (magnitude).
 void normalize()
          Makes the norm of this vector equal to 1.
 AbstractDoubleVector scalarDivide(double x)
          Returns the division of this vector by a scalar.
 VectorSpace.Member scalarDivide(Field.Member x)
          Returns the division of this vector by a scalar.
 AbstractDoubleVector scalarMultiply(double x)
          Returns the multiplication of this vector by a scalar.
 Module.Member scalarMultiply(Ring.Member x)
          Returns the multiplication of this vector by a scalar.
 double scalarProduct(AbstractDoubleVector v)
          Returns the scalar product of this vector and another.
 double scalarProduct(DoubleSparseVector v)
          Returns the scalar product of this vector and another.
 double scalarProduct(DoubleVector v)
          DOCUMENT ME!
 void setAllElements(double r)
          Sets the value of all elements of the vector.
 void setElement(int n, double x)
          Sets the value of a component of this vector.
 AbelianGroup.Member subtract(AbelianGroup.Member v)
          Returns the subtraction of this vector by another.
 AbstractDoubleVector subtract(AbstractDoubleVector v)
          Returns the subtraction of this vector by another.
 DoubleSparseVector subtract(DoubleSparseVector v)
          Returns the subtraction of this vector by another.
 DoubleVector subtract(DoubleVector v)
          DOCUMENT ME!
 double sumSquares()
          Returns the sum of the squares of the components.
 DoubleSparseMatrix tensorProduct(DoubleSparseVector 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 double vector.
 double[] toPrimitiveArray()
          Projects the vector to an array.
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractDoubleVector
abs, equals, getColumn, getElement, getRow, getSubVector, hashCode, infNorm, max, mean, min, multiply, norm, read, reverse, setColumn, setElement, setRow, setSubVector, standardDeviation, tensorProduct, toMatrix, toString, transpose, 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
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
 

Constructor Detail

DoubleSparseVector

public DoubleSparseVector(int dim)
Constructs an empty vector.

Parameters:
dim - the dimension of the vector.

DoubleSparseVector

public DoubleSparseVector(double[] array)
Constructs a vector from an array.

Parameters:
array - DOCUMENT ME!

DoubleSparseVector

public DoubleSparseVector(AbstractDoubleVector vec)
Constructs a vector by copying a vector.

Parameters:
vec - an assigned value
Method Detail

equals

public boolean equals(java.lang.Object obj,
                      double tol)
Compares two vectors for equality.

Overrides:
equals in class AbstractDoubleVector
Parameters:
obj - a double sparse vector
tol - DOCUMENT ME!
Returns:
DOCUMENT ME!

toIntegerVector

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

Overrides:
toIntegerVector in class AbstractDoubleVector
Returns:
a double vector

toComplexVector

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

Overrides:
toComplexVector in class AbstractDoubleVector
Returns:
a complex vector

getPrimitiveElement

public double getPrimitiveElement(int n)
Returns a component of this vector.

Specified by:
getPrimitiveElement in class AbstractDoubleVector
Parameters:
n - index of the vector component
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If attempting to access an invalid component.

setElement

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

Specified by:
setElement in class AbstractDoubleVector
Parameters:
n - index of the vector component
x - a number
Throws:
IllegalDimensionException - If attempting to access an invalid component.

setAllElements

public void setAllElements(double r)
Sets the value of all elements of the vector. You should think about using a DoubleVector.

Overrides:
setAllElements in class AbstractDoubleVector
Parameters:
r - a ring element

norm

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

Specified by:
norm in interface BanachSpace.Member
Overrides:
norm in class AbstractDoubleVector
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

normalize

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

Overrides:
normalize in class AbstractDoubleVector

sumSquares

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

Overrides:
sumSquares in class AbstractDoubleVector
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

mass

public double mass()
Returns the mass.

Overrides:
mass in class AbstractDoubleVector
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

negate

public AbelianGroup.Member negate()
Returns the negative of this vector.

Specified by:
negate in interface AbelianGroup.Member
Returns:
DOCUMENT ME!

add

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

Specified by:
add in interface AbelianGroup.Member
Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

add

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

Overrides:
add in class AbstractDoubleVector
Parameters:
v - a double vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

add

public DoubleVector add(DoubleVector v)
DOCUMENT ME!

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

add

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

Parameters:
v - a double sparse vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

subtract

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

Specified by:
subtract in interface AbelianGroup.Member
Parameters:
v - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

subtract

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

Overrides:
subtract in class AbstractDoubleVector
Parameters:
v - a double vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

subtract

public DoubleVector subtract(DoubleVector v)
DOCUMENT ME!

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

subtract

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

Parameters:
v - a double sparse vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

scalarMultiply

public Module.Member scalarMultiply(Ring.Member x)
Returns the multiplication of this vector by a scalar.

Specified by:
scalarMultiply in interface Module.Member
Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

scalarMultiply

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

Overrides:
scalarMultiply in class AbstractDoubleVector
Parameters:
x - a double
Returns:
DOCUMENT ME!

scalarDivide

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

Specified by:
scalarDivide in interface VectorSpace.Member
Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

scalarDivide

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

Overrides:
scalarDivide in class AbstractDoubleVector
Parameters:
x - a double
Returns:
DOCUMENT ME!

scalarProduct

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

Overrides:
scalarProduct in class AbstractDoubleVector
Parameters:
v - a double vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

scalarProduct

public double scalarProduct(DoubleVector v)
DOCUMENT ME!

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

scalarProduct

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

Parameters:
v - a double sparse vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the vectors are different sizes.

tensorProduct

public DoubleSparseMatrix tensorProduct(DoubleSparseVector v)
Returns the tensor product of this vector and another.

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

mapElements

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

Overrides:
mapElements in class AbstractDoubleVector
Parameters:
f - a user-defined function
Returns:
a double sparse vector

toPrimitiveArray

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

Overrides:
toPrimitiveArray in class AbstractDoubleVector
Returns:
an double array.

clone

public java.lang.Object clone()
Clone vector into a new vector.

Overrides:
clone in class java.lang.Object
Returns:
the cloned vector.