ru.sscc.util.data
Class RealVector

java.lang.Object
  |
  +--ru.sscc.util.data.RealVector
Direct Known Subclasses:
ChainVector, DoubleIRefVector, DoubleIVecVector, DoubleSRefVector, DoubleSVecVector, DoubleVector, FloatIRefVector, FloatIVecVector, FloatSRefVector, FloatSVecVector, FloatVector

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

An abstract implementation of a real data vector distributed within a real data container by the regular manner (for example, with the fixed distance between neighbouring entries). The vector entries are accessed via a zero based index. An imlementation of this class must allow an index to be out of the vector bounds if the corresponding entry in the container exists. Methods for the assignment, the calculation of vector sum, inner product, and various vector norms are implemented.

See Also:
Serialized Form

Field Summary
protected  int index
          The starting index of the vector entry in the container.
 int length
          A length of the vector (a number of its entries).
protected  int step
          The vector's increment step.
 
Constructor Summary
protected RealVector(int length, int index, int step)
          Constructor.
 
Method Summary
abstract  double add(int index, double value)
          Adds the value to the vector entry.
 void addVector(RealVector vec, double factor)
          Adds RealVector vector multiplied by factor.
 void addVector(RealVector vec, double factor, int count)
          Adds count values from the RealVector vector multiplied by factor.
 void assign(double value)
          Assigns a value to the vector.
 void assign(double value, int count)
          Assigns a value to the first count entries of the vector.
 void assign(RealVector vec)
          Assigns values from RealVector vector.
 void assign(RealVector vec, double factor)
          Assigns RealVector vector multiplied by a factor.
 void assign(RealVector vec, double factor, int count)
          Assigns count values of RealVector vector multiplied by a factor.
 void assign(RealVector vec, int count)
          Assigns count values from RealVector vector.
static RealVector by(java.lang.Object obj)
          Static service method which creates RealVector upon an object convertable to it (double[], float[], RealContainer, or RealVector instance).
static RealVector by(java.lang.Object obj, java.lang.Object ref)
          Static service method which tests obj object to be float[] or double[] instance and ref object to be short[] or int[] instance and creates RealVector based on all container entries referenced by ref object.
 void ensureLength(int length)
          Tests a vector length to be not less that specified length and throws the IllegalArgumentException if not.
abstract  double get(int index)
          Gets the value of a vector entry.
abstract  RealPointer getPointer()
          Gets a pointer to the beginning of the real data vector with the unit increment.
 RealPointer getPointer(int index, int step)
          Gets a pointer and resets it for the sequential access to vector entries starting from the index position with the step increment.
protected  int inc(int s)
          Calculates a complete increment step in a subvector as a product of the vector's and subvector's increments.
 int indexOfNormMax()
          Calculates the index of the first vector's entry having the maximum module.
 int indexOfNormMax(int count)
          Calculates the index of the first vector's entry having the maximum module between the first count vector entries.
 double innerProduct(RealVector vec)
          Calculates an inner product of the vector by another RealVector vector.
 double innerProduct(RealVector vec, int count)
          Calculates an inner product of first count entries the vector by another RealVector vector.
abstract  double mul(int index, double value)
          Multiplies the vector entry by the value.
 void multiply(double value)
          Multiplies the vector by a value.
 void multiply(double value, int count)
          Multiplies the first count entries of the vector by a value.
 double norm()
          Calculates the euqlidian norm of the vector.
 double norm(int count)
          Calculates the euqlidian norm of the first count vector entries.
 double normMax()
          Calculates the maximum modules norm.
 double normMax(int count)
          Calculates the max-norm of the first count vector entries.
 double normSum()
          Calculates a sum of modules norm.
 double normSum(int count)
          Calculates the sum-norm of the first count vector entries.
protected  int pos(int i)
          Calculates the complete index of a vector entry in the container by its index in the vector.
abstract  double set(int index, double value)
          Sets the value of a vector entry.
abstract  RealVector subvector(int index, int step, int length)
          Creates a subvector within the real data vector.
 void swap(int i, int j)
          Swaps i-th and j-th vector's values without testing of indices correctness.
 double weightedNorm(RealVector weight)
          Calculates the weighted euqlidian norm of the vector (if the weight vector is null, the calculated norm will be unweighted).
 double weightedNorm(RealVector weight, int count)
          Calculates the weighted euqlidian norm of the first count entries of the vector (if the weight vector is null, the calculated norm will be unweighted).
 double weightedNormMax(RealVector weight)
          Calculates the weighted maximum modules norm (if the weight vector is null, the calculated norm will be unweighted).
 double weightedNormMax(RealVector weight, int count)
          Calculates the weighted max-norm of the first count vector entries (if the weight vector is null, the calculated norm will be unweighted).
 double weightedNormSum(RealVector weight)
          Calculates a weighted sum of modules norm (if the weight vector is null, the calculated norm will be unweighted).
 double weightedNormSum(RealVector weight, int count)
          Calculates the weighted sum-norm of the first count vector entries (if the weight vector is null, the calculated norm will be unweighted).
 double weightedProduct(RealVector vec, RealVector weight)
          Calculates a weighted inner product of the vector by another RealVector vector (if a weight vector is null, the calculated inner product will be unweighted).
 double weightedProduct(RealVector vec, RealVector weight, int count)
          Calculates a weighted inner product of the first count entries of the vector by another RealVector vector (if a weight vector is null, the calculated inner product will be unweighted).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

length

public final int length
A length of the vector (a number of its entries).

index

protected int index
The starting index of the vector entry in the container.

step

protected final int step
The vector's increment step.
Constructor Detail

RealVector

protected RealVector(int length,
                     int index,
                     int step)
Constructor.
Parameters:
length - a vector length (a number of entries)
index - a first vector entry index
step - an increment step
Method Detail

get

public abstract double get(int index)
Gets the value of a vector entry.
Parameters:
index - an entry position in the vector
Returns:
an entry value at the required position

set

public abstract double set(int index,
                           double value)
Sets the value of a vector entry.
Parameters:
index - an entry position in the vector
value - a value to set
Returns:
the set value

add

public abstract double add(int index,
                           double value)
Adds the value to the vector entry.
Parameters:
index - the entry position in the container
value - the value to add
Returns:
the result of addition

mul

public abstract double mul(int index,
                           double value)
Multiplies the vector entry by the value.
Parameters:
index - the entry position in the container
value - the value to multiply
Returns:
the result of multiplication

getPointer

public abstract RealPointer getPointer()
Gets a pointer to the beginning of the real data vector with the unit increment.

getPointer

public final RealPointer getPointer(int index,
                                    int step)
Gets a pointer and resets it for the sequential access to vector entries starting from the index position with the step increment.
Parameters:
index - a starting index in the vector
step - an increment step in the vector

subvector

public abstract RealVector subvector(int index,
                                     int step,
                                     int length)
Creates a subvector within the real data vector.
Parameters:
index - a starting index in the vector
step - an increment step in the vector
length - a length of the subvector

by

public static RealVector by(java.lang.Object obj)
Static service method which creates RealVector upon an object convertable to it (double[], float[], RealContainer, or RealVector instance). In the last case the same object will be returned.

by

public static RealVector by(java.lang.Object obj,
                            java.lang.Object ref)
Static service method which tests obj object to be float[] or double[] instance and ref object to be short[] or int[] instance and creates RealVector based on all container entries referenced by ref object.
Parameters:
obj - a data container (float[] or double[] instance)
ref - a reference vector (short[] or int[] instance)

ensureLength

public final void ensureLength(int length)
Tests a vector length to be not less that specified length and throws the IllegalArgumentException if not.
Parameters:
length - a minimum length needed

swap

public final void swap(int i,
                       int j)
Swaps i-th and j-th vector's values without testing of indices correctness.

assign

public final void assign(double value)
Assigns a value to the vector.
Parameters:
value - a value to assign

assign

public final void assign(double value,
                         int count)
Assigns a value to the first count entries of the vector.
Parameters:
value - a value to assign
count - a number of entries to assign

assign

public final void assign(RealVector vec)
Assigns values from RealVector vector.
Parameters:
vec - source vector

assign

public final void assign(RealVector vec,
                         int count)
Assigns count values from RealVector vector.
Parameters:
vec - source vector
count - a number of entries to assign

assign

public final void assign(RealVector vec,
                         double factor)
Assigns RealVector vector multiplied by a factor.
Parameters:
vec - a source vector
factor - a value to multiply

assign

public final void assign(RealVector vec,
                         double factor,
                         int count)
Assigns count values of RealVector vector multiplied by a factor.
Parameters:
vec - a source vector
factor - a value to multiply
count - a number of entries to assign

addVector

public final void addVector(RealVector vec,
                            double factor)
Adds RealVector vector multiplied by factor.
Parameters:
vec - a vector to be added
factor - a multiplier

addVector

public final void addVector(RealVector vec,
                            double factor,
                            int count)
Adds count values from the RealVector vector multiplied by factor.
Parameters:
vec - a vector to be added
factor - a multiplier
count - a number of entries to add

multiply

public final void multiply(double value)
Multiplies the vector by a value.
Parameters:
value - a value to multiply

multiply

public final void multiply(double value,
                           int count)
Multiplies the first count entries of the vector by a value.
Parameters:
value - a value to multiply
count - a number of entries to multiply

innerProduct

public final double innerProduct(RealVector vec)
Calculates an inner product of the vector by another RealVector vector.
Parameters:
vec - a vector to multiply
Returns:
the inner product by the vector

innerProduct

public final double innerProduct(RealVector vec,
                                 int count)
Calculates an inner product of first count entries the vector by another RealVector vector.
Parameters:
vec - a vector to multiply
count - a number of entries
Returns:
the inner product by the vector

weightedProduct

public final double weightedProduct(RealVector vec,
                                    RealVector weight)
Calculates a weighted inner product of the vector by another RealVector vector (if a weight vector is null, the calculated inner product will be unweighted).
Parameters:
vec - a vector to multiply
weight - a weight vector
Returns:
the weighted inner product by the vector

weightedProduct

public final double weightedProduct(RealVector vec,
                                    RealVector weight,
                                    int count)
Calculates a weighted inner product of the first count entries of the vector by another RealVector vector (if a weight vector is null, the calculated inner product will be unweighted).
Parameters:
vec - a vector to multiply
weight - a weight vector
count - a number of entries
Returns:
the weighted inner product by the vector

norm

public final double norm()
Calculates the euqlidian norm of the vector.
Returns:
the euqlidian norm

norm

public final double norm(int count)
Calculates the euqlidian norm of the first count vector entries.
Parameters:
count - the number of entries
Returns:
the euqlidian norm

normMax

public final double normMax()
Calculates the maximum modules norm.
Returns:
the max-norm

normMax

public final double normMax(int count)
Calculates the max-norm of the first count vector entries.
Parameters:
count - the number of entries
Returns:
the max-norm

normSum

public final double normSum()
Calculates a sum of modules norm.
Returns:
the sum-norm

normSum

public final double normSum(int count)
Calculates the sum-norm of the first count vector entries.
Parameters:
count - the number of entries
Returns:
the sum-norm

indexOfNormMax

public final int indexOfNormMax()
Calculates the index of the first vector's entry having the maximum module. If vector length is nonpositive, (-1) is returned.
Returns:
the index of entry having the maximum module

indexOfNormMax

public final int indexOfNormMax(int count)
Calculates the index of the first vector's entry having the maximum module between the first count vector entries. If the count is nonpositive, (-1) is returned.
Parameters:
count - the number of entries
Returns:
the index of entry having the maximum module

weightedNorm

public final double weightedNorm(RealVector weight)
Calculates the weighted euqlidian norm of the vector (if the weight vector is null, the calculated norm will be unweighted).
Parameters:
weight - the weight vector
Returns:
the weighted euqlidian norm

weightedNorm

public final double weightedNorm(RealVector weight,
                                 int count)
Calculates the weighted euqlidian norm of the first count entries of the vector (if the weight vector is null, the calculated norm will be unweighted).
Parameters:
weight - the weight vector
count - the number of entries
Returns:
the weighted euqlidian norm

weightedNormMax

public final double weightedNormMax(RealVector weight)
Calculates the weighted maximum modules norm (if the weight vector is null, the calculated norm will be unweighted).
Parameters:
weight - the weight vector
Returns:
the weighted max-norm

weightedNormMax

public final double weightedNormMax(RealVector weight,
                                    int count)
Calculates the weighted max-norm of the first count vector entries (if the weight vector is null, the calculated norm will be unweighted).
Parameters:
weight - the weight vector
count - the number of entries
Returns:
the weighted max-norm

weightedNormSum

public final double weightedNormSum(RealVector weight)
Calculates a weighted sum of modules norm (if the weight vector is null, the calculated norm will be unweighted).
Parameters:
weight - the weight vector
Returns:
the weighted sum-norm

weightedNormSum

public final double weightedNormSum(RealVector weight,
                                    int count)
Calculates the weighted sum-norm of the first count vector entries (if the weight vector is null, the calculated norm will be unweighted).
Parameters:
weight - the weight vector
count - the number of entries
Returns:
the sum-norm

inc

protected final int inc(int s)
Calculates a complete increment step in a subvector as a product of the vector's and subvector's increments.
Parameters:
s - an increment step in the subvector
Returns:
the complete increment step

pos

protected final int pos(int i)
Calculates the complete index of a vector entry in the container by its index in the vector.
Parameters:
i - an entry index in the vector
Returns:
the corresponding entry index in the container