def check_init_from_klist(): #check if a list generated from an other has the same kernels with only tr kl = HPK_generator(X_tr).make_a_list(n) kr = kernel_list(X_tr, X_tr, kl) assert_array_almost_equal(kl[0], kr[0]) assert_array_almost_equal(kl[3], kr[3]) #check if a list generated from an other has the same kernels with tr and test kl = HPK_generator(X_tr, X_te).make_a_list(n) kr = kernel_list(X_tr, X_te, kl) assert_array_almost_equal(kl[2], kr[2]) assert_array_almost_equal(kl[7], kr[7]) return
def check_concatenation(): #check with 2 HPK kl1 = HPK_generator(X_tr).make_a_list(n) kl2 = HPK_generator(X_tr).make_a_list(n) kl3 = kl1 + kl2 assert_array_equal(kl1[1], kl3[1]) assert_array_equal(kl1[7], kl3[7]) assert_array_equal(kl2[1], kl3[n + 1]) assert_array_equal(kl2[4], kl3[n + 4]) #check with HPK and SFK del kl2, kl3, kl1 kl1 = HPK_generator(X_tr).make_a_list(n) kl2 = SFK_generator(X_tr).make_a_list(n) kl3 = kl1 + kl2 assert_array_equal(kl1[1], kl3[1]) assert_array_equal(kl1[7], kl3[7]) assert_array_equal(kl2[1], kl3[n + 1]) assert_array_equal(kl2[4], kl3[n + 4]) #check iadd del kl2, kl3, kl1 kl1 = SFK_generator(X_tr).make_a_list(n) kl2 = kernel_list(X_tr) kl2 += kl1 assert_array_equal(kl1[3], kl2[3]) assert_array_equal(kl1[9], kl2[9]) kl3 = HPK_generator(X_tr).make_a_list(n) kl2 += kl3 assert_array_equal(kl2[4], kl1[4]) assert_array_equal(kl2[4 + n], kl3[4]) return
def check_SFKs2(): #check a training list kl = SFK_generator(X_tr, func='rbf').make_a_list(20) ka = kl.to_array() assert_array_almost_equal(kl[0], ka[0]) assert_array_almost_equal(kl[3], ka[3]) #check a test list #kt = SFK_generator(X_tr,X_te).make_a_list(10) kt = kernel_list(X_tr, X_te, kl) kb = kt.to_array() assert_array_almost_equal(kt[0], kb[0]) assert_array_almost_equal(kt[3], kb[3]) #test with the selected feature list fl = kl.__getitem__(3, 'feature') k = rbf_kernel(X_tr[:, fl]) assert_array_almost_equal(k, kl[3]) #test with the function in list ff = kl.__getitem__(3, 'func') k = ff(X_tr[:, fl], X_tr[:, fl]) assert_array_equal(k, kl[3]) #check that train and test use the same functions assert_array_equal(kl.__getitem__(2, 'feature'), kt.__getitem__(2, 'feature')) assert_array_equal(kl.__getitem__(7, 'feature'), kt.__getitem__(7, 'feature')) kt.T = X_tr #one trick to assert_array_equal(kt[1], kl[1])
def check_shape(): #check the shape with only tr kl = HPK_generator(X_tr).make_a_list(n) assert_equal(kl.shape, (n, X_tr.shape[0], X_tr.shape[0])) #check the shape with tr and test kl = HPK_generator(X_tr, X_te).make_a_list(n) assert_equal(kl.shape, (n, X_te.shape[0], X_tr.shape[0])) #check the shape with a klist generated from an other kr = kernel_list(X_tr, X_te, kl) assert_equal(kr.shape, (n, X_te.shape[0], X_tr.shape[0])) assert_equal(kl.shape, kr.shape) return
def check_init(): #check if kl can have only tr set as init kl = kernel_list(X_tr) #check if kl can have tr and test as input kl = kernel_list(X_tr, X_te) return