org.systemsbiology.gaggle.experiment.gui.vectormath
Class ReadOnlyMathVector

java.lang.Object
  extended by org.systemsbiology.gaggle.experiment.gui.vectormath.ReadOnlyMathVector
All Implemented Interfaces:
ReadOnlyVectorDataProvider
Direct Known Subclasses:
MathVector

public class ReadOnlyMathVector
extends java.lang.Object
implements ReadOnlyVectorDataProvider

Implementation of a vector view of a non-modifiable sequence of floating-point values.


Method Summary
 MathVector copy()
          Creates a read-write vector referencing a copy of the data behind this vector.
 double correlation(ReadOnlyMathVector v)
          Returns the linear correlation coefficient (Pearson correlation) between this vector and v.
 double dot(ReadOnlyMathVector v)
          Returns the dot product of this vector with v.
 double dotNorm(ReadOnlyMathVector v)
          Returns the dot product of the normalized versions of this vector and v (neither vector is modified).
 boolean equals(ReadOnlyMathVector v, double tolerance)
          Returns true if every element of this vector is within 'tolerance' of the corresponding element in v; i.e.
 double get(int index)
          Returns the double value at the specified index.
 double[] getNewDataArray()
          Returns an array containing a copy of the data behind this vector.
 double getQuick(int index)
          Unchecked access to the double value at the specified index.
 double mag()
          Returns the normal euclidean magnitude of this vector, i.e.
 double magSquared()
          returns the square of the euclidean magnitude of this vector, i.e.
 double mean()
          Returns the average of the entries of this vector.
 ReadOnlyMathVector readOnlyCopy()
          Creates a read-only vector referencing a copy of the data behind this vector.
 int size()
          Returns the number of elements in this vector.
 java.lang.String toString()
          Returns a String representation of this vector.
static int verifySizeMatch(ReadOnlyMathVector v1, ReadOnlyMathVector v2)
          Helper method to check size matching when combining two vectors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

copy

public MathVector copy()
Creates a read-write vector referencing a copy of the data behind this vector.


readOnlyCopy

public ReadOnlyMathVector readOnlyCopy()
Creates a read-only vector referencing a copy of the data behind this vector.


getNewDataArray

public double[] getNewDataArray()
Returns an array containing a copy of the data behind this vector.


size

public int size()
Returns the number of elements in this vector.

Specified by:
size in interface ReadOnlyVectorDataProvider

verifySizeMatch

public static int verifySizeMatch(ReadOnlyMathVector v1,
                                  ReadOnlyMathVector v2)
                           throws java.lang.IndexOutOfBoundsException
Helper method to check size matching when combining two vectors.

Parameters:
v1 - the first vector
v2 - the second vector
Returns:
int the size if v1 and v2 have the same size
Throws:
java.lang.IndexOutOfBoundsException - if v1 and v2 have different sizes

get

public double get(int index)
           throws java.lang.IndexOutOfBoundsException
Returns the double value at the specified index.

Parameters:
index - the index of the element to return
Throws:
java.lang.IndexOutOfBoundsException - unless index is valid, i.e. 0 <= index < size()

getQuick

public double getQuick(int index)
Unchecked access to the double value at the specified index. Some unspecified run-time exception will likely result if the index is invalid.

Specified by:
getQuick in interface ReadOnlyVectorDataProvider
Parameters:
index - the index of the element to return

equals

public boolean equals(ReadOnlyMathVector v,
                      double tolerance)
               throws java.lang.IndexOutOfBoundsException
Returns true if every element of this vector is within 'tolerance' of the corresponding element in v; i.e. Math.abs(this[i] - v[i]) <= tolerance.

Parameters:
v - the vector to compare to
tolerance - the desired measure of equality
Throws:
java.lang.IndexOutOfBoundsException - if v is not the same size as this vector

mag

public double mag()
Returns the normal euclidean magnitude of this vector, i.e. sqrt( Sum(this[i]*this[i]) )


magSquared

public double magSquared()
returns the square of the euclidean magnitude of this vector, i.e. Sum(this[i]*this[i])


mean

public double mean()
Returns the average of the entries of this vector.


dot

public double dot(ReadOnlyMathVector v)
           throws java.lang.IndexOutOfBoundsException
Returns the dot product of this vector with v.

Parameters:
v - the other vector
Throws:
java.lang.IndexOutOfBoundsException - if v is not the same size as this vector

dotNorm

public double dotNorm(ReadOnlyMathVector v)
               throws java.lang.IndexOutOfBoundsException
Returns the dot product of the normalized versions of this vector and v (neither vector is modified). i.e., returns this.dot(v)/( this.mag()*v.mag() ) If the magnitude of either vector is zero, this method return zero.

Parameters:
v - the other vector
Throws:
java.lang.IndexOutOfBoundsException - if v is not the same size as this vector

correlation

public double correlation(ReadOnlyMathVector v)
                   throws java.lang.IndexOutOfBoundsException
Returns the linear correlation coefficient (Pearson correlation) between this vector and v. The correlation coefficient between vectors X and Y is defined as coeff = Xp.dot(Yp) / ( Xp.mag()*Yp.mag() ) where Xp = X - X.mean(), Yp = Y - Y.mean().

Parameters:
v - the other vector
Throws:
java.lang.IndexOutOfBoundsException - if v is not the same size as this vector

toString

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

Overrides:
toString in class java.lang.Object