Exemple #1
0
 def test_pdf2pmf_ndarray_matrices(self):
     p1 = np.array([1.0])
     p2 = np.array([0.1, 1.0])
     p3 = np.array([0.4, 0.4, 0.7, 1.0])
     p23 = np.array([[0.2, 0.3, 1.0], [0.4, 0.4, 1.0]])
     self.assertTrue(qumo.almost_equal(qumo.pdf2pmf(p1), [1.0]))
     self.assertTrue(qumo.almost_equal(qumo.pdf2pmf(p2), [0.1, 0.9]))
     self.assertTrue(qumo.almost_equal(qumo.pdf2pmf(p3),
                                       [0.4, 0.0, 0.3, 0.3]))
     self.assertTrue(qumo.almost_equal(qumo.pdf2pmf(p23),
                                       [[0.2, 0.1, 0.7], [0.4, 0.0, 0.6]]))
Exemple #2
0
 def test_pdf2pmf_list_matrices(self):
     p1 = [1.0]
     p2 = [0.1, 1.0]
     p3 = [0.4, 0.4, 0.7, 1.0]
     p23 = [[0.2, 0.3, 1.0], [0.4, 0.4, 1.0]]
     self.assertTrue(qumo.almost_equal(qumo.pdf2pmf(p1), [1.0]))
     self.assertTrue(qumo.almost_equal(qumo.pdf2pmf(p2), [0.1, 0.9]))
     self.assertTrue(qumo.almost_equal(qumo.pdf2pmf(p3),
                                       [0.4, 0.0, 0.3, 0.3]))
     self.assertTrue(qumo.almost_equal(qumo.pdf2pmf(p23),
                                       [[0.2, 0.1, 0.7], [0.4, 0.0, 0.6]]))
Exemple #3
0
 def test_compare_ndarrays_and_lists(self):
     a1 = np.array([1])
     a2 = np.array([1, 2])
     a12 = np.array([[1, 2]])
     a22 = np.array([[1, 2], [3, 4]])
     self.assertTrue(qumo.almost_equal(a1, [1]))
     self.assertTrue(qumo.almost_equal(a1, [0.95], 0.1))
     self.assertTrue(qumo.almost_equal(a2, [1, 2]))
     self.assertTrue(qumo.almost_equal(a2, [0.9, 2.1], 0.11))
     self.assertTrue(qumo.almost_equal(a12, [[1, 2]]))
     self.assertTrue(qumo.almost_equal(a12, [[0.9, 2.1]], 0.11))
     self.assertTrue(qumo.almost_equal(a22, [[1, 2], [3, 4]]))
     self.assertTrue(qumo.almost_equal(a22, [[1.2, 2], [3.1, 3.8]], 0.21))
Exemple #4
0
 def test_compare_lists(self):
     a1 = [1]
     a2 = [1, 2]
     a12 = [[1, 2]]
     a22 = [[1, 2], [3, 4]]
     self.assertTrue(qumo.almost_equal(a1, [1]))
     self.assertTrue(qumo.almost_equal(a1, [0.95], 0.1))
     self.assertTrue(qumo.almost_equal(a2, [1, 2]))
     self.assertTrue(qumo.almost_equal(a2, [0.9, 2.1], 0.11))
     self.assertTrue(qumo.almost_equal(a12, [[1, 2]]))
     self.assertTrue(qumo.almost_equal(a12, [[0.9, 2.1]], 0.11))
     self.assertTrue(qumo.almost_equal(a22, [[1, 2], [3, 4]]))
     self.assertTrue(qumo.almost_equal(a22, [[1.2, 2], [3.1, 3.8]], 0.21))
Exemple #5
0
 def test_parse_array_with_correct_strings(self):
     s0 = ''
     s1 = '1,2'
     s1ws = '    1   ,\n\t  2\t'
     s21 = '1;2'
     s21ws = '\n 1\t \n;\n \t 2\n'
     s22 = '1;2 : 3; 4.5'
     self.assertTrue(qumo.almost_equal(qumo.parse_array(s0), []))
     self.assertTrue(qumo.almost_equal(qumo.parse_array(s1, ','), [1, 2]))
     self.assertTrue(qumo.almost_equal(qumo.parse_array(s1ws, ','), [1, 2]))
     self.assertTrue(qumo.almost_equal(qumo.parse_array(s21, ',', ';'),
                                       [[1], [2]]))
     self.assertTrue(qumo.almost_equal(qumo.parse_array(s21ws, ',', ';'),
                                       [[1], [2]]))
     self.assertTrue(qumo.almost_equal(qumo.parse_array(s22, ';', ':'),
                                       [[1.0, 2.0], [3.0, 4.5]]))