Esempio n. 1
0
    def testSmoothSVMth_functional(self):

        F = Topk_Smooth_SVM(self.labels, self.k, self.tau)
        res_th = F(V(self.x), V(self.y))
        res_py = svm_topk_smooth_py_1(V(self.x), V(self.y), self.tau, self.k)

        assert_all_close(res_th, res_py)
Esempio n. 2
0
 def testSmoothSVMth_loss_scales(self):
     svm_topk_smooth_th = SmoothTopkSVM(self.n_classes, tau=self.tau, k=self.k)
     for scale in (1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3):
         x = self.x * scale
         res_th = svm_topk_smooth_th(V(x), V(self.y))
         res_py = svm_topk_smooth_py_1(V(x), V(self.y), self.tau, self.k).mean()
         assert_all_close(res_th, res_py)
Esempio n. 3
0
    def testSmoothSVMth_loss(self):
        for k in range(2, self.k + 1):
            svm_topk_smooth_th = SmoothTopkSVM(self.n_classes, tau=self.tau, k=k)
            res_th = svm_topk_smooth_th(V(self.x), V(self.y))
            res_py = svm_topk_smooth_py_1(V(self.x), V(self.y),
                                          self.tau, k).mean()

            assert_all_close(res_th, res_py)
Esempio n. 4
0
    def testSmoothSVMpy(self):

        res_py_1 = svm_topk_smooth_py_1(V(self.x), V(self.y), self.tau, self.k)
        res_py_2 = svm_topk_smooth_py_2(V(self.x), V(self.y), self.tau, self.k)

        assert_all_close(res_py_1, res_py_2)