gov.sandia.cognition.learning.function.scalar
Class VectorEntryFunction

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.math.AbstractScalarFunction<Vectorizable>
          extended by gov.sandia.cognition.learning.function.scalar.VectorEntryFunction
All Implemented Interfaces:
Evaluator<Vectorizable,Double>, Vectorizable, ScalarFunction<Vectorizable>, CloneableSerializable, Serializable, Cloneable

public class VectorEntryFunction
extends AbstractScalarFunction<Vectorizable>
implements Vectorizable

An evaluator that returns the value of an input vector at a specified index.

Since:
3.0
Author:
Dan Morrow, Justin Basilico
See Also:
Serialized Form

Field Summary
static int DEFAULT_INDEX
          The default index is 0.
protected  int index
          The index of the vector to get.
 
Constructor Summary
VectorEntryFunction()
          Creates a new VectorEntryFunction with an initial index of 0.
VectorEntryFunction(int index)
          Creates a new VectorEntryFunction with the given index.
 
Method Summary
 VectorEntryFunction clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 void convertFromVector(Vector parameters)
          Converts a vector into the index to select from the vector.
 Vector convertToVector()
          Converts the index to select into a vector (of length 1).
 boolean equals(Object other)
           
 double evaluateAsDouble(Vectorizable input)
          Returns the vector value at the specified index.
 int getIndex()
          Gets the index into the vector that the function gets the value for.
 int hashCode()
           
 void setIndex(int index)
          Sets the index into the vector that the function gets the value for.
 
Methods inherited from class gov.sandia.cognition.math.AbstractScalarFunction
evaluate
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INDEX

public static final int DEFAULT_INDEX
The default index is 0.

See Also:
Constant Field Values

index

protected int index
The index of the vector to get.

Constructor Detail

VectorEntryFunction

public VectorEntryFunction()
Creates a new VectorEntryFunction with an initial index of 0.


VectorEntryFunction

public VectorEntryFunction(int index)
Creates a new VectorEntryFunction with the given index.

Parameters:
index - The index into a vector to get the output for.
Method Detail

clone

public VectorEntryFunction clone()
Description copied from class: AbstractCloneableSerializable
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 Vectorizable
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

evaluateAsDouble

public double evaluateAsDouble(Vectorizable input)
Returns the vector value at the specified index.

Specified by:
evaluateAsDouble in interface ScalarFunction<Vectorizable>
Parameters:
input - The input vector.
Returns:
The value of the input vector at the given index.

convertToVector

public Vector convertToVector()
Converts the index to select into a vector (of length 1).

Specified by:
convertToVector in interface Vectorizable
Returns:
A 1-dimensional vector containing the index.

convertFromVector

public void convertFromVector(Vector parameters)
Converts a vector into the index to select from the vector.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - The parameter vector. Must be of dimensionality one.

getIndex

public int getIndex()
Gets the index into the vector that the function gets the value for.

Returns:
The index.

setIndex

public void setIndex(int index)
Sets the index into the vector that the function gets the value for.

Parameters:
index - The index.