MCPcopy Create free account
hub / github.com/davisking/dlib / get_features

Method get_features

examples/sequence_labeler_ex.cpp:113–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111
112 template <typename feature_setter, typename EXP>
113 void get_features (
114 feature_setter& set_feature,
115 const sequence_type& x,
116 const matrix_exp<EXP>& y,
117 unsigned long position
118 ) const
119 /*!
120 requires
121 - EXP::type == unsigned long
122 (i.e. y contains unsigned longs)
123 - position < x.size()
124 - y.size() == min(position, order) + 1
125 - is_vector(y) == true
126 - max(y) < num_labels()
127 - set_feature is a function object which allows expressions of the form:
128 - set_features((unsigned long)feature_index, (double)feature_value);
129 - set_features((unsigned long)feature_index);
130 ensures
131 - for all valid i:
132 - interprets y(i) as the label corresponding to x[position-i]
133 - This function computes the part of PSI() corresponding to the x[position]
134 element of the input sequence. Moreover, this part of PSI() is returned as
135 a sparse vector by invoking set_feature(). For example, to set the feature
136 with an index of 55 to the value of 1 this method would call:
137 set_feature(55);
138 Or equivalently:
139 set_feature(55,1);
140 Therefore, the first argument to set_feature is the index of the feature
141 to be set while the second argument is the value the feature should take.
142 Additionally, note that calling set_feature() multiple times with the same
143 feature index does NOT overwrite the old value, it adds to the previous
144 value. For example, if you call set_feature(55) 3 times then it will
145 result in feature 55 having a value of 3.
146 - This function only calls set_feature() with feature_index values < num_features()
147 !*/
148 {
149 // Again, the features below only define a simple HMM. But in general, you can
150 // use a wide variety of sophisticated feature extraction methods here.
151
152 // Pull out an indicator feature for the type of transition between the
153 // previous label and the current label.
154 if (y.size() > 1)
155 set_feature(y(1)*num_label_states + y(0));
156
157 // Pull out an indicator feature for the type of observed node given
158 // the current label.
159 set_feature(num_label_states*num_label_states +
160 y(0)*num_sample_states + x[position]);
161 }
162};
163
164// We need to define serialize() and deserialize() for our feature extractor if we want

Callers

nothing calls this directly

Calls 2

yFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected