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

Function test_cca1

dlib/test/cca.cpp:211–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209 }
210
211 void test_cca1()
212 {
213 print_spinner();
214 const unsigned long rank = rnd.get_random_32bit_number()%10 + 1;
215 const unsigned long m = rank + rnd.get_random_32bit_number()%15;
216 const unsigned long n = rank + rnd.get_random_32bit_number()%15;
217
218 dlog << LINFO << "m: " << m;
219 dlog << LINFO << "n: " << n;
220 dlog << LINFO << "rank: " << rank;
221
222 matrix<double> T = randm(n,n, rnd);
223
224 matrix<double> L = randm(m,rank, rnd)*randm(rank,n, rnd);
225 //matrix<double> L = randm(m,n, rnd);
226 matrix<double> R = L*T;
227
228 matrix<double> Ltrans, Rtrans;
229 matrix<double,0,1> correlations;
230
231 {
232 correlations = cca(L, R, Ltrans, Rtrans, rank);
233 DLIB_TEST(Ltrans.nc() == Rtrans.nc());
234 if (Ltrans.nc() > 1)
235 {
236 // The CCA projection directions are supposed to be uncorrelated for
237 // non-matching pairs of projections.
238 const double corr_rot1_error = max(abs(compute_correlations(rm_zeros(L*rotate<0,1>(Ltrans)), rm_zeros(R*Rtrans))));
239 dlog << LINFO << "corr_rot1_error: "<< corr_rot1_error;
240 DLIB_TEST(std::abs(corr_rot1_error) < 1e-7);
241 }
242 // Matching projection directions should be correlated with the amount of
243 // correlation indicated by the return value of cca().
244 const double corr_error = max(abs(compute_correlations(rm_zeros(L*Ltrans), rm_zeros(R*Rtrans)) - correlations));
245 dlog << LINFO << "correlation error: "<< corr_error;
246 DLIB_TEST(corr_error < 1e-13);
247
248 const double trans_error = max(abs(L*Ltrans - R*Rtrans));
249 dlog << LINFO << "trans_error: "<< trans_error;
250 DLIB_TEST(trans_error < 2e-9);
251
252 dlog << LINFO << "correlations: "<< trans(correlations);
253 }
254 {
255 correlations = cca(mat_to_sparse(L), mat_to_sparse(R), Ltrans, Rtrans, rank);
256 DLIB_TEST(Ltrans.nc() == Rtrans.nc());
257 if (Ltrans.nc() > 1)
258 {
259 // The CCA projection directions are supposed to be uncorrelated for
260 // non-matching pairs of projections.
261 const double corr_rot1_error = max(abs(compute_correlations(rm_zeros(L*rotate<0,1>(Ltrans)), rm_zeros(R*Rtrans))));
262 dlog << LINFO << "corr_rot1_error: "<< corr_rot1_error;
263 DLIB_TEST(std::abs(corr_rot1_error) < 2e-9);
264 }
265 // Matching projection directions should be correlated with the amount of
266 // correlation indicated by the return value of cca().
267 const double corr_error = max(abs(compute_correlations(rm_zeros(L*Ltrans), rm_zeros(R*Rtrans)) - correlations));
268 dlog << LINFO << "correlation error: "<< corr_error;

Callers 1

perform_testMethod · 0.85

Calls 11

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
maxFunction · 0.50
transFunction · 0.50
ncMethod · 0.45

Tested by

no test coverage detected