Example #1
0
 def test_quality(self):
     for _ in range(100):
         one_prob = np.random.uniform(0.1, 0.9)
         nrows = np.random.randint(1, 30)
         ncols = np.random.randint(1, 8)
         arr = np.random.uniform(0, 1, size=(nrows, ncols)) < one_prob
         permutation = run_randomized_greedy_algorithm(arr)
         target = get_total_gaps_in_rows(arr[:, permutation])
         best_permutation = find_best_columns_permutation_bruteforce(arr)
         best_target = get_total_gaps_in_rows(arr[:, best_permutation])
         self.assertLessEqual((target - best_target), 0.3 * best_target + 1)
Example #2
0
 def test_all_ones(self):
     """
     Test that the number of runs of a matrix of ones is equal to the number of rows.
     """
     arr = np.ones((7, 3), dtype=bool)
     gaps_count = get_total_gaps_in_rows(arr)
     self.assertEqual(gaps_count, 0)
Example #3
0
 def test_all_zeros(self):
     """
     Test that number of runs of a zero matrix is zero
     """
     arr = np.zeros((2, 3), dtype=bool)
     gaps_count = get_total_gaps_in_rows(arr)
     self.assertEqual(gaps_count, 0)
Example #4
0
 def test_one_col(self):
     """
     Test that the number of runs of a matrix with one col is equal to the number of ones
     """
     rows_count = 100
     arr = np.random.randint(0, 2, size=(rows_count, 1))
     gaps_count = get_total_gaps_in_rows(arr)
     self.assertEqual(gaps_count, 0)
Example #5
0
 def test_nontrivial_two(self):
     arr = np.array([[1, 0, 0, 0],
                     [0, 0, 0, 1],
                     [0, 0, 0, 1]])
     gaps_count = get_total_gaps_in_rows(arr)
     self.assertEqual(gaps_count, 0)