gov.sandia.cognition.framework.learning.converter
Class CogxelVectorConverter

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.math.matrix.DefaultVectorFactoryContainer
          extended by gov.sandia.cognition.framework.learning.converter.CogxelVectorConverter
All Implemented Interfaces:
CogxelConverter<Vector>, VectorFactoryContainer, CloneableSerializable, Serializable, Cloneable

public class CogxelVectorConverter
extends DefaultVectorFactoryContainer
implements CogxelConverter<Vector>

The CogxelVectorConverter implements a converter to convert Cogxels to and from Vector objects.

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

Field Summary
 
Fields inherited from class gov.sandia.cognition.math.matrix.DefaultVectorFactoryContainer
vectorFactory
 
Constructor Summary
CogxelVectorConverter()
          Creates a new, empty instance of VectorCogxelMap.
CogxelVectorConverter(CogxelVectorConverter other)
          Creates a new copy of the given CogxelVectorConverter.
CogxelVectorConverter(Iterable<SemanticLabel> labels)
          Creates a new CogxelVectorConverter from the given labels.
CogxelVectorConverter(Iterable<SemanticLabel> labels, SemanticIdentifierMap semanticIdentifierMap)
          Creates a new CogxelVectorConverter from the given SemanticIdentifierMap and SemanticLabels.
CogxelVectorConverter(Iterable<SemanticLabel> labels, SemanticIdentifierMap semanticIdentifierMap, VectorFactory<?> vectorFactory, CogxelFactory cogxelFactory)
          Creates a new CogxelVectorConverter.
CogxelVectorConverter(SemanticLabel... labels)
          Creates a new CogxelVectorConverter from the given labels.
CogxelVectorConverter(SemanticLabel[] labels, SemanticIdentifierMap semanticIdentifierMap)
          Creates a new CogxelVectorConverter from the given SemanticIdentifierMap and SemanticLabels.
CogxelVectorConverter(SemanticLabel[] labels, SemanticIdentifierMap semanticIdentifierMap, VectorFactory<?> vectorFactory, CogxelFactory cogxelFactory)
          Creates a new CogxelVectorConverter
 
Method Summary
 void addLabel(SemanticLabel label)
          Adds the given SemanticLabel to the list of labels used by the converter.
 void addLabels(Iterable<SemanticLabel> labels)
          Adds all of the given labels to the converter.
 void addLabels(SemanticLabel[] labels)
          Adds all of the given labels to the converter.
protected  void addLabelToIdentifierCache(SemanticLabel label)
          Adds the given label to the cache of SemanticIdentifiers.
protected  void buildIdentifierCache()
          Rebuilds the cache of SemanticIdentifier objects.
 CogxelVectorConverter clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 Vector createEmptyVector()
          Creates an empty Vector for the converter, of the proper dimensionality.
 boolean equals(CogxelVectorConverter other)
          Returns true if the two converters have the same labels.
 boolean equals(Object other)
          
protected  int findIndexForIdentifier(SemanticIdentifier identifier)
          Finds the vector index for the given SemanticIdentifier.
 Vector fromCogxels(CogxelState cogxels)
          Converts from a CogxelState object to an object of type DataType.
 CogxelFactory getCogxelFactory()
          Gets the CogxelFactory used to create the Cogxels used by the converter.
 int getDimensionality()
          Gets the dimensionality of the Vector created by the converter.
protected  ArrayList<SemanticIdentifier> getIdentifiers()
          Gets the list of cached SemanticIdentifiers.
protected  HashMap<SemanticIdentifier,Integer> getIdentifierToIndexMap()
          Gets the cached mapping of SemanticIdentifier to vector index.
 ArrayList<SemanticLabel> getLabels()
          Gets the labels used by the converter, each one corresponding to one dimension in the converted Vector.
 SemanticIdentifierMap getSemanticIdentifierMap()
          Gets the SemanticIdentifierMap used by this converter.
 int hashCode()
           
 void setCogxelFactory(CogxelFactory cogxelFactory)
          Gets the CogxelFactory used to create the Cogxels used by the converter.
protected  void setIdentifiers(ArrayList<SemanticIdentifier> identifiers)
          Sets the list of cached SemanticIdentifiers.
