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

Method test_lda

dlib/test/statistics.cpp:891–942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

889 }
890
891 void test_lda ()
892 {
893 // This test makes sure we pick the right direction in a simple 2D -> 1D LDA
894 typedef matrix<double,2,1> sample_type;
895
896 std::vector<unsigned long> labels;
897 std::vector<sample_type> samples;
898 for (int i=0; i<4; i++)
899 {
900 sample_type s;
901 s(0) = i;
902 s(1) = i+1;
903 samples.push_back(s);
904 labels.push_back(1);
905
906 sample_type s1;
907 s1(0) = i+1;
908 s1(1) = i;
909 samples.push_back(s1);
910 labels.push_back(2);
911 }
912
913 matrix<double> X;
914 X.set_size(8,2);
915 for (int i=0; i<8; i++){
916 X(i,0) = samples[i](0);
917 X(i,1) = samples[i](1);
918 }
919
920 matrix<double,0,1> mean;
921
922 dlib::compute_lda_transform(X,mean,labels,1);
923
924 std::vector<double> vals1, vals2;
925 for (unsigned long i = 0; i < samples.size(); ++i)
926 {
927 double val = X*samples[i]-mean;
928 if (i%2 == 0)
929 vals1.push_back(val);
930 else
931 vals2.push_back(val);
932 dlog << LINFO << "1D LDA output: " << val;
933 }
934
935 if (vals1[0] > vals2[0])
936 swap(vals1, vals2);
937
938 const double err = equal_error_rate(vals1, vals2).first;
939 dlog << LINFO << "LDA ERR: " << err;
940 DLIB_TEST(err == 0);
941 DLIB_TEST(equal_error_rate(vals2, vals1).first == 1);
942 }
943
944 void test_equal_error_rate()
945 {

Callers

nothing calls this directly

Calls 6

compute_lda_transformFunction · 0.85
equal_error_rateFunction · 0.85
swapFunction · 0.70
push_backMethod · 0.45
set_sizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected