ru.sscc.util.data
Class RealVectors

java.lang.Object
  |
  +--ru.sscc.util.data.RealVectors
Direct Known Subclasses:
DoubleIRefVectors, DoubleSRefVectors, DoubleVectors, FloatIRefVectors, FloatSRefVectors, FloatVectors

public abstract class RealVectors
extends java.lang.Object
implements java.io.Serializable

An abstract class for access to vectors container. The container is really 2D array, which rows are vectors. The vectors are stored in row by row order. All access operations are implemented via RealPointer and RealVector.

See Also:
Serialized Form

Field Summary
 int dimension
          A dimension of every vector in the array.
 int size
          A number of vectors in the array.
 
Constructor Summary
protected RealVectors(int dimension, int size)
          Constructor.
 
Method Summary
abstract  double add(int i, int j, double value)
          Adds a value to j-th component of i-th vector and returns the result.
abstract  void assign(RealPointer vector, int i)
          Assignment vector = "this i-th vector".
abstract  BoundingBox boundingBox()
          Calculates a minimal bounding box containing the vectors array.
static RealVectors by(java.lang.Object obj, int dimension)
          Static service method that tests obj object to be float[] or double[] instance and creates corresponding RealVectors instance.
static RealVectors by(java.lang.Object obj, java.lang.Object ref, int dimension)
          Static service method that tests obj object to be float[] or double[] instance and ref object to be short[] or int[] instance and creates corresponding RealVectors instance referenced by ref object.
 void calculateCenter(RealPointer center)
          Calculates the mass center of the vectors set.
 void ensureDimension(int dimension)
          Tests a vectors' dimension to be not less that specified dimension and throws the IllegalArgumentException if not.
 void ensureSize(int size)
          Tests vectors' size to be not less that specified size and throws the IllegalArgumentException if not.
abstract  double get(int i, int j)
          Returns j-th componet of i-th vector.
abstract  RealVector getComponent(int j)
          Returns j-th component of all vectors as a RealVector.
abstract  RealPointer getPointer(int i)
          Returns a pointer to i-th vector (i is zero based index).
 RealPointers getPointers()
          Returns RealPointers object.
abstract  RealVector getVector(int i)
          Returns i-th data vector as a RealVector.
abstract  boolean inBox(int i, BoundingBox box)
          Tests i-th vector to belong to a bounding box.
abstract  double mul(int i, int j, double value)
          Multiplies the j-th component of i-th vector by a value and returns the result.
abstract  int offset(int i)
          Returns offset of i-th vector in the vectors container.
protected  int pos(int i)
          Calculates the position of i-th table row in the container.
abstract  double set(int i, int j, double value)
          Sets a value for j-th component of i-th vector and returns it.
abstract  double squaredDistance(int index1, RealPointer vec2)
          Calculates the squared euqlidian distance between a vector stored in this object and another vector presented by a real pointer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dimension

public final int dimension
A dimension of every vector in the array.

size

public final int size
A number of vectors in the array.
Constructor Detail

RealVectors

protected RealVectors(int dimension,
                      int size)
Constructor.
Parameters:
dimension - a vectors dimension
size - a number of vectors
Method Detail

get

public abstract double get(int i,
                           int j)
Returns j-th componet of i-th vector.

set

public abstract double set(int i,
                           int j,
                           double value)
Sets a value for j-th component of i-th vector and returns it.

add

public abstract double add(int i,
                           int j,
                           double value)
Adds a value to j-th component of i-th vector and returns the result.

mul

public abstract double mul(int i,
                           int j,
                           double value)
Multiplies the j-th component of i-th vector by a value and returns the result.

getComponent

public abstract RealVector getComponent(int j)
Returns j-th component of all vectors as a RealVector.

getVector

public abstract RealVector getVector(int i)
Returns i-th data vector as a RealVector.

boundingBox

public abstract BoundingBox boundingBox()
Calculates a minimal bounding box containing the vectors array.

inBox

public abstract boolean inBox(int i,
                              BoundingBox box)
Tests i-th vector to belong to a bounding box.
Parameters:
i - a vector's index
box - a bounding box for test
Returns:
true, if i-th vector belongs to the bounding box

getPointer

public abstract RealPointer getPointer(int i)
Returns a pointer to i-th vector (i is zero based index). To access to the vector components you have to move the pointer using next operation.

assign

public abstract void assign(RealPointer vector,
                            int i)
Assignment vector = "this i-th vector". Copies i-th vector of vectors array to the memory pointed by vector.
Parameters:
vector - a pointer to the vector
i - an index of copied vector in this object

getPointers

public final RealPointers getPointers()
Returns RealPointers object.

offset

public abstract int offset(int i)
Returns offset of i-th vector in the vectors container.

by

public static RealVectors by(java.lang.Object obj,
                             int dimension)
Static service method that tests obj object to be float[] or double[] instance and creates corresponding RealVectors instance.
Parameters:
obj - a vectors container (float[] or double[] instance)
dimension - a vector dimension

by

public static RealVectors by(java.lang.Object obj,
                             java.lang.Object ref,
                             int dimension)
Static service method that tests obj object to be float[] or double[] instance and ref object to be short[] or int[] instance and creates corresponding RealVectors instance referenced by ref object.
Parameters:
obj - a vectors container (float[] or double[])
ref - a reference vector (short[] or int[])
dimension - a vector dimension

ensureSize

public final void ensureSize(int size)
Tests vectors' size to be not less that specified size and throws the IllegalArgumentException if not.
Parameters:
size - a minimum size needed

ensureDimension

public final void ensureDimension(int dimension)
Tests a vectors' dimension to be not less that specified dimension and throws the IllegalArgumentException if not.
Parameters:
dimension - a minimum dimension needed

squaredDistance

public abstract double squaredDistance(int index1,
                                       RealPointer vec2)
Calculates the squared euqlidian distance between a vector stored in this object and another vector presented by a real pointer.
Parameters:
index1 - an index of the first vector in array
vec2 - a pointer to the second vector
Returns:
the squared euqlidian distance

calculateCenter

public final void calculateCenter(RealPointer center)
Calculates the mass center of the vectors set. Every coordinate of the mass center vector is calculated as a mean value of corresponding coordinate of vectors.
Parameters:
center - a pointer to the vector to store the result

pos

protected final int pos(int i)
Calculates the position of i-th table row in the container.