Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
|
A class to represent a feature vector, where features are represented by unique identifiers, and feature values are represented by the template type. More...
#include <feature-vector.H>
Public Types | |
typedef K | key_type |
The type of vector component/feature uid's in this vector. More... | |
typedef V | mapped_type |
The type of values/feature weights in this vector. More... | |
typedef Map | FeatureMap |
The underlying type that this class stores the mapping of feature uid's to their weights. More... | |
typedef FeatureMap::const_iterator | const_iterator |
The type of const iterator for the feature-weight pairs in this vector. More... | |
Public Member Functions | |
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... | |
Friends | |
ostream & | operator<< (ostream &os, const FeatureVector< K, V > &fv) |
A class to represent a feature vector, where features are represented by unique identifiers, and feature values are represented by the template type.
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.
typedef FeatureMap::const_iterator reranker::FeatureVector< K, V, Map >::const_iterator |
The type of const iterator for the feature-weight pairs in this vector.
Definition at line 157 of file feature-vector.H.
typedef Map reranker::FeatureVector< K, V, Map >::FeatureMap |
The underlying type that this class stores the mapping of feature uid's to their weights.
Definition at line 155 of file feature-vector.H.
typedef K reranker::FeatureVector< K, V, Map >::key_type |
The type of vector component/feature uid's in this vector.
Definition at line 149 of file feature-vector.H.
typedef V reranker::FeatureVector< K, V, Map >::mapped_type |
The type of values/feature weights in this vector.
Definition at line 151 of file feature-vector.H.
|
inline |
Create an empty feature vector.
Definition at line 117 of file feature-vector.H.
|
inline |
Copy features from the type of map used internally.
features | the map of features with which to initialize this feature vector |
Definition at line 125 of file feature-vector.H.
|
inline |
Copy features from any map, or any collection of (feature,value) pairs, for that matter.
MapType | the type of map from which to copy features into this feature vector |
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.
|
inlinevirtual |
Definition at line 145 of file feature-vector.H.
|
inline |
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.
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 |
Definition at line 373 of file feature-vector.H.
|
inline |
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.
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 |
Definition at line 348 of file feature-vector.H.
|
inline |
Returns a const iterator pointing to the first of the feature-value pairs of this feature vector.
Definition at line 163 of file feature-vector.H.
|
inline |
Sets all feature weights to zero and, because this is a sparse vector, clears all storage.
Definition at line 405 of file feature-vector.H.
|
inline |
Computes the dot product of this feature vector with the specified FeatureVector.
This primitive operation is one out of which a multitude of kernel functions may be constructed.
Definition at line 247 of file feature-vector.H.
|
inline |
Definition at line 242 of file feature-vector.H.
|
inline |
Returns a const iterator pointing to the end of the feature-value pairs of this feature vector.
Definition at line 169 of file feature-vector.H.
|
inline |
Inserts the uid's of features with non-zero weights into the specified set.
[out] | set | the set in which to insert uid's of all features with non-zero weight |
Definition at line 181 of file feature-vector.H.
|
inline |
Synonymous with GetWeight.
uid | the uid of the feature whose value is to be retrieved |
Definition at line 235 of file feature-vector.H.
|
inline |
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).
uid | the uid of the feature whose weight is to be retrieved |
Definition at line 227 of file feature-vector.H.
|
inline |
Increments the value of the specified vector component by the specified amount.
(Synonym for IncrementWeight.)
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 |
Definition at line 304 of file feature-vector.H.
|
inline |
Increments the weight of the specified feature by the specified amount.
This method is synonymous with IncrementValue.
uid | the uid of the feature whose weight is to be incremented |
by | the amount by which to increment the specified feature's value |
Definition at line 269 of file feature-vector.H.
|
inline |
Increments the weights for the specified collection of features.
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 |
Definition at line 393 of file feature-vector.H.
|
inline |
Removes from the specified set the uid's of feature with weights equal in this vector to their weights in the specified vector.
[in] | other | the vector whose feature weights are to be compared to those in this vector |
[out] | set | the set to be modified by this method |
Definition at line 210 of file feature-vector.H.
|
inline |
Removes the uid's of features with non-zero weights from the specified set.
[out] | set | the set from which to remove uid's of all features with non-zero weight |
Definition at line 196 of file feature-vector.H.
|
inline |
Multiplies this vector, in situ, by the specified scalar.
scalar | the amount by which to scale this vector |
Definition at line 331 of file feature-vector.H.
|
inline |
Synonym for SetWeight.
Definition at line 323 of file feature-vector.H.
|
inline |
Sets the weight of the specified feature to the specified value.
uid | the uid of the feature whose weight is to be set |
new_weight | the weight to which to set the specified feature |
Definition at line 312 of file feature-vector.H.
|
inline |
Returns the number of non-zero feature components of this feature vector.
Definition at line 240 of file feature-vector.H.
|
friend |
Definition at line 413 of file feature-vector.H.