JSci.maths.vectors
Class DoubleSparseVector

java.lang.Object
  extended byJSci.maths.vectors.MathVector
      extended byJSci.maths.vectors.AbstractDoubleVector
          extended byJSci.maths.vectors.DoubleSparseVector
All Implemented Interfaces:
AbelianGroup.Member, BanachSpace.Member, Member, Module.Member, java.io.Serializable, VectorSpace.Member

public final class DoubleSparseVector
extends AbstractDoubleVector

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

See Also:
Serialized Form

Field Summary
 
Fields inherited from class JSci.maths.vectors.MathVector
N
 
Constructor Summary
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)
           
 boolean equals(java.lang.Object a)
          Compares two vectors for equality.
 double getComponent(int n)
          Returns a component of this vector.
 AbstractDoubleVector mapComponents(Mapping 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).
 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)
           
 void setComponent(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)
           
 double sumSquares()
          Returns the sum of the squares of the components.
 DoubleSparseMatrix tensorProduct(DoubleSparseVector v)
          Returns the tensor product of this vector and another.
 
Methods inherited from class JSci.maths.vectors.AbstractDoubleVector
hashCode, infNorm, norm, normalize, toString
 
Methods inherited from class JSci.maths.vectors.MathVector
dimension, getInvalidComponentMsg
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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

equals

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

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

getComponent

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

Specified by:
getComponent in class AbstractDoubleVector
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.

Specified by:
setComponent in class AbstractDoubleVector
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 AbstractDoubleVector

sumSquares

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


mass

public double mass()
Returns the mass.

Overrides:
mass in class AbstractDoubleVector

negate

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


add

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

Parameters:
v - a group member

add

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

Specified by:
add in class AbstractDoubleVector
Parameters:
v - a double vector
Throws:
VectorDimensionException - If the vectors are different sizes.

add

public DoubleVector add(DoubleVector v)

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 AbelianGroup.Member subtract(AbelianGroup.Member v)
Returns the subtraction of this vector by another.

Parameters:
v - a group member

subtract

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

Specified by:
subtract in class AbstractDoubleVector
Parameters:
v - a double vector
Throws:
VectorDimensionException - If the vectors are different sizes.

subtract

public DoubleVector subtract(DoubleVector v)

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 Module.Member scalarMultiply(Ring.Member x)
Returns the multiplication of this vector by a scalar.

Parameters:
x - a ring member

scalarMultiply

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

Specified by:
scalarMultiply in class AbstractDoubleVector
Parameters:
x - a double

scalarDivide

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

Parameters:
x - a field member

scalarDivide

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

Specified by:
scalarDivide in class AbstractDoubleVector
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.

Specified by:
scalarProduct in class AbstractDoubleVector
Parameters:
v - a double vector
Throws:
VectorDimensionException - If the vectors are different sizes.

scalarProduct

public double scalarProduct(DoubleVector v)

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 AbstractDoubleVector mapComponents(Mapping f)
Applies a function on all the vector components.

Specified by:
mapComponents in class AbstractDoubleVector
Parameters:
f - a user-defined function
Returns:
a double sparse vector