org.retro.neural
Class SNVector

java.lang.Object
  extended byorg.retro.neural.SNVector

public class SNVector
extends java.lang.Object


Field Summary
protected  Vector vec
           
 
Constructor Summary
  SNVector(double[] a)
           
  SNVector(int n)
           
protected SNVector(Vector x)
           
 
Method Summary
 void add(double s)
           
 void add(SNVector x)
           
static SNVector add(SNVector x, double s)
           
static SNVector add(SNVector x, SNVector y)
           
 SNVector and(SNVector x)
          Returns the logical AND of this vector with another.
 void arrayMultiply(SNVector x)
          Multiplies the elements of this vector by those of another.
static SNVector arrayMultiply(SNVector x, SNVector y)
          Returns a vector containing the products of the elements of two vectors.
 SNVector copy()
          Returns a deep copy of this vector.
 void divide(double s)
           
static SNVector divide(SNVector x, double s)
           
 double eucDist(SNVector x)
          Returns the Euclidean distance between this vector and another.
 int[] find(double s)
          Returns indices where vector equals scalar argument.
static SNVector gaussianNoise(int n, java.util.Random r)
          Returns a vector of normally distributed random values.
 SNVector ge(double s)
          Returns a vector containing ones where this vector's elements are greater than or equal to a scalar, and zeros elsewhere.
 double getValue(int i)
           
 double[] getValues()
          Returns a 1D array of the values contained in this vector.
 SNVector le(double s)
          Returns a vector containing ones where this vector's elements are less than or equal to a scalar, and zeros elsewhere.
 int length()
           
 double max()
          Returns the largest value of any element in this vector.
 double min()
          Returns the value of the smallest element of this vector.
 void multiply(double s)
           
 SNVector multiply(SNMatrix a)
          Returns the product of this Vector and a Matrix.
 void multiply(SNVector x)
           
static SNVector multiply(SNVector x, double s)
           
 SNVector ne(double s)
          Returns a vector containing ones where this vector's elements are not equal to a scalar, and zeros elsewhere.
 double nycDist(SNVector x)
          Returns the Manhattan distance (L1 norm of differences) between this vector and another.
 SNMatrix outer(SNVector x)
          Returns the outer product of this vector and another.
 SNMatrix repmat(int m)
          Replicates this vector as a matrix.
 void setAll(double s)
          Sets all entries to a scalar.
 void setValue(int i, double s)
          Sets an entry to a scalar at a certain index.
 SNVector sort()
          Returns a copy of this vector, sorted in ascending order.
 void subtract(double s)
           
 void subtract(SNVector x)
           
static SNVector subtract(SNVector x, double s)
           
static SNVector subtract(SNVector x, SNVector y)
           
 double sum()
          Returns the sum of the elements of this vector.
 java.lang.String toString()
          Returns a String representation of this vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vec

protected Vector vec
Constructor Detail

SNVector

public SNVector(int n)

SNVector

public SNVector(double[] a)

SNVector

protected SNVector(Vector x)
Method Detail

length

public int length()

getValue

public double getValue(int i)
                throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException

add

public void add(double s)

subtract

public void subtract(double s)

multiply

public void multiply(double s)

divide

public void divide(double s)

add

public static SNVector add(SNVector x,
                           double s)

subtract

public static SNVector subtract(SNVector x,
                                double s)

multiply

public static SNVector multiply(SNVector x,
                                double s)

divide

public static SNVector divide(SNVector x,
                              double s)

add

public void add(SNVector x)
         throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException

subtract

public void subtract(SNVector x)
              throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException

multiply

public void multiply(SNVector x)
              throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException

add

public static SNVector add(SNVector x,
                           SNVector y)
                    throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException

subtract

public static SNVector subtract(SNVector x,
                                SNVector y)
                         throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException

arrayMultiply

public static SNVector arrayMultiply(SNVector x,
                                     SNVector y)
                              throws java.lang.RuntimeException
Returns a vector containing the products of the elements of two vectors.

