gov.sandia.cognition.framework.lite
Class SimplePatternRecognizer

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.framework.lite.SimplePatternRecognizer
All Implemented Interfaces:
CognitiveModuleSettings, MutablePatternRecognizerLite, PatternRecognizerLite, CloneableSerializable, Serializable, Cloneable

public class SimplePatternRecognizer
extends AbstractCloneableSerializable
implements MutablePatternRecognizerLite

The SimplePatternRecognizer class implements a simple version of the PatternRecognizerLite interface. All it does is use a matrix multiply to come up with the next set of values. This implementation is for demonstration purposes only and is in no way psychologically plausible.

Since:
1.0
Author:
Justin Basilico
See Also:
Serialized Form

Constructor Summary
SimplePatternRecognizer()
          Creates a new, empty instance of SimplePatternRecognizer.
SimplePatternRecognizer(SemanticNetwork network)
          Creates a new instance of SimplePatternRecognizer.
SimplePatternRecognizer(SimplePatternRecognizer other)
          Creates a new instance of SimplePatternRecognizer.
 
Method Summary
 void addNode(SemanticLabel label)
          Adds a node to the pattern recognizer.
protected  void buildNodeToIDMap()
          Builds the map of nodes to identifiers from the list of nodes.
 SimplePatternRecognizer clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 Vector createEmptyInputVector()
          Creates an empty vector to use for input.
 Collection<SemanticLabel> getAllLabels()
          Gets the collection of all the labels used in the recognizer.
 double getAssociation(SemanticLabel from, SemanticLabel to)
          Gets the association between two nodes in the network.
 int getIndex(SemanticLabel label)
          Gets the index in the vector of the given label.
 int getInputDimensionality()
          Gets the dimensionality of the input vector to the pattern recognizer.
 Collection<SemanticLabel> getInputLabels()
          Gets the labels for the dimensions of the input vector.
 SemanticNetwork getNetwork()
          Gets the SemanticNetwork describing the structure of the pattern recognizer.
 int getOutputDimensionality()
          Gets the dimensionality of the output vector to the pattern recognizer.
 Collection<SemanticLabel> getOutputLabels()
          Gets the labels for the dimensions of the output vector.
 SimplePatternRecognizerState initialState()
          Creates a new initial state for the recognizer.
 boolean isInputLabel(SemanticLabel label)
          Takes a SemanticLabel and returns true if it is a label used to provide input to the PatternRecognizerLite.
 boolean isLabel(SemanticLabel label)
          Takes a SemanticLabel and returns true if the PatternRecognizer uses it.
 boolean isOutputLabel(SemanticLabel label)
          Takes a SemanticLabel and returns true if it is a label used as output from the PatternRecognizerLite.
 Vector recognize(CognitiveModuleState state, Vector inputs)
          Computes the recognition.
 void removeNode(SemanticLabel label)
          Removes a node and all links associated with that node from the pattern recognizer.
 void setAssociation(SemanticLabel from, SemanticLabel to, double weight)
          Sets the association between nodes in the recognizer.
protected  void setMatrix(Matrix matrix)
          Sets the underlying matrix.
protected  void setNodes(ArrayList<SemanticLabel> nodes)
          Sets the nodes in the recognizer.
protected  void setNodeToIDMap(HashMap<SemanticLabel,Integer> nodeToIDMap)
          Sets the mapping of nodes to their vector indices.
 boolean trySetInputLabel(SemanticLabel label, boolean inputLabel)
          Attempts to set whether or not the given label is an input label.
 boolean trySetOutputLabel(SemanticLabel label, boolean outputLabel)
          Attempts to set whether or not the given label is an output label.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimplePatternRecognizer

public SimplePatternRecognizer()
Creates a new, empty instance of SimplePatternRecognizer.


SimplePatternRecognizer

public SimplePatternRecognizer(SemanticNetwork network)
Creates a new instance of SimplePatternRecognizer.

Parameters:
network - The network to create the pattern recognizer from.

SimplePatternRecognizer

public SimplePatternRecognizer(SimplePatternRecognizer other)
Creates a new instance of SimplePatternRecognizer.

Parameters:
other - The SimplePatternRecognizer to copy.
Method Detail

clone

public SimplePatternRecognizer 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 PatternRecognizerLite
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

initialState

public SimplePatternRecognizerState initialState()
Creates a new initial state for the recognizer.

Specified by:
initialState in interface PatternRecognizerLite
Returns:
A new initial state for the recognizer.

recognize

public Vector recognize(CognitiveModuleState state,
                        Vector inputs)
Computes the recognition. It operates on the state by side-effect and uses the given set of inputs and sets the outputs.

Specified by:
recognize in interface PatternRecognizerLite
Parameters:
state - The previous state of the module.
inputs - The vector of inputs to the recognizer.
Returns:
The output vector

addNode

public void addNode(SemanticLabel label)
Adds a node to the pattern recognizer.

Specified by:
addNode in interface MutablePatternRecognizerLite
Parameters:
label - The label for the node to add.

removeNode

public void removeNode(SemanticLabel label)
Removes a node and all links associated with that node from the pattern recognizer. The node's entry in the vector is assumed to be removed so that the vector is now one dimension shorter.

Specified by:
removeNode in interface MutablePatternRecognizerLite
Parameters:
label - The label of the node to remove.

getAssociation

public double getAssociation(SemanticLabel from,
                             SemanticLabel to)
Gets the association between two nodes in the network.

Parameters:
from - The label the association is from
to - The label the association is to.
Returns:
The association weight between the two labels or zero if one of the labels is not in the recognizer.

setAssociation

public void setAssociation(SemanticLabel from,
                           SemanticLabel to,
                           double weight)
Sets the association between nodes in the recognizer.

Specified by:
setAssociation in interface MutablePatternRecognizerLite
Parameters:
from - The label of the node the assocation is from.
to - The label of the node the assocation is to.
weight - The weight of the association.

getIndex

public int getIndex(SemanticLabel label)
Gets the index in the vector of the given label.

Parameters:
label - The label to get the index of.
Returns:
The index assigned to the label or -1 if the label is not in the recognizer.

isLabel

public boolean isLabel(SemanticLabel label)
Takes a SemanticLabel and returns true if the PatternRecognizer uses it.

Specified by:
isLabel in interface PatternRecognizerLite
Parameters:
label - The label to determine if the recognizer uses.
Returns:
True if the label is used by the recognizer and false if not or if the label is not valid.

isInputLabel

public boolean isInputLabel(SemanticLabel label)
Takes a SemanticLabel and returns true if it is a label used to provide input to the PatternRecognizerLite.

Specified by:
isInputLabel in interface PatternRecognizerLite
Parameters:
label - The label to determine if it is an input label.
Returns:
True if the label is an input label and false otherwise.

isOutputLabel

public boolean isOutputLabel(SemanticLabel label)
Takes a SemanticLabel and returns true if it is a label used as output from the PatternRecognizerLite.

Specified by:
isOutputLabel in interface PatternRecognizerLite
Parameters:
label - The label to determine if it is an output label.
Returns:
True if the label is an output label and false otherwise.

getAllLabels

public Collection<SemanticLabel> getAllLabels()
Gets the collection of all the labels used in the recognizer.

Specified by:
getAllLabels in interface PatternRecognizerLite
Returns:
The collection of all labels used in the recognizer.

trySetInputLabel

public boolean trySetInputLabel(SemanticLabel label,
                                boolean inputLabel)
Attempts to set whether or not the given label is an input label. It returns true if the set operation was successful and false otherwise.

Specified by:
trySetInputLabel in interface MutablePatternRecognizerLite
Parameters:
label - The label to set whether or not it is input label.
inputLabel - Whether or not the label is an input label.
Returns:
True if the operation was successful and false if it was not.

trySetOutputLabel

public boolean trySetOutputLabel(SemanticLabel label,
                                 boolean outputLabel)
Attempts to set whether or not the given label is an output label. It returns true if the set operation was successful and false otherwise.

Specified by:
trySetOutputLabel in interface MutablePatternRecognizerLite
Parameters:
label - The label to set whether or not it is output label.
outputLabel - Whether or not the label is an output label.
Returns:
True if the operation was successful and false if it was not.

buildNodeToIDMap

protected void buildNodeToIDMap()
Builds the map of nodes to identifiers from the list of nodes.


createEmptyInputVector

public Vector createEmptyInputVector()
Creates an empty vector to use for input.

Specified by:
createEmptyInputVector in interface PatternRecognizerLite
Returns:
An empty input vector.

getInputDimensionality

public int getInputDimensionality()
Gets the dimensionality of the input vector to the pattern recognizer.

Specified by:
getInputDimensionality in interface PatternRecognizerLite
Returns:
The dimensionality of the input vector of the pattern recognizer.

getOutputDimensionality

public int getOutputDimensionality()
Gets the dimensionality of the output vector to the pattern recognizer.

Specified by:
getOutputDimensionality in interface PatternRecognizerLite
Returns:
The dimensionality of the output vector of the pattern recognizer.

getInputLabels

public Collection<SemanticLabel> getInputLabels()
Gets the labels for the dimensions of the input vector.

Specified by:
getInputLabels in interface PatternRecognizerLite
Returns:
The labels for the dimensions of the input vector.

getOutputLabels

public Collection<SemanticLabel> getOutputLabels()
Gets the labels for the dimensions of the output vector.

Specified by:
getOutputLabels in interface PatternRecognizerLite
Returns:
The labels for the dimensions of the output vector.

getNetwork

public SemanticNetwork getNetwork()
Gets the SemanticNetwork describing the structure of the pattern recognizer.

Specified by:
getNetwork in interface PatternRecognizerLite
Returns:
The recognizer's SemanticNetwork

setNodes

protected void setNodes(ArrayList<SemanticLabel> nodes)
Sets the nodes in the recognizer.

Parameters:
nodes - The new list of nodes.

setNodeToIDMap

protected void setNodeToIDMap(HashMap<SemanticLabel,Integer> nodeToIDMap)
Sets the mapping of nodes to their vector indices.

Parameters:
nodeToIDMap - The new mapping of nodes to vector indices.

setMatrix

protected void setMatrix(Matrix matrix)
Sets the underlying matrix.

Parameters:
matrix - The new underlying matrix.