gov.sandia.cognition.math.matrix
Class VectorFactory<VectorType extends Vector>

java.lang.Object
  extended by gov.sandia.cognition.math.matrix.VectorFactory<VectorType>
Type Parameters:
VectorType - Type of Vector created by this factory.
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DenseVectorFactoryMTJ, SparseVectorFactory

public abstract class VectorFactory<VectorType extends Vector>
extends Object
implements Serializable

Abstract factory for creating Vector objects.

Since:
1.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Field Summary
protected static VectorFactory<? extends Vector> DEFAULT_DENSE_INSTANCE
          The default VectorFactory instance.
protected static SparseVectorFactory<? extends Vector> DEFAULT_SPARSE_INSTANCE
          The default SparseVectorFactory instance.
 
Constructor Summary
protected VectorFactory()
          Creates a new VectorFactory.
 
Method Summary
 VectorType copyArray(double[] values)
          Copies the values from the array into the Vector
 VectorType copyArray(int dimensionality, int[] indices, double[] values)
          Creates a new vector of the given dimensionality by setting the values at the given indices.
 VectorType copyValues(Collection<? extends Number> values)
          Copies the values from the given Collection
 VectorType copyValues(double... values)
          Copies the values from the given doubles into a Vector
abstract  VectorType copyVector(Vector m)
          Creates a deep copy new Vector given another, argument is unchanged
 VectorType createUniformRandom(int dim, double min, double max, Random random)
          Creates a Vector with random values for the entries, uniformly distributed between "min" and "max"
abstract  VectorType createVector(int dim)
          Creates an empty Vector of the specified dimension, all elements must be all zeros!
 VectorType createVector(int dimensionality, double initialValue)
          Creates a Vector with the given initial value for all elements.
 Vector1D createVector1D()
          Creates a one-dimensional zero vector: (0.0).
abstract  Vector1D createVector1D(double x)
          Creates a one-dimensional vector with the given x coordinate: (x).
 Vector2D createVector2D()
          Creates a two-dimensional zero vector: (0.0, 0.0).
abstract  Vector2D createVector2D(double x, double y)
          Creates a two-dimensional vector with the given x and y coordinates: (x, y).
 Vector3D createVector3D()
          Creates a three-dimensional zero vector: (0.0, 0.0, 0.0).
abstract  Vector3D createVector3D(double x, double y, double z)
          Creates a three-dimensional vector with the given x, y, and z coordinates: (x, y, z).
static VectorFactory<? extends Vector> getDefault()
          Gets the default implementation of the VectorFactory.
static VectorFactory<? extends Vector> getDenseDefault()
          Gets the default implementation of VectorFactory for dense vectors.
static SparseVectorFactory<? extends Vector> getSparseDefault()
          Gets the default implementation of the SparseVectorFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DENSE_INSTANCE

protected static final VectorFactory<? extends Vector> DEFAULT_DENSE_INSTANCE
The default VectorFactory instance.


DEFAULT_SPARSE_INSTANCE

protected static final SparseVectorFactory<? extends Vector> DEFAULT_SPARSE_INSTANCE
The default SparseVectorFactory instance.

Constructor Detail

VectorFactory

protected VectorFactory()
Creates a new VectorFactory.

Method Detail

getDefault

public static VectorFactory<? extends Vector> getDefault()
Gets the default implementation of the VectorFactory.

Returns:
The default VectorFactory implementation.

getDenseDefault

public static VectorFactory<? extends Vector> getDenseDefault()
Gets the default implementation of VectorFactory for dense vectors.

Returns:
The default dense vector factory;

getSparseDefault

public static SparseVectorFactory<? extends Vector> getSparseDefault()
Gets the default implementation of the SparseVectorFactory.

Returns:
The default SparseVectorFactory implementation.

copyVector

public abstract VectorType copyVector(Vector m)
Creates a deep copy new Vector given another, argument is unchanged

Parameters:
m - Vector to copy
Returns:
Deep copy of the given Vector

copyArray

public VectorType copyArray(double[] values)
Copies the values from the array into the Vector

Parameters:
values - Values to copy
Returns:
Vector with same dimension and values as "values"

copyValues

public VectorType copyValues(double... values)
Copies the values from the given doubles into a Vector

Parameters:
values - Values to copy
Returns:
Vector with same dimension and values as "values"

copyValues

public VectorType copyValues(Collection<? extends Number> values)
Copies the values from the given Collection

Parameters:
values - Values to copy
Returns:
Vector with the same dimension and values as "values" has size.

createVector

public abstract VectorType createVector(int dim)
Creates an empty Vector of the specified dimension, all elements must be all zeros!

Parameters:
dim - number of elements in the Vector
Returns:
A new Vector or the given dimensionality with all zero elements.

createVector1D

public Vector1D createVector1D()
Creates a one-dimensional zero vector: (0.0).

Returns:
A one-dimensional zero vector.

createVector1D

public abstract Vector1D createVector1D(double x)
Creates a one-dimensional vector with the given x coordinate: (x). This is useful mainly for creating a vector wrapper for the double.

Parameters:
x - The x coordinate.
Returns:
A new one-dimensional vector with the given coordinate.

createVector2D

public Vector2D createVector2D()
Creates a two-dimensional zero vector: (0.0, 0.0).

Returns:
A two-dimensional zero vector.

createVector2D

public abstract Vector2D createVector2D(double x,
                                        double y)
Creates a two-dimensional vector with the given x and y coordinates: (x, y).

Parameters:
x - The x coordinate.
y - The y coordinate.
Returns:
A new two-dimensional vector with the given coordinates.

createVector3D

public Vector3D createVector3D()
Creates a three-dimensional zero vector: (0.0, 0.0, 0.0).

Returns:
A three-dimensional zero vector.

createVector3D

public abstract Vector3D createVector3D(double x,
                                        double y,
                                        double z)
Creates a three-dimensional vector with the given x, y, and z coordinates: (x, y, z).

Parameters:
x - The x coordinate.
y - The y coordinate.
z - The z coordinate.
Returns:
A new three-dimensional vector with the given coordinates.

createUniformRandom

public VectorType createUniformRandom(int dim,
                                      double min,
                                      double max,
                                      Random random)
Creates a Vector with random values for the entries, uniformly distributed between "min" and "max"

Parameters:
dim - number of elements in the Vector
min - minimum range of the uniform distribution
max - maximum range of the uniform distribution
random - The random number generator.
Returns:
Vector with random values for the entries, uniformly distributed between "min" and "max"

createVector

public VectorType createVector(int dimensionality,
                               double initialValue)
Creates a Vector with the given initial value for all elements.

Parameters:
dimensionality - The number of elements for the vector.
initialValue - Initial value to set all elements to
Returns:
Vector of the given dimensions, with all value equal to initialValue

copyArray

public VectorType copyArray(int dimensionality,
                            int[] indices,
                            double[] values)
Creates a new vector of the given dimensionality by setting the values at the given indices.

Parameters:
dimensionality - The dimensionality of the vector to create.
indices - The array of indices of values to set. Must be the same length as the values array. The indices must be between 0 and the dimensionality - 1.
values - The array of values to set. Must be the same length as the indices array.
Returns:
A new vector with the given indices set to their corresponding values.