Parameters:
x - one vector
y - the other vector
Returns:
x .* y
Throws:
java.lang.RuntimeException - if the vectors have unequal lengths

arrayMultiply

public void arrayMultiply(SNVector x)
                   throws java.lang.RuntimeException
Multiplies the elements of this vector by those of another.

Parameters:
x - the other vector
Throws:
java.lang.RuntimeException - if the vectors have unequal lengths

getValues

public double[] getValues()
Returns a 1D array of the values contained in this vector.

Returns:
values

sum

public double sum()
Returns the sum of the elements of this vector.

Returns:
sum

min

public double min()
Returns the value of the smallest element of this vector.

Returns:
minimum value

eucDist

public double eucDist(SNVector x)
               throws java.lang.RuntimeException
Returns the Euclidean distance between this vector and another.

Parameters:
x - the other vector
Returns:
dist(this, x)
Throws:
java.lang.RuntimeException - if the vectors have unequal lengths

repmat

public SNMatrix repmat(int m)
Replicates this vector as a matrix. Returns an m-by-n matrix for a length-n vector replicated m times.

Parameters:
m - number of times to replicate
Returns:
an m-by-n Matrix

sort

public SNVector sort()
Returns a copy of this vector, sorted in ascending order.

Returns:
sorted copy

find

public int[] find(double s)
Returns indices where vector equals scalar argument. Index of first value in any vector is 0.

Returns:
indices where vector equals scalar

nycDist

public double nycDist(SNVector x)
               throws java.lang.RuntimeException
Returns the Manhattan distance (L1 norm of differences) between this vector and another.

Parameters:
x - the other vector
Returns:
Manhattan distance between this and anotherVector
Throws:
java.lang.RuntimeException - if Vectors have unequal lengths

gaussianNoise

public static SNVector gaussianNoise(int n,
                                     java.util.Random r)
Returns a vector of normally distributed random values. Values are taken from a Gaussian distribution with zero mean and standard deviation one.

Returns:
vector of normally distributed random values

outer

public SNMatrix outer(SNVector x)
Returns the outer product of this vector and another.

Parameters:
x - the other vector
Returns:
this^T X x
Throws:
java.lang.RuntimeException - if the other vector is null

copy

public SNVector copy()
Returns a deep copy of this vector.

Returns:
vector copy

setAll

public void setAll(double s)
Sets all entries to a scalar.

Parameters:
s - the scalar

setValue

public void setValue(int i,
                     double s)
              throws java.lang.RuntimeException
Sets an entry to a scalar at a certain index.

Parameters:
i - index
s - scalar
Throws:
java.lang.RuntimeException - if the index is invalide

ne

public SNVector ne(double s)
Returns a vector containing ones where this vector's elements are not equal to a scalar, and zeros elsewhere.

Parameters:
s - the scalar
Returns:
vector of ones and zeros

ge

public SNVector ge(double s)
Returns a vector containing ones where this vector's elements are greater than or equal to a scalar, and zeros elsewhere.

Parameters:
s - the scalar
Returns:
vector of ones and zeros

le

public SNVector le(double s)
Returns a vector containing ones where this vector's elements are less than or equal to a scalar, and zeros elsewhere.

Parameters:
s - the scalar
Returns:
vector of ones and zeros

max

public double max()
Returns the largest value of any element in this vector.

Returns:
the largest value

and

public SNVector and(SNVector x)
             throws java.lang.RuntimeException
Returns the logical AND of this vector with another. Elements of the result are 1 where both vectors are non-zero, and zero elsewhere.

Parameters:
x - the other vector
Returns:
vector of 1's and 0's
Throws:
java.lang.RuntimeException - if the vectors have unequal lengths

multiply

public SNVector multiply(SNMatrix a)
                  throws java.lang.RuntimeException
Returns the product of this Vector and a Matrix.

Parameters:
a - the matrix
Returns:
this * a
Throws:
InvalidOperationException - if the matrix is null
InvalidOperationException - if the inner dimensions mismatch
java.lang.RuntimeException

toString

public java.lang.String toString()
Returns a String representation of this vector.

Returns:
string representation