A class to represent a feature vector, where features are represented by unique identifiers, and feature values are represented by the template type.
More...
|
| FeatureVector () |
| Create an empty feature vector. More...
|
|
| FeatureVector (const Map &features) |
| Copy features from the type of map used internally. More...
|
|
template<typename MapType > |
| FeatureVector (const MapType &features) |
| Copy features from any map, or any collection of (feature,value) pairs, for that matter. More...
|
|
virtual | ~FeatureVector () |
|
const_iterator | begin () const |
| Returns a const iterator pointing to the first of the feature-value pairs of this feature vector. More...
|
|
const_iterator | end () const |
| Returns a const iterator pointing to the end of the feature-value pairs of this feature vector. More...
|
|
unordered_set< K > & | GetNonZeroFeatures (unordered_set< K > &set) const |
| Inserts the uid's of features with non-zero weights into the specified set. More...
|
|
unordered_set< K > & | RemoveNonZeroFeatures (unordered_set< K > &set) const |
| Removes the uid's of features with non-zero weights from the specified set. More...
|
|
unordered_set< K > & | RemoveEqualFeatures (const FeatureVector< K, V > &other, unordered_set< K > &set) const |
| Removes from the specified set the uid's of feature with weights equal in this vector to their weights in the specified vector. More...
|
|
V | GetWeight (const K &uid) const |
| Returns the weight of the feature with the specified uid, where crucially features not "present" in this vector implicitly have a weight of 0.0 (or whatever the default constructor of the value type is). More...
|
|
V | GetValue (const K &uid) const |
| Synonymous with GetWeight. More...
|
|
size_t | size () const |
| Returns the number of non-zero feature components of this feature vector. More...
|
|
bool | empty () const |
|
V | Dot (const FeatureVector< K, V > &other) const |
| Computes the dot product of this feature vector with the specified FeatureVector. More...
|
|
V | IncrementWeight (const K &uid, V by) |
| Increments the weight of the specified feature by the specified amount. More...
|
|
V | IncrementValue (const K &uid, V by) |
| Increments the value of the specified vector component by the specified amount. More...
|
|
V | SetWeight (const K &uid, V new_weight) |
| Sets the weight of the specified feature to the specified value. More...
|
|
V | SetValue (const K &uid, V new_value) |
| Synonym for SetWeight. More...
|
|
FeatureVector< K, V > & | Scale (V scalar) |
| Multiplies this vector, in situ, by the specified scalar. More...
|
|
FeatureVector< K, V > & | AddScaledVector (const FeatureVector< K, V > &other, V scalar) |
| Modifies this vector so that it equals this vector plus the scaled specified vector. More...
|
|
template<typename Collection > |
FeatureVector< K, V > & | AddScaledSubvector (const Collection &feature_uids, const FeatureVector< K, V > &feature_vector, V scalar) |
| Modifies this vector so that it equals this vector plus the scaled specified subvector. More...
|
|
template<typename Collection > |
FeatureVector< K, V > & | IncrementWeights (const Collection &feature_uids, V increment) |
| Increments the weights for the specified collection of features. More...
|
|
void | clear () |
| Sets all feature weights to zero and, because this is a sparse vector, clears all storage. More...
|
|
template<typename K, typename V, typename Map = unordered_map<K, V>>
class reranker::FeatureVector< K, V, Map >
A class to represent a feature vector, where features are represented by unique identifiers, and feature values are represented by the template type.
- Template Parameters
-
K | the type to represent unique identifiers for each feature |
V | the value or weight of a feature in this vector |
Definition at line 114 of file feature-vector.H.
template<typename K, typename V, typename Map = unordered_map<K, V>>
template<typename MapType >
Copy features from any map, or any collection of (feature,value) pairs, for that matter.
- Template Parameters
-
MapType | the type of map from which to copy features into this feature vector |
- Parameters
-
features | the map or collection of (feature,value) pairs with which to initialize this feature vector |
Definition at line 137 of file feature-vector.H.
template<typename K, typename V, typename Map = unordered_map<K, V>>
template<typename Collection >
Modifies this vector so that it equals this vector plus the scaled specified subvector.
The specified collection of feature uid's—the feature_uids
parameter—specifies the subspace into which to project the specified feature vector—the feature_vector
parameter. This subvector is then scaled by the specified scalar—the scalar
parameter—and added to this vector in situ.
- Parameters
-
feature_uids | the subspace into which to project the specified feature vector before scaling and adding to this vector |
feature_vector | the feature vector to be projected into a subspace, scaled and then added to this vector |
scalar | the amount by which to scale the specified subvector prior to adding it to this vector |
- Returns
- this vector, having been modified by this method
Definition at line 373 of file feature-vector.H.
template<typename K, typename V, typename Map = unordered_map<K, V>>
Modifies this vector so that it equals this vector plus the scaled specified vector.
In notation, if this vector is v1 and the specified vector is v2 and the scalar is a, then after invoking this method this vector would equal v1 + a*v2.
- Parameters
-
other | the vector the scaled version of which is to be added to this vector |
scalar | the amount by which to scale the specified vector before adding the result to this vector |
- Returns
- this vector, having been modified by this method
Definition at line 348 of file feature-vector.H.
template<typename K, typename V, typename Map = unordered_map<K, V>>
Returns the weight of the feature with the specified uid, where crucially features not "present" in this vector implicitly have a weight of 0.0 (or whatever the default constructor of the value type is).
- Parameters
-
uid | the uid of the feature whose weight is to be retrieved |
Definition at line 227 of file feature-vector.H.
template<typename K, typename V, typename Map = unordered_map<K, V>>
Increments the value of the specified vector component by the specified amount.
(Synonym for IncrementWeight.)
- Parameters
-
uid | the uid of the vector component whose value is to be incremented |
by | the amount by which to increment the specified component's value |
- Returns
- the new value for the specified vector component
Definition at line 304 of file feature-vector.H.
template<typename K, typename V, typename Map = unordered_map<K, V>>
Increments the weight of the specified feature by the specified amount.
This method is synonymous with IncrementValue.
- Parameters
-
uid | the uid of the feature whose weight is to be incremented |
by | the amount by which to increment the specified feature's value |
- Returns
- the new value for the specified feature
Definition at line 269 of file feature-vector.H.
template<typename K, typename V, typename Map = unordered_map<K, V>>
template<typename Collection >
Increments the weights for the specified collection of features.
- Parameters
-
feature_uids | a collection of feature uid's whose weights are to be incremented by the specified amount |
increment | the amount by which to increment the weight of the specified set of features |
- Returns
- this vector, having been modified by this method
Definition at line 393 of file feature-vector.H.