JSci.maths
Class DoubleSparseVector

java.lang.Object
  extended by JSci.maths.MathVector
      extended by JSci.maths.DoubleVector
          extended by JSci.maths.DoubleSparseVector
All Implemented Interfaces:
java.io.Serializable, BanachSpace.Member, Module.Member, VectorSpace.Member, AbelianGroup.Member, Member

public final class DoubleSparseVector
extends DoubleVector

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

Author:
Daniel Lemire, Alain Beliveau
See Also:
Serialized Form

Field Summary
protected static int SPARSE
          Storage format identifier.
 
Fields inherited from class JSci.maths.DoubleVector
ARRAY_1D, vector
 
Fields inherited from class JSci.maths.MathVector
CLASS_SPECIFIC, N, storageFormat
 
Constructor Summary
DoubleSparseVector(double[] array)
          Constructs a vector from an array.
DoubleSparseVector(int dim)
          Constructs an empty vector.
 
Method Summary
 DoubleSparseVector add(DoubleSparseVector v)
          Returns the addition of this vector and another.
 DoubleVector add(DoubleVector v)
          Returns the addition of this vector and another.
 boolean equals(java.lang.Object a)
          Compares two vectors for equality.
protected  void finalize()
          Finalize.
 double getComponent(int n)
          Returns a component of this vector.
 DoubleVector mapComponents(Mapping f)
          Applies a function on all the vector components.
 double mass()
          Returns the mass.
 double norm()
          Returns the l2-norm (magnitude).
 void normalize()
          Makes the norm of this vector equal to 1.
 DoubleVector scalarDivide(double x)
          Returns the division of this vector by a scalar.
 DoubleVector scalarMultiply(double x)
          Returns the multiplication of this vector by a scalar.
 double scalarProduct(DoubleSparseVector v)
          Returns the scalar product of this vector and another.
 double scalarProduct(DoubleVector v)
          Returns the scalar product of this vector and another.
 void setComponent(int n, double x)
          Sets the value of a component of this vector.
 DoubleSparseVector subtract(DoubleSparseVector v)
          Returns the subtraction of this vector by another.
 DoubleVector subtract(DoubleVector v)
          Returns the subtraction of this vector by another.
 double sumSquares()
          Returns the sum of the squares of the components.
 DoubleSparseMatrix tensorProduct(DoubleSparseVector v)
          Returns the tensor product of this vector and another.
 java.lang.String toString()
          Returns a comma delimited string representing the value of this vector.
 
Methods inherited from class JSci.maths.DoubleVector
add, hashCode, infNorm, negate, norm, scalarDivide, scalarMultiply, subtract, toComplexVector, toIntegerVector
 
Methods inherited from class JSci.maths.MathVector
dimension, getInvalidComponentMsg
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SPARSE

protected static final int SPARSE
Storage format identifier.

See Also:
Constant Field Values
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.

Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalize.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - Any that occur.

equals

public boolean equals(java.lang.Object a)
Compares two vectors for equality.

Overrides:
equals in class DoubleVector
Parameters:
a - a double sparse vector

toString

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

Overrides:
toString in class DoubleVector

getComponent

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

Overrides:
getComponent in class DoubleVector
Parameters:
n - index of the vector component
Throws:
VectorDimensionException - If attempting to access an invalid component.

setComponent

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

Overrides:
setComponent in class DoubleVector
Parameters:
n - index of the vector component
x - a number
Throws:
VectorDimensionException - If attempting to access an invalid component.

norm

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

Specified by:
norm in interface BanachSpace.Member
Overrides:
norm in class DoubleVector

normalize

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

Overrides:
normalize in class DoubleVector

sumSquares

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


mass

public double mass()
Returns the mass.


add

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

Overrides:
add in class DoubleVector
Parameters:
v - a double vector
Throws:
VectorDimensionException - If the vectors are different sizes.

add

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

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

subtract

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

Overrides:
subtract in class DoubleVector
Parameters:
v - a double vector
Throws:
VectorDimensionException - If the vectors are different sizes.

subtract

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

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

scalarMultiply

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

Overrides:
scalarMultiply in class DoubleVector
Parameters:
x - a double

scalarDivide

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

Overrides:
scalarDivide in class DoubleVector
Parameters:
x - a double
Throws:
java.lang.ArithmeticException - If divide by zero.

scalarProduct

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

Overrides:
scalarProduct in class DoubleVector
Parameters:
v - a double vector
Throws:
VectorDimensionException - If the vectors are different sizes.

scalarProduct

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

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

tensorProduct

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


mapComponents

public DoubleVector mapComponents(Mapping f)
Applies a function on all the vector components.

Overrides:
mapComponents in class DoubleVector
Parameters:
f - a user-defined function
Returns:
a double sparse vector