Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## prea.data.structure
Class DenseVector

    java.lang.Object
      prea.data.structure.DenseVector

    public class DenseVector

extends java.lang.Object

This class implements dense vector with array-based implementation. Note that we use UJMP package (http://www.ujmp.org) to implement this class.

Since:
  2012. 4. 20
Version:
  1.1
Author:
  Joonseok Lee

Field Summary
`private org.ujmp.core.Matrix` | `map` The UJMP matrix to store data.
`private int` | `N` The length (maximum number of items to be stored) of sparse vector.

Constructor Summary
`DenseVector()` Construct an empty dense vector, with capacity 0.
`DenseVector(int n)` Construct a new dense vector with size n.
`DenseVector(org.ujmp.core.Matrix m)` Construct a new dense vector, having same data with the given UJMP matrix.

Method Summary
`double` | `absoluteSum()` Sum of absolute value of every element in the vector.
`DenseVector` | `add(double alpha)` Scalar addition operator.
`double` | `average()` Average of every element.
`DenseVector` | `commonMinus(DenseVector b)` Vector subtraction (a - b), for only existing values.
`DenseVector` | `copy()` Copy the whole dense vector and make a clone.
`DenseVector` | `exp(double alpha)` Exponential of a given constant.
`double` | `getValue(int i)` Retrieve a stored value from the given index.
`org.ujmp.core.Matrix` | `getVector()` Get an UJMP matrix.
`int[]` | `indexList()` Get a list of existing indices.
`void` | `initialize(double value)` Set a same value to every element.
`void` | `initialize(int[] index, double value)` Set same value to given indices.
`double` | `innerProduct(DenseVector b)` Inner product of two vectors.
`int` | `itemCount()` Actual number of items in the vector.
`int` | `length()` Capacity of this vector
`DenseVector` | `minus(DenseVector b)` Vector subtraction (a - b)
`double` | `norm()` 2-norm of the vector.
`DenseMatrix` | `outerProduct(DenseVector b)` Outer product of two vectors.
`double` | `partInnerProduct(DenseVector b, int[] indexList)` Inner-product for indices only in the given indices.
`DenseVector` | `partMinus(DenseVector b, int[] indexList)` Vector subtraction (a - b) for indices only in the given indices.
`DenseMatrix` | `partOuterProduct(DenseVector b, int[] indexList)` Outer-product for indices only in the given indices.
`DenseVector` | `partPlus(DenseVector b, int[] indexList)` Vector sum (a + b) for indices only in the given indices.
`DenseVector` | `plus(DenseVector b)` Vector sum (a + b)
`DenseVector` | `power(double alpha)` Scalar power operator.
`void` | `remove(int i)` Delete a value stored at the given index.
`DenseVector` | `scale(double alpha)` Scalar multiplication operator.
`void` | `setLength(int n)` Set a new capacity of the vector.
`void` | `setValue(int i, double value)` Set a new value at the given index.
`double` | `stdev()` Standard Deviation of every element.
`DenseVector` | `sub(double alpha)` Scalar subtraction operator.
`double` | `sum()` Sum of every element in the vector.
`DenseVector` | `toDenseSubset(int[] indexList)` Convert the vector into a sparse vector, but only with the selected indices.
`SparseVector` | `toSparseVector()` Convert the vector into the sparse vector.
`java.lang.String` | `toString()` Convert the vector to a printable string.
`double` | `variance()` Variance of every element.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### map

    private org.ujmp.core.Matrix map

  The UJMP matrix to store data.

### N

    private int N

  The length (maximum number of items to be stored) of sparse vector.

Constructor Detail

### DenseVector

    public DenseVector()

  Construct an empty dense vector, with capacity 0. Capacity can be reset with setLength method later.

### DenseVector

    public DenseVector(int n)

  Construct a new dense vector with size n.

  Parameters:
    `n` - The capacity of new dense vector.

### DenseVector

    public DenseVector(org.ujmp.core.Matrix m)

  Construct a new dense vector, having same data with the given UJMP matrix.

  Parameters:
    `m` - An UJMP matrix.

Method Detail

### getVector

    public org.ujmp.core.Matrix getVector()

  Get an UJMP matrix. Note that the Matrix class is implemented like a vector, by UJMP.

  Returns:
    UJMP matrix.

### setValue

    public void setValue(int i,
                         double value)

  Set a new value at the given index.

  Parameters:
    `i` - The index to store new value.
    `value` - The value to store.
  Throws:
    `java.lang.ArrayIndexOutOfBoundsException` - when the index is out of range.

### getValue

    public double getValue(int i)

  Retrieve a stored value from the given index.

  Parameters:
    `i` - The index to retrieve.
  Returns:
    The value stored at the given index.
  Throws:
    `java.lang.ArrayIndexOutOfBoundsException` - when the index is out of range.

### remove

    public void remove(int i)

  Delete a value stored at the given index.

  Parameters:
    `i` - The index to delete the value in it.

### copy

    public DenseVector copy()

  Copy the whole dense vector and make a clone.

  Returns:
    A clone of the current dense vector, containing same values.

### indexList

    public int[] indexList()

  Get a list of existing indices. This can be useful to traverse the whole vector efficiently only with existing values.

  Returns:
    An array of integer, containing indices with valid items.

### initialize

    public void initialize(double value)

  Set a same value to every element.

  Parameters:
    `value` - The value to assign to every element.

### initialize

    public void initialize(int[] index,
                           double value)

  Set same value to given indices.

  Parameters:
    `index` - The list of indices, which will be assigned the new value.
    `value` - The new value to be assigned.

### toSparseVector

    public SparseVector toSparseVector()

  Convert the vector into the sparse vector.

  Returns:
    The sparse vector with the same data.

### toDenseSubset

    public DenseVector toDenseSubset(int[] indexList)

  Convert the vector into a sparse vector, but only with the selected indices.

  Parameters:
    `indexList` - The list of indices converting to sparse vector.
  Returns:
    The sparse vector with the same data, with given indices.

### length

    public int length()

  Capacity of this vector

  Returns:
    The length of dense vector

### itemCount

    public int itemCount()

  Actual number of items in the vector.

  Returns:
    The number of items in the vector.

### setLength

    public void setLength(int n)

  Set a new capacity of the vector.

  Parameters:
    `n` - The new capacity value.

### add

    public DenseVector add(double alpha)

  Scalar addition operator.

  Parameters:
    `alpha` - The scalar value to be added to the original vector.
  Returns:
    The resulting vector, added by alpha.

### sub

    public DenseVector sub(double alpha)

  Scalar subtraction operator.

  Parameters:
    `alpha` - The scalar value to be subtracted from the original vector.
  Returns:
    The resulting vector, subtracted by alpha.

### scale

    public DenseVector scale(double alpha)

  Scalar multiplication operator.

  Parameters:
    `alpha` - The scalar value to be multiplied to the original vector.
  Returns:
    The resulting vector, multiplied by alpha.

### power

    public DenseVector power(double alpha)

  Scalar power operator.

  Parameters:
    `alpha` - The scalar value to be powered to the original vector.
  Returns:
    The resulting vector, powered by alpha.

### exp

    public DenseVector exp(double alpha)

  Exponential of a given constant.

  Parameters:
    `alpha` - The exponent.
  Returns:
    The resulting exponential vector.

### norm

    public double norm()

  2-norm of the vector.

  Returns:
    2-norm value of the vector.

### sum

    public double sum()

  Sum of every element in the vector.

  Returns:
    Sum value of every element.

### absoluteSum

    public double absoluteSum()

  Sum of absolute value of every element in the vector.

  Returns:
    Sum of absolute value of every element.

### average

    public double average()

  Average of every element. It ignores non-existing values.

  Returns:
    The average value.

### variance

    public double variance()

  Variance of every element. It ignores non-existing values.

  Returns:
    The variance value.

### stdev

    public double stdev()

  Standard Deviation of every element. It ignores non-existing values.

  Returns:
    The standard deviation value.

### plus

    public DenseVector plus(DenseVector b)

  Vector sum (a + b)

  Parameters:
    `b` - The vector to be added to this vector.
  Returns:
    The resulting vector after summation.
  Throws:
    `java.lang.RuntimeException` - when vector lengths disagree.

### minus

    public DenseVector minus(DenseVector b)

  Vector subtraction (a - b)

  Parameters:
    `b` - The vector to be subtracted from this vector.
  Returns:
    The resulting vector after subtraction.
  Throws:
    `java.lang.RuntimeException` - when vector lengths disagree.

### commonMinus

    public DenseVector commonMinus(DenseVector b)

  Vector subtraction (a - b), for only existing values. The resulting vector can have a non-zero value only if both vectors have a value at the index.

  Parameters:
    `b` - The vector to be subtracted from this vector.
  Returns:
    The resulting vector after subtraction.

### innerProduct

    public double innerProduct(DenseVector b)

  Inner product of two vectors.

  Parameters:
    `b` - The vector to be inner-producted with this vector.
  Returns:
    The inner-product value.

### outerProduct

    public DenseMatrix outerProduct(DenseVector b)

  Outer product of two vectors.

  Parameters:
    `b` - The vector to be outer-producted with this vector.
  Returns:
    The resulting outer-product matrix.

### partPlus

    public DenseVector partPlus(DenseVector b,
                                int[] indexList)

  Vector sum (a + b) for indices only in the given indices.

  Parameters:
    `b` - The vector to be added to this vector.
    `indexList` - The list of indices to be applied summation.
  Returns:
    The resulting vector after summation.
  Throws:
    `java.lang.RuntimeException` - when vector lengths disagree.

### partMinus

    public DenseVector partMinus(DenseVector b,
                                 int[] indexList)

  Vector subtraction (a - b) for indices only in the given indices.

  Parameters:
    `b` - The vector to be subtracted from this vector.
    `indexList` - The list of indices to be applied subtraction.
  Returns:
    The resulting vector after subtraction.
  Throws:
    `java.lang.RuntimeException` - when vector lengths disagree.

### partInnerProduct

    public double partInnerProduct(DenseVector b,
                                   int[] indexList)

  Inner-product for indices only in the given indices.

  Parameters:
    `b` - The vector to be inner-producted with this vector.
    `indexList` - The list of indices to be applied inner-product.
  Returns:
    The inner-product value.

### partOuterProduct

    public DenseMatrix partOuterProduct(DenseVector b,
                                        int[] indexList)

  Outer-product for indices only in the given indices.

  Parameters:
    `b` - The vector to be outer-producted with this vector.
    `indexList` - The list of indices to be applied outer-product.
  Returns:
    The outer-product value.

### toString

    public java.lang.String toString()

  Convert the vector to a printable string.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    The resulted string in the form of "(1: 5.0) (2: 4.5)"

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD