def test_converge3(self): w_solved_vec, is_converged_bool = cg_cond.cg_cond(x_mat, y_vec, t3_mat) dist_vec = numpy.dot( x_mat, w_opt_vec - w_solved_vec.reshape(len(w_solved_vec), 1)) err = numpy.sum(dist_vec**2) print('Squared norm error of CG (tolerance=1e-3):' + str(err)) self.assertTrue(err < 1e-10)
def test_margin(self): w_solved_vec, is_converged_bool = cg_cond.cg_cond(x_mat, y_vec, t3_mat, tol=1e-10, max_iter_int=0) self.assertTrue(not is_converged_bool) w_solved_vec, is_converged_bool = cg_cond.cg_cond(x_mat, y_vec, t3_mat, tol=1e-10, max_iter_int=1) self.assertTrue(not is_converged_bool) w_solved_vec, is_converged_bool = cg_cond.cg_cond(x_mat, y_vec, t3_mat, tol=1e-10, max_iter_int=2) self.assertTrue(not is_converged_bool)