protected  void setIdentifierToIndexMap(HashMap<SemanticIdentifier,Integer> identifierToIndexMap)
          Sets the cached mapping of SemanticIdentifier to vector index.
 void setLabels(ArrayList<SemanticLabel> labels)
          Sets the labels to be used by the converter, each one corresponding to one dimension in the converted Vector.
 void setSemanticIdentifierMap(SemanticIdentifierMap semanticIdentifierMap)
          Sets the SemanticIdentifierMap that the converter is to use.
 void toCogxels(Vector data, CogxelState cogxels)
          Converts from an object of type DataType to an updated CogxelState.
 
Methods inherited from class gov.sandia.cognition.math.matrix.DefaultVectorFactoryContainer
getVectorFactory, setVectorFactory
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CogxelVectorConverter

public CogxelVectorConverter()
Creates a new, empty instance of VectorCogxelMap.


CogxelVectorConverter

public CogxelVectorConverter(SemanticLabel... labels)
Creates a new CogxelVectorConverter from the given labels.

Parameters:
labels - The labels to use.

CogxelVectorConverter

public CogxelVectorConverter(Iterable<SemanticLabel> labels)
Creates a new CogxelVectorConverter from the given labels.

Parameters:
labels - The labels to use.

CogxelVectorConverter

public CogxelVectorConverter(SemanticLabel[] labels,
                             SemanticIdentifierMap semanticIdentifierMap)
Creates a new CogxelVectorConverter from the given SemanticIdentifierMap and SemanticLabels.

Parameters:
labels - The labels to use.
semanticIdentifierMap - The SemanticIdentifierMap to use.

CogxelVectorConverter

public CogxelVectorConverter(Iterable<SemanticLabel> labels,
                             SemanticIdentifierMap semanticIdentifierMap)
Creates a new CogxelVectorConverter from the given SemanticIdentifierMap and SemanticLabels.

Parameters:
labels - The labels to use.
semanticIdentifierMap - The SemanticIdentifierMap to use.

CogxelVectorConverter

public CogxelVectorConverter(SemanticLabel[] labels,
                             SemanticIdentifierMap semanticIdentifierMap,
                             VectorFactory<?> vectorFactory,
                             CogxelFactory cogxelFactory)
Creates a new CogxelVectorConverter

Parameters:
labels - The labels to use.
semanticIdentifierMap - The SemanticIdentifierMap to use.
vectorFactory - The VectorFactory to use.
cogxelFactory - The CogxelFactory to use.

CogxelVectorConverter

public CogxelVectorConverter(Iterable<SemanticLabel> labels,
                             SemanticIdentifierMap semanticIdentifierMap,
                             VectorFactory<?> vectorFactory,
                             CogxelFactory cogxelFactory)
Creates a new CogxelVectorConverter.

Parameters:
labels - The labels to use.
semanticIdentifierMap - The SemanticIdentifierMap to use.
vectorFactory - The VectorFactory to use.
cogxelFactory - The CogxelFactory to use.

CogxelVectorConverter

public CogxelVectorConverter(CogxelVectorConverter other)
Creates a new copy of the given CogxelVectorConverter.

Parameters:
other - The CogxeLVectorConverter to copy.
Method Detail

clone

public CogxelVectorConverter clone()
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CogxelConverter<Vector>
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

addLabel

public void addLabel(SemanticLabel label)
Adds the given SemanticLabel to the list of labels used by the converter.

Parameters:
label - The label to add.

addLabels

public void addLabels(Iterable<SemanticLabel> labels)
Adds all of the given labels to the converter.

Parameters:
labels - The labels to add to the converter.

addLabels

public void addLabels(SemanticLabel[] labels)
Adds all of the given labels to the converter.

Parameters:
labels - The labels to add to the converter.

buildIdentifierCache

protected void buildIdentifierCache()
Rebuilds the cache of SemanticIdentifier objects. Should only need to be called after the SemanticIdentifierMap is changed.


addLabelToIdentifierCache

protected void addLabelToIdentifierCache(SemanticLabel label)
Adds the given label to the cache of SemanticIdentifiers. This is used so that the fast SemanticIdentifiers can be used by the converter instead of the SemanticLabel.

