Пример #1
0
 def test_empty_arrays(self):
     """Check that computing the IB on a pair of empty arrays raises an exception"""
     for alpha in self.alphas:
         with self.subTest(alpha=alpha):
              with self.assertRaises(
                     ValueError,
                     msg="If pxy is not specified, x and y can't be empty."):
                  eb = embo.InformationBottleneck(self.empty, self.empty, alpha=alpha)
Пример #2
0
 def test_array_with_inf(self):
     """Check that an error is raised in presence of infinities"""
     for alpha in self.alphas:
         with self.subTest(alpha=alpha):
             with self.assertRaises(
                     ValueError,
                     msg="The observation data contains NaNs or Infs."):
                 embo.InformationBottleneck(self.x_with_inf, self.y, alpha=alpha)
Пример #3
0
def test_asymptote(x, y, maxbeta=30, alpha=1):
    """Check that the IB/DIB bound saturates at MI(X:Y) for large beta.

    This should be true with the default setting that the cardinality
    of M is the same as that of X.
    
    Note that the reference value of MI(X,Y) is computed using embo's
    internal facility for this.

    """
    eb = embo.InformationBottleneck(x, y, maxbeta=maxbeta, alpha=alpha)
    i_y = eb.get_iy()
    mi = eb.get_saturation_point()
    np.testing.assert_allclose(i_y[-1], mi, rtol=1e-7, atol=1e-6)
Пример #4
0
 def test_random_distributions(self):
     """Run IB/DIB on many random distributions of various shapes and check β→∞ limit"""
     for X in range(2, self.Xmax):
         for Y in range(2, self.Ymax):
             for alpha in self.alphas:
                 with self.subTest(X=X, Y=Y, alpha=alpha):
                     for each in range(self.N):
                         #pxy = self.rng.dirichlet(np.full(X*Y,1/2)).reshape(X,Y)
                         pxy = self.sample_pxy(X,Y)
                         eb = embo.InformationBottleneck(pxy=pxy, maxbeta=20, numbeta=5, alpha=alpha, restarts=10, rtol=1e-5, iterations=1000, ensure_monotonic_bound=False)
                         ix, iy, hm, _, ixy, hx, hy = eb.get_bottleneck(return_entropies=True)
                         self.assertTrue(
                             # note the relatively large
                             # tolerances: they help ignoring
                             # uninteresting cases where I(X:Y) is
                             # very small
                             np.testing.assert_allclose(iy[-1], ixy, rtol=1e-1, atol=1e-1) is None,
                             msg='Check asymptote')
Пример #5
0
def test_origin(x, y, alpha=1):
    """Check that the IB bound starts at (0,0) for small beta"""
    eb = embo.InformationBottleneck(x, y, alpha=alpha)
    i_x = eb.get_ix()
    i_y = eb.get_iy()
    np.testing.assert_allclose((i_x[0], i_y[0]), (0,0), rtol=1e-7, atol=1e-6)