gov.sandia.cognition.data.convert.vector
Class UniqueBooleanVectorEncoder<InputType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.data.convert.AbstractDataConverter<InputType,Vector>
          extended by gov.sandia.cognition.data.convert.vector.AbstractToVectorEncoder<InputType>
              extended by gov.sandia.cognition.data.convert.vector.UniqueBooleanVectorEncoder<InputType>
Type Parameters:
InputType - The input type to encode as a unique values in a Vector.
All Implemented Interfaces:
DataConverter<InputType,Vector>, DataToVectorEncoder<InputType>, Evaluator<InputType,Vector>, VectorOutputEvaluator<InputType,Vector>, CloneableSerializable, Serializable, Cloneable

public class UniqueBooleanVectorEncoder<InputType>
extends AbstractToVectorEncoder<InputType>

An encoder for arbitrary objects that encodes an equality comparison between a given input and a set of unique values. It does an equality comparison to each specified value and encodes those booleans using a given boolean encoding. Typically, this encoding uses a single dimension for each value, but it supports boolean encodings of higher dimensionalities. This encoding is sometimes refered to as a "grandmother" encoding for neural networks, after the idea that there is a single neuron for each concept, such as your grandmother. The encoding is called a unique encoding because if a given input is in the set of possible values, a single true value will be encoded.

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

Field Summary
protected  DataToVectorEncoder<Boolean> booleanConverter
          The boolean encoder for the equality comparison between each of the possible values and a given input.
protected  List<InputType> values
          The set of possible unique values.
 
Fields inherited from class gov.sandia.cognition.data.convert.vector.AbstractToVectorEncoder
vectorFactory
 
Constructor Summary
UniqueBooleanVectorEncoder(List<InputType> values, DataToVectorEncoder<Boolean> booleanConverter)
          Creates a new UniqueBooleanVectorEncoder.
 
Method Summary
 void encode(InputType object, Vector vector, int startIndex)
          Encodes the given object into the given vector at the given starting index by using a unique boolean encoding, where the given input value is compared to each of the encoder's values using equality.
 DataToVectorEncoder<Boolean> getBooleanConverter()
          Gets the boolean converter used to encode the equality comparison between each of the unique values and a given input.
 int getOutputDimensionality()
          Gets the dimensionality of the vector created by this converter, which is the number of possible values times the size of the boolean encoding.
 List<InputType> getValues()
          Gets the list of unique values that the encoder is to use.
protected  void setBooleanConverter(DataToVectorEncoder<Boolean> booleanConverter)
          Sets the boolean converter used to encode the equality comparison between each of the unique values and a given input.
protected  void setValues(List<InputType> values)
          Sets the list of unique values that the encoder is to use.
 
Methods inherited from class gov.sandia.cognition.data.convert.vector.AbstractToVectorEncoder
encode, evaluate
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

values

protected List<InputType> values
The set of possible unique values.


booleanConverter

protected DataToVectorEncoder<Boolean> booleanConverter
The boolean encoder for the equality comparison between each of the possible values and a given input.

Constructor Detail

UniqueBooleanVectorEncoder

public UniqueBooleanVectorEncoder(List<InputType> values,
                                  DataToVectorEncoder<Boolean> booleanConverter)
Creates a new UniqueBooleanVectorEncoder.

Parameters:
values - The list of possible values.
booleanConverter - The boolean converter for the values.
Method Detail

encode

public void encode(InputType object,
                   Vector vector,
                   int startIndex)
Encodes the given object into the given vector at the given starting index by using a unique boolean encoding, where the given input value is compared to each of the encoder's values using equality. If the input is in the set of unique values, a single unique true boolean will be encoded, otherwise, all of the encoded values will be false.

Parameters:
object - The object to encode.
vector - The vector to encode into.
startIndex - The index to start the encoding at.

getOutputDimensionality

public int getOutputDimensionality()
Gets the dimensionality of the vector created by this converter, which is the number of possible values times the size of the boolean encoding.

Returns:
The dimensionality of the vector created by this encoder.

getValues

public List<InputType> getValues()
Gets the list of unique values that the encoder is to use.

Returns:
The list of unique values.

setValues

protected void setValues(List<InputType> values)
Sets the list of unique values that the encoder is to use.

Parameters:
values - The list of unique values.

getBooleanConverter

public DataToVectorEncoder<Boolean> getBooleanConverter()
Gets the boolean converter used to encode the equality comparison between each of the unique values and a given input.

Returns:
The boolean converter to use.

setBooleanConverter

protected void setBooleanConverter(DataToVectorEncoder<Boolean> booleanConverter)
Sets the boolean converter used to encode the equality comparison between each of the unique values and a given input.

Parameters:
booleanConverter - The boolean converter to use.