Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Friends | List of all members
reranker::FeatureVector< K, V, Map > Class Template Reference

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...
 
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...
 
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
 
Dot (const FeatureVector< K, V > &other) const
 Computes the dot product of this feature vector with the specified FeatureVector. More...
 
IncrementWeight (const K &uid, V by)
 Increments the weight of the specified feature by the specified amount. More...
 
IncrementValue (const K &uid, V by)
 Increments the value of the specified vector component by the specified amount. More...
 
SetWeight (const K &uid, V new_weight)
 Sets the weight of the specified feature to the specified value. More...
 
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)
 

Detailed Description

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
Kthe type to represent unique identifiers for each feature
Vthe value or weight of a feature in this vector

Definition at line 114 of file feature-vector.H.

Member Typedef Documentation

template<typename K, typename V, typename Map = unordered_map<K, V>>
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.

template<typename K, typename V, typename Map = unordered_map<K, V>>
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.

template<typename K, typename V, typename Map = unordered_map<K, V>>
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.

template<typename K, typename V, typename Map = unordered_map<K, V>>
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.

Constructor & Destructor Documentation

template<typename K, typename V, typename Map = unordered_map<K, V>>
reranker::FeatureVector< K, V, Map >::FeatureVector ( )
inline

Create an empty feature vector.

Definition at line 117 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
reranker::FeatureVector< K, V, Map >::FeatureVector ( const Map &  features)
inline

Copy features from the type of map used internally.

Parameters
featuresthe map of features with which to initialize this feature vector

Definition at line 125 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
template<typename MapType >
reranker::FeatureVector< K, V, Map >::FeatureVector ( const MapType &  features)
inline

Copy features from any map, or any collection of (feature,value) pairs, for that matter.

Template Parameters
MapTypethe type of map from which to copy features into this feature vector
Parameters
featuresthe 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>>
virtual reranker::FeatureVector< K, V, Map >::~FeatureVector ( )
inlinevirtual

Definition at line 145 of file feature-vector.H.

Member Function Documentation

template<typename K, typename V, typename Map = unordered_map<K, V>>
template<typename Collection >
FeatureVector<K,V>& reranker::FeatureVector< K, V, Map >::AddScaledSubvector ( const Collection &  feature_uids,
const FeatureVector< K, V > &  feature_vector,
scalar 
)
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.

Parameters
feature_uidsthe subspace into which to project the specified feature vector before scaling and adding to this vector
feature_vectorthe feature vector to be projected into a subspace, scaled and then added to this vector
scalarthe 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>>
FeatureVector<K,V>& reranker::FeatureVector< K, V, Map >::AddScaledVector ( const FeatureVector< K, V > &  other,
scalar 
)
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.

Parameters
otherthe vector the scaled version of which is to be added to this vector
scalarthe 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>>
const_iterator reranker::FeatureVector< K, V, Map >::begin ( ) const
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.

template<typename K, typename V, typename Map = unordered_map<K, V>>
void reranker::FeatureVector< K, V, Map >::clear ( )
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.

template<typename K, typename V, typename Map = unordered_map<K, V>>
V reranker::FeatureVector< K, V, Map >::Dot ( const FeatureVector< K, V > &  other) const
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.

template<typename K, typename V, typename Map = unordered_map<K, V>>
bool reranker::FeatureVector< K, V, Map >::empty ( ) const
inline

Definition at line 242 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
const_iterator reranker::FeatureVector< K, V, Map >::end ( ) const
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.

template<typename K, typename V, typename Map = unordered_map<K, V>>
unordered_set<K>& reranker::FeatureVector< K, V, Map >::GetNonZeroFeatures ( unordered_set< K > &  set) const
inline

Inserts the uid's of features with non-zero weights into the specified set.

Attention
The specified is not cleared at any time by this method.
Parameters
[out]setthe set in which to insert uid's of all features with non-zero weight
Returns
the specified set, having been modified by this method

Definition at line 181 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
V reranker::FeatureVector< K, V, Map >::GetValue ( const K &  uid) const
inline

Synonymous with GetWeight.

Parameters
uidthe uid of the feature whose value is to be retrieved

Definition at line 235 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
V reranker::FeatureVector< K, V, Map >::GetWeight ( const K &  uid) const
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).

Parameters
uidthe 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>>
V reranker::FeatureVector< K, V, Map >::IncrementValue ( const K &  uid,
by 
)
inline

Increments the value of the specified vector component by the specified amount.

(Synonym for IncrementWeight.)

Parameters
uidthe uid of the vector component whose value is to be incremented
bythe 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>>
V reranker::FeatureVector< K, V, Map >::IncrementWeight ( const K &  uid,
by 
)
inline

Increments the weight of the specified feature by the specified amount.

This method is synonymous with IncrementValue.

Parameters
uidthe uid of the feature whose weight is to be incremented
bythe 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 >
FeatureVector<K,V>& reranker::FeatureVector< K, V, Map >::IncrementWeights ( const Collection &  feature_uids,
increment 
)
inline

Increments the weights for the specified collection of features.

Parameters
feature_uidsa collection of feature uid's whose weights are to be incremented by the specified amount
incrementthe 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.

template<typename K, typename V, typename Map = unordered_map<K, V>>
unordered_set<K>& reranker::FeatureVector< K, V, Map >::RemoveEqualFeatures ( const FeatureVector< K, V > &  other,
unordered_set< K > &  set 
) const
inline

Removes from the specified set the uid's of feature with weights equal in this vector to their weights in the specified vector.

Parameters
[in]otherthe vector whose feature weights are to be compared to those in this vector
[out]setthe set to be modified by this method
Returns
the specified set having been modified

Definition at line 210 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
unordered_set<K>& reranker::FeatureVector< K, V, Map >::RemoveNonZeroFeatures ( unordered_set< K > &  set) const
inline

Removes the uid's of features with non-zero weights from the specified set.

Attention
The specified is not cleared at any time by this method.
Parameters
[out]setthe set from which to remove uid's of all features with non-zero weight
Returns
the specified set having been modified

Definition at line 196 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
FeatureVector<K,V>& reranker::FeatureVector< K, V, Map >::Scale ( scalar)
inline

Multiplies this vector, in situ, by the specified scalar.

Parameters
scalarthe amount by which to scale this vector
Returns
this vector, having been modified by this method

Definition at line 331 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
V reranker::FeatureVector< K, V, Map >::SetValue ( const K &  uid,
new_value 
)
inline

Synonym for SetWeight.

Definition at line 323 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
V reranker::FeatureVector< K, V, Map >::SetWeight ( const K &  uid,
new_weight 
)
inline

Sets the weight of the specified feature to the specified value.

Parameters
uidthe uid of the feature whose weight is to be set
new_weightthe weight to which to set the specified feature
Returns
the old weight for the specified feature

Definition at line 312 of file feature-vector.H.

template<typename K, typename V, typename Map = unordered_map<K, V>>
size_t reranker::FeatureVector< K, V, Map >::size ( ) const
inline

Returns the number of non-zero feature components of this feature vector.

Definition at line 240 of file feature-vector.H.

Friends And Related Function Documentation

template<typename K, typename V, typename Map = unordered_map<K, V>>
ostream& operator<< ( ostream &  os,
const FeatureVector< K, V > &  fv 
)
friend

Definition at line 413 of file feature-vector.H.


The documentation for this class was generated from the following file: