def test_suppress_warnings(self): bad_log_dir = "path/to/bad_log/dir/zxc8aj3n" with captured_output() as out: self.prob.solve(self.prob.compute_max_l1_penalty(), log_directory=bad_log_dir) self.assertIn("Warning", out[0]) blitzml.suppress_warnings() with captured_output() as out: self.prob.solve(self.prob.compute_max_l1_penalty(), log_directory=bad_log_dir) self.assertNotIn("Warning", out[0]) blitzml.unsuppress_warnings()
def test_sparse_logreg_all_positive_labels_warning(self): b = np.array([0., 1.0, 0.5]) A = np.zeros((3, 3)) with captured_output() as out: prob = blitzml.SparseLogisticRegressionProblem(A, b) message = out[0] self.assertIn("Warning", message)
def test_sparse_logreg_bad_label_too_small(self): b = np.array([-1., 0., -2.]) A = np.zeros((3, 3)) with captured_output() as out: prob = blitzml.SparseLogisticRegressionProblem(A, b) message = out[0] self.assertIn("Warning", message)
def test_lasso_empty(self): A = sp.csc_matrix((100, 1000)) b = np.ones(100) with captured_output() as out: prob = blitzml.LassoProblem(A, b) self.assertEqual(prob.compute_max_l1_penalty(), 0.) sol = prob.solve(0.) self.assertEqual(np.linalg.norm(sol.weights), 0.) self.assertEqual(sol.bias, 1.0) self.assertEqual(sol.objective_value, 0.) self.assertEqual(sol.duality_gap, 0.)
def setUp(self): A = np.array([[2]], dtype=np.float) b = np.array([10], dtype=np.double) with captured_output() as out: self.prob = blitzml.LassoProblem(A, b)
def test_lasso_csr_matrix_warning(self): self.A = sp.csr_matrix(self.A) with captured_output() as out: prob = blitzml.LassoProblem(self.A, self.b) message = out[0] self.assertTrue("Warning" in message)
def test_lasso_dense_copy_warning_F_contiguous(self): self.A = np.asfortranarray(self.A) with captured_output() as out: prob = blitzml.LassoProblem(self.A, self.b) message = out[0] self.assertTrue("Warning" not in message)