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

Method get_features

examples/sequence_segmenter_ex.cpp:56–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54
55 template <typename feature_setter>
56 void get_features (
57 feature_setter& set_feature,
58 const sequence_type& sentence,
59 unsigned long position
60 ) const
61 /*!
62 requires
63 - position < sentence.size()
64 - set_feature is a function object which allows expressions of the form:
65 - set_features((unsigned long)feature_index, (double)feature_value);
66 - set_features((unsigned long)feature_index);
67 ensures
68 - This function computes a feature vector which should capture the properties
69 of sentence[position] that are informative relative to the sequence
70 segmentation task you are trying to perform.
71 - The output feature vector is returned as a sparse vector by invoking set_feature().
72 For example, to set the feature with an index of 55 to the value of 1
73 this method would call:
74 set_feature(55);
75 Or equivalently:
76 set_feature(55,1);
77 Therefore, the first argument to set_feature is the index of the feature
78 to be set while the second argument is the value the feature should take.
79 Additionally, note that calling set_feature() multiple times with the
80 same feature index does NOT overwrite the old value, it adds to the
81 previous value. For example, if you call set_feature(55) 3 times then it
82 will result in feature 55 having a value of 3.
83 - This function only calls set_feature() with feature_index values < num_features()
84 !*/
85 {
86 // The model in this example program is very simple. Our features only look at the
87 // capitalization pattern of the words. So we have a single feature which checks
88 // if the first letter is capitalized or not.
89 if (isupper(sentence[position][0]))
90 set_feature(0);
91 }
92};
93
94// We need to define serialize() and deserialize() for our feature extractor if we want

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected