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

Function test_cca3

dlib/test/cca.cpp:93–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91// ----------------------------------------------------------------------------------------
92
93 void test_cca3()
94 {
95 print_spinner();
96 const unsigned long rank = rnd.get_random_32bit_number()%10 + 1;
97 const unsigned long m = rank + rnd.get_random_32bit_number()%15;
98 const unsigned long n = rank + rnd.get_random_32bit_number()%15;
99 const unsigned long n2 = rank + rnd.get_random_32bit_number()%15;
100 const unsigned long rank2 = rank + rnd.get_random_32bit_number()%5;
101
102 dlog << LINFO << "m: " << m;
103 dlog << LINFO << "n: " << n;
104 dlog << LINFO << "n2: " << n2;
105 dlog << LINFO << "rank: " << rank;
106 dlog << LINFO << "rank2: " << rank2;
107
108
109 matrix<double> L = randm(m,rank, rnd)*randm(rank,n, rnd);
110 //matrix<double> R = randm(m,rank, rnd)*randm(rank,n2, rnd);
111 matrix<double> R = L*randm(n,n2, rnd);
112 //matrix<double> L = randm(m,n, rnd);
113 //matrix<double> R = randm(m,n2, rnd);
114
115 matrix<double> Ltrans, Rtrans;
116 matrix<double,0,1> correlations;
117
118 {
119 correlations = cca(L, R, Ltrans, Rtrans, min(m,n), max(n,n2));
120 DLIB_TEST(Ltrans.nc() == Rtrans.nc());
121 dlog << LINFO << "correlations: "<< trans(correlations);
122
123 const double corr_error = max(abs(compute_correlations(rm_zeros(L*Ltrans), rm_zeros(R*Rtrans)) - correlations));
124 dlog << LINFO << "correlation error: "<< corr_error;
125 DLIB_TEST_MSG(corr_error < 1e-13, Ltrans << "\n\n" << Rtrans);
126
127 const double trans_error = max(abs(L*Ltrans - R*Rtrans));
128 dlog << LINFO << "trans_error: "<< trans_error;
129 DLIB_TEST_MSG(trans_error < 1e-9, trans_error);
130 }
131 {
132 correlations = cca(mat_to_sparse(L), mat_to_sparse(R), Ltrans, Rtrans, min(m,n), max(n,n2)+6, 4);
133 DLIB_TEST(Ltrans.nc() == Rtrans.nc());
134 dlog << LINFO << "correlations: "<< trans(correlations);
135 dlog << LINFO << "computed cors: " << trans(compute_correlations(rm_zeros(L*Ltrans), rm_zeros(R*Rtrans)));
136
137 const double trans_error = max(abs(L*Ltrans - R*Rtrans));
138 dlog << LINFO << "trans_error: "<< trans_error;
139 const double corr_error = max(abs(compute_correlations(rm_zeros(L*Ltrans), rm_zeros(R*Rtrans)) - correlations));
140 dlog << LINFO << "correlation error: "<< corr_error;
141 DLIB_TEST_MSG(corr_error < 1e-13, Ltrans << "\n\n" << Rtrans);
142
143 DLIB_TEST(trans_error < 2e-9);
144 }
145
146 dlog << LINFO << "*****************************************************";
147 }
148
149 void test_cca2()
150 {

Callers 1

perform_testMethod · 0.85

Calls 12

print_spinnerFunction · 0.85
ccaFunction · 0.85
absFunction · 0.85
compute_correlationsFunction · 0.85
rm_zerosFunction · 0.85
mat_to_sparseFunction · 0.85
randmFunction · 0.70
minFunction · 0.50
maxFunction · 0.50
transFunction · 0.50
ncMethod · 0.45

Tested by

no test coverage detected