messif.objects.impl
Class ObjectFloatVector

java.lang.Object
  extended by messif.objects.UniqueID
      extended by messif.objects.AbstractObject
          extended by messif.objects.LocalAbstractObject
              extended by messif.objects.impl.ObjectFloatVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<UniqueID>, BinarySerializable, Clearable
Direct Known Subclasses:
ObjectFloatUnitVector, ObjectFloatVectorL1, ObjectFloatVectorL2

public abstract class ObjectFloatVector
extends LocalAbstractObject
implements BinarySerializable

This object uses static array of floats as its data content. No implementation of distance function is provided - see ObjectFloatVectorL1 or ObjectFloatVectorL2.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class messif.objects.LocalAbstractObject
LocalAbstractObject.DataEqualObject
 
Field Summary
protected  float[] data
          Data array
 
Fields inherited from class messif.objects.LocalAbstractObject
counterDistanceComputations, counterLowerBoundDistanceComputations, counterUpperBoundDistanceComputations, MAX_DISTANCE, MIN_DISTANCE, suppData, UNKNOWN_DISTANCE
 
Constructor Summary
protected ObjectFloatVector(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of ObjectFloatVector loaded from binary input buffer.
  ObjectFloatVector(java.io.BufferedReader stream)
          Creates a new instance of ObjectFloatVector from text stream.
  ObjectFloatVector(float[] data)
          Creates a new instance of ObjectFloatVector.
  ObjectFloatVector(int dimension, float min, float max)
          Creates a new instance of ObjectFloatVector with randomly generated content data.
 
Method Summary
 int binarySerialize(BinaryOutput output, BinarySerializator serializator)
          Binary-serialize this object into the output.
 LocalAbstractObject cloneRandomlyModify(java.lang.Object... args)
          Creates and returns a randomly modified copy of this vector.
 boolean dataEquals(java.lang.Object obj)
          Indicates whether some other object has the same data as this one.
 int dataHashCode()
          Returns a hash code value for the data of this object.
 int getBinarySize(BinarySerializator serializator)
          Returns the exact size of the binary-serialized version of this object in bytes.
 int getDimensionality()
          Returns the number of dimensions of this vector.
static float[][] getMinMaxForEveryCoord(AbstractObjectIterator<? extends ObjectFloatVector> iterator)
          Computes minimum and maximum values over every coordinate of vectors in the collection's iterator.
static float[] getMinMaxOverCoords(AbstractObjectIterator<? extends ObjectFloatVector> iterator)
          Computes minimum and maximum values over all coordinates of vectors in the collection's iterator.
protected  float[] getMinMaxOverCoords(float[] currRange)
          Computes minimum and maximum values over all coordinates of the current vector.
 int getSize()
          Returns the size of this object in bytes.
 float[] getVectorData()
          Returns the vector of float values, which represents the contents of this object.
 java.lang.String toString()
          Converts the object to a string representation.
 float[] translateToUnitCube(float[] bounds)
          Translates the current vector into a unit hypercube.
 float[] translateToUnitCube(float[][] bounds)
          Translates the current vector into a unit hypercube.
 void writeData(java.io.OutputStream stream)
          Store this object's data to a text stream.
 
Methods inherited from class messif.objects.LocalAbstractObject
clearSurplusData, clone, clone, create, create, createMetaDistancesHolder, excludeUsingPrecompDist, getDistance, getDistance, getDistance, getDistanceFilter, getDistanceFilter, getDistanceFilter, getDistanceImpl, getDistanceLowerBound, getDistanceLowerBoundImpl, getDistanceUpperBound, getDistanceUpperBoundImpl, getMaxDistance, getNormDistance, getRandomChar, getRandomNormal, chainDestroy, chainFilter, includeUsingPrecompDist, readObjectComments, unchainFilter, write, write
 
Methods inherited from class messif.objects.AbstractObject
clone, getLocatorURI, getNoDataObject, getObjectID, getObjectKey, setObjectKey
 
Methods inherited from class messif.objects.UniqueID
compareTo, equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected float[] data
Data array

Constructor Detail

ObjectFloatVector

public ObjectFloatVector(float[] data)
Creates a new instance of ObjectFloatVector.

Parameters:
data - the data content of the new object

ObjectFloatVector

public ObjectFloatVector(int dimension,
                         float min,
                         float max)
Creates a new instance of ObjectFloatVector with randomly generated content data. Content will be generated using normal distribution of random numbers from interval [min;max).

Parameters:
dimension - number of dimensions to generate
min - lower bound of the random generated values (inclusive)
max - upper bound of the random generated values (exclusive)

ObjectFloatVector

public ObjectFloatVector(java.io.BufferedReader stream)
                  throws java.io.EOFException,
                         java.io.IOException,
                         java.lang.NumberFormatException
Creates a new instance of ObjectFloatVector from text stream.

Parameters:
stream - the stream from which to read lines of text
Throws:
java.io.EOFException - if the end-of-file of the given stream is reached
java.io.IOException - if there was an I/O error during reading from the stream
java.lang.NumberFormatException - if a line read from the stream does not consist of comma-separated or space-separated numbers

ObjectFloatVector

protected ObjectFloatVector(BinaryInput input,
                            BinarySerializator serializator)
                     throws java.io.IOException
Creates a new instance of ObjectFloatVector loaded from binary input buffer.

Parameters:
input - the buffer to read the ObjectFloatVector from
serializator - the serializator used to write objects
Throws:
java.io.IOException - if there was an I/O error reading from the buffer
Method Detail

writeData

public void writeData(java.io.OutputStream stream)
               throws java.io.IOException
Description copied from class: LocalAbstractObject
Store this object's data to a text stream. This method should have the opposite deserialization in constructor of a given object class.

Specified by:
writeData in class LocalAbstractObject
Parameters:
stream - the stream to store this object to
Throws:
java.io.IOException - if there was an error while writing to stream

dataEquals

public boolean dataEquals(java.lang.Object obj)
Description copied from class: LocalAbstractObject
Indicates whether some other object has the same data as this one.

Specified by:
dataEquals in class LocalAbstractObject
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

dataHashCode

public int dataHashCode()
Description copied from class: LocalAbstractObject
Returns a hash code value for the data of this object.

Specified by:
dataHashCode in class LocalAbstractObject
Returns:
a hash code value for the data of this object

getVectorData

public float[] getVectorData()
Returns the vector of float values, which represents the contents of this object. A copy is returned, so any modifications to the returned array do not affect the original object.

Returns:
the data contents of this object

getSize

public int getSize()
Description copied from class: LocalAbstractObject
Returns the size of this object in bytes.

Specified by:
getSize in class LocalAbstractObject
Returns:
the size of this object in bytes

getDimensionality

public int getDimensionality()
Returns the number of dimensions of this vector.

Returns:
the number of dimensions of this vector

translateToUnitCube

public float[] translateToUnitCube(float[][] bounds)
Translates the current vector into a unit hypercube. This translation requires minimum and maximum per coordinate to be passed in an array. The method which provides such values is getMinMaxForEveryCoord().

Parameters:
bounds - A 2-dimensional array of minimum and maximum values per coordinate. For details refer to getMinMaxForEveryCoord().
Returns:
A new vector (array of floats) is returned which represents current vector transformed to the unit cube.

translateToUnitCube

public float[] translateToUnitCube(float[] bounds)
Translates the current vector into a unit hypercube. This translation requires minimum and maximum computed over all coordinates to be passed. The method which provides such values is getMinMaxOverCoords().

Parameters:
bounds - Array consisting of two values for minimum and maximum value of all coordinates, respectively.
Returns:
A new vector (array of floats) is returned which represents current vector transformed to the unit cube.

getMinMaxOverCoords

protected float[] getMinMaxOverCoords(float[] currRange)
Computes minimum and maximum values over all coordinates of the current vector.

Parameters:
currRange - An optional parameter containing current minimum and maximum values. If null is passed a new range with minimum and maximum is created, otherwise the passed array is updated.
Returns:
Returns an array of two float values for the minimum and the maximum, respectively.

getMinMaxOverCoords

public static float[] getMinMaxOverCoords(AbstractObjectIterator<? extends ObjectFloatVector> iterator)
Computes minimum and maximum values over all coordinates of vectors in the collection's iterator.

Parameters:
iterator - Iterator of a collection containing vectors to process.
Returns:
Returns an array of two float values for the minimum and the maximum per all coordinates, respectively.

getMinMaxForEveryCoord

public static float[][] getMinMaxForEveryCoord(AbstractObjectIterator<? extends ObjectFloatVector> iterator)
Computes minimum and maximum values over every coordinate of vectors in the collection's iterator.

Parameters:
iterator - Iterator of a collection containing vectors to process.
Returns:
Returns a 2-dimensional array of float values. The first dimension distiguishes between minimum and maximum values. Index [0] contains an array of floats which represent minimum values of individual coordinates over all vectors. Index [0] contains a respective array of maximum values. This return value can be directly passed to translateToUnitCube() method.

cloneRandomlyModify

public LocalAbstractObject cloneRandomlyModify(java.lang.Object... args)
                                        throws java.lang.CloneNotSupportedException
Creates and returns a randomly modified copy of this vector. Selects a vector position in random and changes it - the final value stays in the given range. The modification is small - only by (max-min)/1000

Overrides:
cloneRandomlyModify in class LocalAbstractObject
Parameters:
args - expected size of the array is 2: minVector vector with minimal values in all positions maxVector vector with maximal values in all positions
Returns:
a randomly modified clone of this instance.
Throws:
java.lang.CloneNotSupportedException - if the object's class does not support clonning or there was an error

toString

public java.lang.String toString()
Converts the object to a string representation. The format is the comma-separated list of coordinates enclosed in square brackets and the result of super.toString() is appended.

Overrides:
toString in class AbstractObject
Returns:
a string representation of this abstract object

binarySerialize

public int binarySerialize(BinaryOutput output,
                           BinarySerializator serializator)
                    throws java.io.IOException
Description copied from class: LocalAbstractObject
Binary-serialize this object into the output.

Specified by:
binarySerialize in interface BinarySerializable
Overrides:
binarySerialize in class LocalAbstractObject
Parameters:
output - the output that this object is binary-serialized into
serializator - the serializator used to write objects
Returns:
the number of bytes actually written
Throws:
java.io.IOException - if there was an I/O error during serialization

getBinarySize

public int getBinarySize(BinarySerializator serializator)
Description copied from class: LocalAbstractObject
Returns the exact size of the binary-serialized version of this object in bytes.

Specified by:
getBinarySize in interface BinarySerializable
Overrides:
getBinarySize in class LocalAbstractObject
Parameters:
serializator - the serializator used to write objects
Returns:
size of the binary-serialized version of this object