Parameters:
label - The label to add.

fromCogxels

public Vector fromCogxels(CogxelState cogxels)
Converts from a CogxelState object to an object of type DataType.

Specified by:
fromCogxels in interface CogxelConverter<Vector>
Parameters:
cogxels - The CogxelState to convert to DataType.
Returns:
An object of DataType extracted from the given CogxelState.

toCogxels

public void toCogxels(Vector data,
                      CogxelState cogxels)
Converts from an object of type DataType to an updated CogxelState.

Specified by:
toCogxels in interface CogxelConverter<Vector>
Parameters:
data - The object to convert into the CogxelState.
cogxels - The CogxelState to update with the converted data.

findIndexForIdentifier

protected int findIndexForIdentifier(SemanticIdentifier identifier)
Finds the vector index for the given SemanticIdentifier.

Parameters:
identifier - The SemanticIdentifier to find the integer index for.
Returns:
The integer index for the given SemanticIdentifier, if it is an identifier this converter is using; otherwise, -1.

equals

public boolean equals(Object other)

Overrides:
equals in class Object
Parameters:
other -
Returns:

equals

public boolean equals(CogxelVectorConverter other)
Returns true if the two converters have the same labels.

Parameters:
other - Another CogxelVectorConverter.
Returns:
True if the two converters have the same labels.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

createEmptyVector

public Vector createEmptyVector()
Creates an empty Vector for the converter, of the proper dimensionality.

Returns:
An empty Vector for the converter to use.

getDimensionality

public int getDimensionality()
Gets the dimensionality of the Vector created by the converter.

Returns:
The dimensionality of the Vector created by the converter.

getSemanticIdentifierMap

public SemanticIdentifierMap getSemanticIdentifierMap()
Gets the SemanticIdentifierMap used by this converter.

Specified by:
getSemanticIdentifierMap in interface CogxelConverter<Vector>
Returns:
The SemanticIdentifierMap used by this converter.

setSemanticIdentifierMap

public void setSemanticIdentifierMap(SemanticIdentifierMap semanticIdentifierMap)
Sets the SemanticIdentifierMap that the converter is to use.

Specified by:
setSemanticIdentifierMap in interface CogxelConverter<Vector>
Parameters:
semanticIdentifierMap - The SemanticIdentifierMap the converter is to use.

getLabels

public ArrayList<SemanticLabel> getLabels()
Gets the labels used by the converter, each one corresponding to one dimension in the converted Vector.

Returns:
The labels used by the converter.

setLabels

public void setLabels(ArrayList<SemanticLabel> labels)
Sets the labels to be used by the converter, each one corresponding to one dimension in the converted Vector.

Parameters:
labels - The labels to be used by the converter.

getIdentifiers

protected ArrayList<SemanticIdentifier> getIdentifiers()
Gets the list of cached SemanticIdentifiers.

Returns:
The list of cached SemanticIdentifiers.

setIdentifiers

protected void setIdentifiers(ArrayList<SemanticIdentifier> identifiers)
Sets the list of cached SemanticIdentifiers.

Parameters:
identifiers - The list of cached SemanticIdentifiers.

getIdentifierToIndexMap

protected HashMap<SemanticIdentifier,Integer> getIdentifierToIndexMap()
Gets the cached mapping of SemanticIdentifier to vector index.

Returns:
The cached mapping of SemanticIdentifier to vector index.

setIdentifierToIndexMap

protected void setIdentifierToIndexMap(HashMap<SemanticIdentifier,Integer> identifierToIndexMap)
Sets the cached mapping of SemanticIdentifier to vector index.

Parameters:
identifierToIndexMap - The cached mapping of SemanticIdentifier to vector index.

getCogxelFactory

public CogxelFactory getCogxelFactory()
Gets the CogxelFactory used to create the Cogxels used by the converter.

Returns:
The CogxelFactory used to create the Cogxels used by the converter.

setCogxelFactory

public void setCogxelFactory(CogxelFactory cogxelFactory)
Gets the CogxelFactory used to create the Cogxels used by the converter.

Parameters:
cogxelFactory - The CogxelFactory used to create the Cogxels used by the converter.