def mut_inf(m1,m2): from pyinform import utils, mutual_info # Bin Timeseries bined1,number1,width1 = utils.bin_series(m1, b=20) bined2,number2,width2 = utils.bin_series(m2, b=20) # Compute mutual info between time courses m_info = [] for tc1,tc2 in zip(bined1,bined2): m_info.append(mutual_info(tc1, tc2)) m_info = np.array(m_info) return m_info
def test_bin_2D(self): binned, _, _ = bin_series([[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1]], b=3) self.assertTrue(([[0, 0, 1, 1, 2, 2], [2, 2, 1, 1, 0, 0]] == binned).all()) binned, _, _ = bin_series([[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1]], step=2.0) self.assertTrue(([[0, 0, 1, 1, 2, 2], [2, 2, 1, 1, 0, 0]] == binned).all()) binned, _, _ = bin_series([[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1]], bounds=[2.5, 4.5]) self.assertTrue(([[0, 0, 1, 1, 2, 2], [2, 2, 1, 1, 0, 0]] == binned).all())
def test_keyword_args(self): with self.assertRaises(ValueError): bin_series([1, 2, 3, 4]) with self.assertRaises(ValueError): bin_series([1, 2, 3, 4], b=2, step=2) with self.assertRaises(ValueError): bin_series([1, 2, 3, 4], b=2, bounds=[]) with self.assertRaises(ValueError): bin_series([1, 2, 3, 4], step=2, bounds=[])
def test_empty(self): with self.assertRaises(InformError): bin_series([], b=2) with self.assertRaises(InformError): bin_series([], step=2) with self.assertRaises(InformError): bin_series([], bounds=[0.5])
def test_size_one(self): binned, b, _ = bin_series([1, 2, 3, 4, 5, 6], step=1.) self.assertEqual(6, b) for i, x in enumerate([0, 1, 2, 3, 4, 5]): self.assertEqual(x, binned[i])
def test_size_fivehalves(self): binned, b, _ = bin_series([1, 2, 3, 4, 5, 6], step=5. / 2.) self.assertEqual(3, b) for i, x in enumerate([0, 0, 0, 1, 1, 2]): self.assertEqual(x, binned[i])
def test_size_two(self): binned, b, _ = bin_series([1, 2, 3, 4, 5, 6], step=2.0) self.assertEqual(3, b) for i, x in enumerate([0, 0, 1, 1, 2, 2]): self.assertEqual(x, binned[i])
def test_six_bins(self): binned, _, step = bin_series([1, 2, 3, 4, 5, 6], b=6) self.assertAlmostEqual(5. / 6., step) for i, x in enumerate([0, 1, 2, 3, 4, 5]): self.assertEqual(x, binned[i])
def test_three_bins(self): binned, _, step = bin_series([1, 2, 3, 4, 5, 6], b=3) self.assertAlmostEqual(5. / 3., step) for i, x in enumerate([0, 0, 1, 1, 2, 2]): self.assertEqual(x, binned[i])
def test_invalid_binning(self): with self.assertRaises(InformError): bin_series([1, 2, 3, 4, 5, 6], b=-1) with self.assertRaises(InformError): bin_series([1, 2, 3, 4, 5, 6], b=0) with self.assertRaises(InformError): bin_series([1, 2, 3, 4, 5, 6], b=1) with self.assertRaises(InformError): bin_series([1, 2, 3, 4, 5, 6], step=-1) with self.assertRaises(InformError): bin_series([1, 2, 3, 4, 5, 6], step=0) with self.assertRaises(InformError): bin_series([1, 2, 3, 4, 5, 6], bounds=[])
def test_bounds_all(self): binned, b, _ = bin_series([1, 2, 3, 4, 5, 6], bounds=[0.0]) self.assertEqual(2, b) for i, x in enumerate([1, 1, 1, 1, 1, 1]): self.assertEqual(x, binned[i])
def test_bounds_none(self): binned, b, _ = bin_series([1, 2, 3, 4, 5, 6], bounds=[6.1]) self.assertEqual(1, b) for i, x in enumerate([0, 0, 0, 0, 0, 0]): self.assertEqual(x, binned[i])
def test_two_bounds(self): binned, b, _ = bin_series([1, 2, 3, 4, 5, 6], bounds=[2.5, 5.5]) self.assertEqual(3, b) for i, x in enumerate([0, 0, 1, 1, 1, 2]): self.assertEqual(x, binned[i])
def test_one_bound(self): binned, b, _ = bin_series([1, 2, 3, 4, 5, 6], bounds=[3]) self.assertEqual(2, b) for i, x in enumerate([0, 0, 1, 1, 1, 1]): self.assertEqual(x, binned[i])
def test_size_half(self): binned, b, _ = bin_series([1, 2, 3, 4, 5, 6], step=0.5) self.assertEqual(11, b) for i, x in enumerate([0, 2, 4, 6, 8, 10]): self.assertEqual(x, binned[i])