예제 #1
0
    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()
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 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.)
예제 #5
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)
예제 #6
0
 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)
예제 #7
0
 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)