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

Function test_defaults

dlib/test/tfidf.cpp:38–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36// ----------------------------------------------------------------------------------------
37
38 void test_defaults()
39 {
40 tfidf_transformer<sparse_type> tfidf;
41 DLIB_TEST(tfidf.vocabulary_size() == 0);
42 DLIB_TEST(tfidf.min_document_frequency() == 1);
43 DLIB_TEST(tfidf.uses_smooth_idf());
44 DLIB_TEST(!tfidf.uses_sublinear_tf());
45 DLIB_TEST(tfidf.normalizes_to_unit_length());
46
47 tfidf.train(corpus());
48 DLIB_TEST(tfidf.vocabulary() == std::vector<unsigned long>({0,1,2,3}));
49 // smooth idf: log((1+n)/(1+df)) + 1 with n == 3
50 DLIB_TEST(near(tfidf.idf()[0], std::log(2.0) + 1));
51 DLIB_TEST(near(tfidf.idf()[1], 1));
52 DLIB_TEST(near(tfidf.idf()[2], std::log(2.0) + 1));
53 DLIB_TEST(near(tfidf.idf()[3], std::log(2.0) + 1));
54
55 const sparse_type r = tfidf(corpus()[0]);
56 const double a = std::log(2.0) + 1;
57 const double b = 2;
58 const double norm = std::sqrt(a*a + b*b);
59 DLIB_TEST(r.size() == 2);
60 DLIB_TEST(r[0].first == 0 && near(r[0].second, a/norm));
61 DLIB_TEST(r[1].first == 1 && near(r[1].second, b/norm));
62 DLIB_TEST(near(length(r), 1));
63 }
64
65// ----------------------------------------------------------------------------------------
66

Callers 1

perform_testMethod · 0.85

Calls 12

corpusFunction · 0.85
nearFunction · 0.85
logFunction · 0.85
vocabulary_sizeMethod · 0.80
uses_smooth_idfMethod · 0.80
uses_sublinear_tfMethod · 0.80
sqrtFunction · 0.50
lengthFunction · 0.50
trainMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected