public class ConcatVectorNamespace
extends java.lang.Object
This is a wrapper function to keep a namespace of namespace of recognized features, so that building a set of ConcatVectors for featurizing a model is easier and more intuitive. It's actually quite simple, and threadsafe.
Constructor and Description |
---|
ConcatVectorNamespace() |
Modifier and Type | Method and Description |
---|---|
void |
debugVector(ConcatVector vector,
java.io.BufferedWriter bw)
This prints out a ConcatVector by mapping to the namespace, to make debugging learning algorithms easier.
|
int |
ensureFeature(java.lang.String featureName)
An optimization, this lets clients inform the ConcatVectorNamespace of how many features to expect, so
that we can avoid resizing ConcatVectors.
|
int |
ensureSparseFeature(java.lang.String featureName,
java.lang.String index)
An optimization, this lets clients inform the ConcatVectorNamespace of how many sparse feature components to
expect, again so that we can avoid resizing ConcatVectors.
|
ConcatVector |
newVector()
Creates a new vector that is appropriately sized to accommodate all the features that have been named so far.
|
ConcatVector |
newWeightsVector()
This constructs a fresh vector that is sized correctly to accommodate all the known sparse values for vectors
that are possibly sparse.
|
void |
setDenseFeature(ConcatVector vector,
java.lang.String featureName,
double[] value)
This adds a dense feature to a vector, setting the appropriate component of the given vector to the passed in
value.
|
void |
setSparseFeature(ConcatVector vector,
java.lang.String featureName,
java.lang.String index,
double value)
This adds a sparse feature to a vector, setting the appropriate component of the given vector to the passed in
value.
|
public ConcatVector newVector()
public ConcatVector newWeightsVector()
public int ensureFeature(java.lang.String featureName)
featureName
- the feature to add to our indexpublic int ensureSparseFeature(java.lang.String featureName, java.lang.String index)
featureName
- the feature to use in our indexindex
- the sparse value to ensure is availablepublic void setDenseFeature(ConcatVector vector, java.lang.String featureName, double[] value)
vector
- the vectorfeatureName
- the feature whose value to setvalue
- the value we want to set this vector topublic void setSparseFeature(ConcatVector vector, java.lang.String featureName, java.lang.String index, double value)
vector
- the vectorfeatureName
- the feature whose value to setindex
- the index of the one-hot vector to set, as a string, which we will translate into a mappingvalue
- the value we want to set this one-hot index topublic void debugVector(ConcatVector vector, java.io.BufferedWriter bw) throws java.io.IOException
vector
- the vector to printbw
- the output stream to write tojava.io.IOException