edu.stanford.rsl.konrad.numerics
Class SimpleVector

java.lang.Object
  extended by edu.stanford.rsl.konrad.numerics.SimpleVector
All Implemented Interfaces:
java.io.Serializable

public class SimpleVector
extends java.lang.Object
implements java.io.Serializable

Author:
Andreas Keil, Andreas Maier (only very few additions)
See Also:
Serialized Form

Nested Class Summary
static class SimpleVector.VectorNormType
           
 
Constructor Summary
SimpleVector()
          Creates a null vector.
SimpleVector(double... otherBuffer)
          Creates a new vector initialized by an ordered list of numbers
SimpleVector(int len)
          Creates a len dimensional vector
SimpleVector(Jama.Matrix other)
          Creates a new vector from a jama equivalent
SimpleVector(SimpleVector otherVec)
          Creates a new vector from otherVec.
SimpleVector(java.lang.String str)
          Creates a new vector from a string equivalent
 
Method Summary
 void add(double addend)
          Method to add a scalar to this vector in place.
 void add(SimpleVector... addends)
          Method to add other vectors to this vector in place.
 void addToElement(int i, double addend)
           
 SimpleVector clone()
           
 double[] copyAsDoubleArray()
          Copies the elements of this vector to a double array
 void copyTo(double[] other)
          Copies the element of this vector to the double array provided
 void divideBy(double divisor)
           
 SimpleVector dividedBy(double divisor)
           
 void divideElementBy(int i, double divisor)
           
 void divideElementWiseBy(SimpleVector... divisors)
           
 void fill(double value)
          Sets all entries to the given value.
 double getElement(int i)
          Retrieve vector element at index i
 int getLen()
           
 SimpleVector getSubVec(int firstInd, int size)
           
 java.lang.String getVectorSerialization()
           
 void init(double... otherBuffer)
          Initialize vector with a comma-separated list of double array
 void init(int len)
          Initialize vector to [0,0,...,0] and length len.
 void init(SimpleVector otherVec)
          Initialize vector with otherVec
 void init(java.lang.String str)
          Initialize vector with string equivalent
 SimpleVector multipliedBy(double factor)
          Returns a scaled instance of the vector.
 void multiplyBy(double factor)
           
 void multiplyElementBy(int i, double factor)
           
 void multiplyElementWiseBy(SimpleVector... factors)
           
 void negate()
           
 SimpleVector negated()
           
 double norm(SimpleVector.VectorNormType normType)
           
 SimpleVector normalizedL2()
           
 void normalizeL2()
           
 double normL2()
           
 void ones()
          Sets all entries to 1.0.
 void randomize(double min, double max)
          Assigns random values to the entries of the vector.
 void setElementValue(int i, double val)
          Replaces the vector element at index i
 void setSubVecValue(int firstInd, SimpleVector subVector)
           
 void setVectorSerialization(java.lang.String str)
           
 void subtract(double subtrahend)
           
 void subtract(SimpleVector... subtrahends)
           
 void subtractFromElement(int i, double subtrahend)
           
 java.lang.String toString()
           
 SimpleMatrix transposed()
           
 void zeros()
          Sets all entries to 0.0.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleVector

public SimpleVector()
Creates a null vector. vector must be initialized before use;


SimpleVector

public SimpleVector(int len)
Creates a len dimensional vector

Parameters:
len - is dimension of vector.

SimpleVector

public SimpleVector(SimpleVector otherVec)
Creates a new vector from otherVec. The entries of this vector are element wise equal to other vec

Parameters:
otherVec -

SimpleVector

public SimpleVector(double... otherBuffer)
Creates a new vector initialized by an ordered list of numbers

Parameters:
otherBuffer -

SimpleVector

public SimpleVector(java.lang.String str)
Creates a new vector from a string equivalent

Parameters:
str -

SimpleVector

public SimpleVector(Jama.Matrix other)
Creates a new vector from a jama equivalent

Parameters:
other -
Method Detail

init

public void init(int len)
Initialize vector to [0,0,...,0] and length len.

Parameters:
len - is dimension of vector

init

public void init(SimpleVector otherVec)
Initialize vector with otherVec

Parameters:
otherVec -

init

public void init(double... otherBuffer)
Initialize vector with a comma-separated list of double array

Parameters:
otherBuffer -

init

public void init(java.lang.String str)
Initialize vector with string equivalent

Parameters:
str -

clone

public SimpleVector clone()
Overrides:
clone in class java.lang.Object

copyAsDoubleArray

public double[] copyAsDoubleArray()
Copies the elements of this vector to a double array

Returns:
double array containing ordered values

copyTo

public void copyTo(double[] other)
Copies the element of this vector to the double array provided

Parameters:
other - is array to be populated

getLen

public int getLen()
Returns:
the dimension of this vector

fill

public void fill(double value)
Sets all entries to the given value.


zeros

public void zeros()
Sets all entries to 0.0.


ones

public void ones()
Sets all entries to 1.0.


randomize

public void randomize(double min,
                      double max)
Assigns random values to the entries of the vector. Values are uniformly distributed in the given interval [min, max).

Parameters:
min - The lower bound of the interval the values are drawn from.
max - The upper bound of the interval the values are drawn from. Note that value max itself is excluded from the interval and therefore never assigned.

getElement

public double getElement(int i)
Retrieve vector element at index i

Parameters:
i - index to be retrieved
Returns:
element at index i

setElementValue

public void setElementValue(int i,
                            double val)
Replaces the vector element at index i

Parameters:
i - index to be replaced
val - is new value

getSubVec

public SimpleVector getSubVec(int firstInd,
                              int size)

setSubVecValue

public void setSubVecValue(int firstInd,
                           SimpleVector subVector)

addToElement

public void addToElement(int i,
                         double addend)

subtractFromElement

public void subtractFromElement(int i,
                                double subtrahend)

multiplyElementBy

public void multiplyElementBy(int i,
                              double factor)

divideElementBy

public void divideElementBy(int i,
                            double divisor)

add

public void add(double addend)
Method to add a scalar to this vector in place.

Parameters:
addend - the other vector

subtract

public void subtract(double subtrahend)

multiplyBy

public void multiplyBy(double factor)

multipliedBy

public SimpleVector multipliedBy(double factor)
Returns a scaled instance of the vector. All elements in the scaled instance are multiplied by s

Parameters:
factor - the scalar
Returns:
the scaled instance

divideBy

public void divideBy(double divisor)

dividedBy

public SimpleVector dividedBy(double divisor)

add

public void add(SimpleVector... addends)
Method to add other vectors to this vector in place.

Parameters:
addends - The other vectors.

subtract

public void subtract(SimpleVector... subtrahends)

multiplyElementWiseBy

public void multiplyElementWiseBy(SimpleVector... factors)

divideElementWiseBy

public void divideElementWiseBy(SimpleVector... divisors)

negate

public void negate()

negated

public SimpleVector negated()

transposed

public SimpleMatrix transposed()

norm

public double norm(SimpleVector.VectorNormType normType)

normL2

public double normL2()

normalizeL2

public void normalizeL2()

normalizedL2

public SimpleVector normalizedL2()

getVectorSerialization

public java.lang.String getVectorSerialization()

setVectorSerialization

public void setVectorSerialization(java.lang.String str)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object