drasys.or.matrix
Class SparseVector

java.lang.Object
  |
  +--drasys.or.matrix.RealContainer
        |
        +--drasys.or.matrix.Vect
              |
              +--drasys.or.matrix.SparseVector

public class SparseVector
extends Vect
implements SizableVectorI

A sparse dynamic vector of double values.

References:

Matrix Computations (Johns Hopkins Studies in the Mathematical Sciences)
    Gene H. Golub, Charles F. Van Loan (Contributor) / Paperback / Published 1996
Numerical Recipes in C : The Art of Scientific Computing
    William H. Press, et al / Hardcover / Published 1993
Parallel Algorithms for Matrix Computations
    K.A. Gallivan / Paperback / Published 1990

See Also:
Serialized Form

Fields inherited from class drasys.or.matrix.RealContainer
_epsilon, _globalEpsilon
 
Constructor Summary
SparseVector()
          Creates a sparse vector with zero size.
SparseVector(double[] array)
          Creates a sparse vector from the contents of 'array'.
SparseVector(double[] array, double epsilon)
          Creates a sparse vector from the contents of 'array'.
SparseVector(int size)
          Creates a sparse vector with explicit size.
SparseVector(int size, int capacityOfElements)
          Creates a sparse vector with explicit size and element capacity.
SparseVector(VectorI vector)
          Creates a sparse vector from the contents of 'vector'.
SparseVector(VectorI vector, double epsilon)
          Creates a sparse vector from the non-null elements of 'vector'.
 
Method Summary
 void addElement(double value)
          Adds a new element to the end of the vector.
 int capacity()
          Always returns Integer.MAX_VALUE.
 double elementAt(int index)
          Gets an element's value from the vector.
 java.util.Enumeration elements()
          Returns an enumeration of the non-null elements in the vector.
 double[] getArray()
          Returns a new two-dimensional array containing the values in matrix.
 boolean isNull(int index)
          Returns true if an element has no value associated with it.
 void setCapacity(int capacity)
          Has no effect.
 void setElementAt(int index, double value)
          Sets an element's value in the vector.
 void setElements(double value)
          Sets the value of all the non-null elements.
 void setSize(int size)
          Sets the size of the vector.
 int size()
          The length of the vector.
 int sizeOfElements()
          Returns the number of non-null elements in the vector.
 double sum(int begin)
          Returns the sum of all of the elements in the subvector.
 double sum(int begin, int end)
          Returns the sum of all of the selected elements in the subvector.
 double sumOfSquaredDifferences(int begin, double scaler)
          Returns the sum the squared differences between 'scaler' and the elements in the subvector.
 double sumOfSquaredDifferences(int begin, int end, double scaler)
          Returns the sum the squared differences between 'scaler' and the selected elements in the subvector.
 double sumOfSquares(int begin)
          Returns the sum of the squares of the elements in the subvector.
 double sumOfSquares(int begin, int end)
          Returns the sum of the squares of the selected elements in the subvector.
 
Methods inherited from class drasys.or.matrix.Vect
equals, equals, setElements, sum, sumOfSquaredDifferences, sumOfSquares, toString
 
Methods inherited from class drasys.or.matrix.RealContainer
equals, getEpsilon, getGlobalEpsilon, setEpsilon, setGlobalEpsilon
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SparseVector

public SparseVector()
Creates a sparse vector with zero size.

SparseVector

public SparseVector(int size)
Creates a sparse vector with explicit size.

SparseVector

public SparseVector(int size,
                    int capacityOfElements)
Creates a sparse vector with explicit size and element capacity.

SparseVector

public SparseVector(double[] array)
Creates a sparse vector from the contents of 'array'. All the elements in array will be added.

SparseVector

public SparseVector(double[] array,
                    double epsilon)
Creates a sparse vector from the contents of 'array'. Elements in which equal 0.0 to within 'epsilon' will not be added. The vector epsilon will be set to 'epsilon'.

SparseVector

public SparseVector(VectorI vector)
Creates a sparse vector from the contents of 'vector'. All non-null elements in 'vector' will be added.

SparseVector

public SparseVector(VectorI vector,
                    double epsilon)
Creates a sparse vector from the non-null elements of 'vector'. Elements which equal 0.0 to within 'epsilon' will not be added. The vector epsilon will be set to 'epsilon'.
Method Detail

setSize

public void setSize(int size)
Sets the size of the vector.
Specified by:
setSize in interface SizableVectorI

setCapacity

public void setCapacity(int capacity)
Has no effect.
Specified by:
setCapacity in interface SizableVectorI

addElement

public void addElement(double value)
Adds a new element to the end of the vector.
Specified by:
addElement in interface SizableVectorI

sizeOfElements

public int sizeOfElements()
Returns the number of non-null elements in the vector.

size

public int size()
The length of the vector.

capacity

public int capacity()
Always returns Integer.MAX_VALUE.
Specified by:
capacity in interface SizableVectorI

setElements

public void setElements(double value)
Sets the value of all the non-null elements.

setElementAt

public void setElementAt(int index,
                         double value)
Sets an element's value in the vector.

getArray

public double[] getArray()
Returns a new two-dimensional array containing the values in matrix. The rows of the array hold the rows of the matrix.

isNull

public boolean isNull(int index)
Returns true if an element has no value associated with it. Elements which have no value assigned return 0.0 when accessed.

elementAt

public double elementAt(int index)
Gets an element's value from the vector.
Tags copied from interface: VectorI
Returns:
zero if the element is null.

elements

public java.util.Enumeration elements()
Returns an enumeration of the non-null elements in the vector. The elements are enumerated in random order.
Returns:
an enumeration whose elements are of type VectorElementI

sum

public double sum(int begin)
Returns the sum of all of the elements in the subvector.
Overrides:
sum in class Vect

sum

public double sum(int begin,
                  int end)
Returns the sum of all of the selected elements in the subvector.

sumOfSquares

public double sumOfSquares(int begin)
Returns the sum of the squares of the elements in the subvector.
Overrides:
sumOfSquares in class Vect

sumOfSquares

public double sumOfSquares(int begin,
                           int end)
Returns the sum of the squares of the selected elements in the subvector.

sumOfSquaredDifferences

public double sumOfSquaredDifferences(int begin,
                                      double scaler)
Returns the sum the squared differences between 'scaler' and the elements in the subvector.
Overrides:
sumOfSquaredDifferences in class Vect

sumOfSquaredDifferences

public double sumOfSquaredDifferences(int begin,
                                      int end,
                                      double scaler)
Returns the sum the squared differences between 'scaler' and the selected elements in the subvector.


Copyright(C)1997-2000 by DRA Systems all rights reserved. OpsResearch.com