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

Function make_dataset

dlib/test/sequence_labeler.cpp:221–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219// ----------------------------------------------------------------------------------------
220
221 void make_dataset (
222 const matrix<double>& transition_probabilities,
223 const matrix<double>& emission_probabilities,
224 std::vector<funny_sequence>& samples,
225 std::vector<std::vector<unsigned long> >& labels,
226 unsigned long dataset_size
227 )
228 /*!
229 requires
230 - transition_probabilities.nr() == transition_probabilities.nc()
231 - transition_probabilities.nr() == emission_probabilities.nr()
232 - The rows of transition_probabilities and emission_probabilities must sum to 1.
233 (i.e. sum_cols(transition_probabilities) and sum_cols(emission_probabilities)
234 must evaluate to vectors of all 1s.)
235 ensures
236 - This function randomly samples a bunch of sequences from the HMM defined by
237 transition_probabilities and emission_probabilities.
238 - The HMM is defined by:
239 - The probability of transitioning from hidden state H1 to H2
240 is given by transition_probabilities(H1,H2).
241 - The probability of a hidden state H producing an observed state
242 O is given by emission_probabilities(H,O).
243 - #samples.size() == labels.size() == dataset_size
244 - for all valid i:
245 - #labels[i] is a randomly sampled sequence of hidden states from the
246 given HMM. #samples[i] is its corresponding randomly sampled sequence
247 of observed states.
248 !*/
249 {
250 samples.clear();
251 labels.clear();
252
253 dlib::rand rnd;
254
255 // now randomly sample some labeled sequences from our Hidden Markov Model
256 for (unsigned long iter = 0; iter < dataset_size; ++iter)
257 {
258 const unsigned long sequence_size = rnd.get_random_32bit_number()%20+3;
259 std::vector<unsigned long> sample(sequence_size);
260 std::vector<unsigned long> label(sequence_size);
261
262 unsigned long previous_label = rnd.get_random_32bit_number()%num_label_states;
263 for (unsigned long i = 0; i < sample.size(); ++i)
264 {
265 unsigned long next_label=0, next_sample=0;
266 sample_hmm(rnd, transition_probabilities, emission_probabilities,
267 previous_label, next_label, next_sample);
268
269 label[i] = next_label;
270 sample[i] = next_sample;
271
272 previous_label = next_label;
273 }
274
275 samples.push_back(make_funny_sequence(sample));
276 labels.push_back(label);
277 }
278 }

Callers 2

do_testFunction · 0.70
test2Function · 0.70

Calls 6

make_funny_sequenceFunction · 0.85
sample_hmmFunction · 0.70
clearMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected