Exemple #1
0
    def test_dkwm_mean_two_sample_assertion(self):
        rng = np.random.RandomState(seed=0)
        num_samples = 15000

        # 15000 samples is chosen to be enough to find discrepancies of
        # size 0.1 or more with assurance 1e-6, as confirmed here:
        with self.test_session() as sess:
            d = st.min_discrepancy_of_true_means_detectable_by_dkwm_two_sample(
                num_samples,
                0.,
                1.,
                num_samples,
                0.,
                1.,
                false_fail_rate=1e-6,
                false_pass_rate=1e-6)
            d = sess.run(d)
            self.assertLess(d, 0.1)

        # Test that the test assertion agrees that the standard
        # uniform distribution has the same mean as itself.
        samples1 = rng.uniform(size=num_samples).astype(np.float32)
        samples2 = rng.uniform(size=num_samples).astype(np.float32)
        with self.test_session() as sess:
            sess.run(
                st.assert_true_mean_equal_by_dkwm_two_sample(
                    samples1, 0., 1., samples2, 0., 1., false_fail_rate=1e-6))

            # Test that the test assertion confirms that the mean of the
            # standard uniform distribution is different from the mean of beta(2, 1).
            beta_high_samples = rng.beta(2, 1,
                                         size=num_samples).astype(np.float32)
            with self.assertRaises(errors.InvalidArgumentError):
                sess.run(
                    st.assert_true_mean_equal_by_dkwm_two_sample(
                        samples1,
                        0.,
                        1.,
                        beta_high_samples,
                        0.,
                        1.,
                        false_fail_rate=1e-6))

            # Test that the test assertion confirms that the mean of the
            # standard uniform distribution is different from the mean of beta(1, 2).
            beta_low_samples = rng.beta(1, 2,
                                        size=num_samples).astype(np.float32)
            with self.assertRaises(errors.InvalidArgumentError):
                sess.run(
                    st.assert_true_mean_equal_by_dkwm_two_sample(
                        samples1,
                        0.,
                        1.,
                        beta_low_samples,
                        0.,
                        1.,
                        false_fail_rate=1e-6))
    def test_dkwm_mean_two_sample_assertion(self):
        rng = np.random.RandomState(seed=0)
        num_samples = 4000

        # 4000 samples is chosen to be enough to find discrepancies of
        # size 0.2 or more with assurance 1e-6, as confirmed here:
        with self.test_session() as sess:
            d = st.min_discrepancy_of_true_means_detectable_by_dkwm_two_sample(
                num_samples,
                0.,
                1.,
                num_samples,
                0.,
                1.,
                false_fail_rate=1e-6,
                false_pass_rate=1e-6)
            d = sess.run(d)
            self.assertLess(d, 0.2)

        # Test that the test assertion agrees that the standard
        # uniform distribution has the same mean as itself.
        samples1 = rng.uniform(size=num_samples).astype(np.float32)
        samples2 = rng.uniform(size=num_samples).astype(np.float32)
        with self.test_session() as sess:
            sess.run(
                st.assert_true_mean_equal_by_dkwm_two_sample(
                    samples1, 0., 1., samples2, 0., 1., false_fail_rate=1e-6))
  def test_dkwm_mean_two_sample_assertion(self):
    rng = np.random.RandomState(seed=0)
    num_samples = 15000

    # 15000 samples is chosen to be enough to find discrepancies of
    # size 0.1 or more with assurance 1e-6, as confirmed here:
    with self.test_session() as sess:
      d = st.min_discrepancy_of_true_means_detectable_by_dkwm_two_sample(
          num_samples, 0., 1., num_samples, 0., 1.,
          false_fail_rate=1e-6, false_pass_rate=1e-6)
      d = sess.run(d)
      self.assertLess(d, 0.1)

    # Test that the test assertion agrees that the standard
    # uniform distribution has the same mean as itself.
    samples1 = rng.uniform(size=num_samples).astype(np.float32)
    samples2 = rng.uniform(size=num_samples).astype(np.float32)
    with self.test_session() as sess:
      sess.run(st.assert_true_mean_equal_by_dkwm_two_sample(
          samples1, 0., 1., samples2, 0., 1., false_fail_rate=1e-6))

      # Test that the test assertion confirms that the mean of the
      # standard uniform distribution is different from the mean of beta(2, 1).
      beta_high_samples = rng.beta(2, 1, size=num_samples).astype(np.float32)
      with self.assertRaises(errors.InvalidArgumentError):
        sess.run(st.assert_true_mean_equal_by_dkwm_two_sample(
            samples1, 0., 1.,
            beta_high_samples, 0., 1.,
            false_fail_rate=1e-6))

      # Test that the test assertion confirms that the mean of the
      # standard uniform distribution is different from the mean of beta(1, 2).
      beta_low_samples = rng.beta(1, 2, size=num_samples).astype(np.float32)
      with self.assertRaises(errors.InvalidArgumentError):
        sess.run(st.assert_true_mean_equal_by_dkwm_two_sample(
            samples1, 0., 1.,
            beta_low_samples, 0., 1.,
            false_fail_rate=1e-6))
  def test_dkwm_mean_two_sample_assertion_beta_1_2_false(self):
    rng = np.random.RandomState(seed=0)
    num_samples = 4000
    samples1 = rng.uniform(size=num_samples).astype(np.float32)

    # As established above, 4000 samples is enough to find discrepancies
    # of size 0.2 or more with assurance 1e-6.

    with self.test_session() as sess:
      # Test that the test assertion confirms that the mean of the
      # standard uniform distribution is different from the mean of beta(1, 2).
      beta_low_samples = rng.beta(1, 2, size=num_samples).astype(np.float32)
      with self.assertRaisesOpError("samples2 has a smaller mean"):
        sess.run(st.assert_true_mean_equal_by_dkwm_two_sample(
            samples1, 0., 1.,
            beta_low_samples, 0., 1.,
            false_fail_rate=1e-6))
  def test_dkwm_mean_two_sample_assertion(self):
    rng = np.random.RandomState(seed=0)
    num_samples = 4000

    # 4000 samples is chosen to be enough to find discrepancies of
    # size 0.2 or more with assurance 1e-6, as confirmed here:
    with self.test_session() as sess:
      d = st.min_discrepancy_of_true_means_detectable_by_dkwm_two_sample(
          num_samples, 0., 1., num_samples, 0., 1.,
          false_fail_rate=1e-6, false_pass_rate=1e-6)
      d = sess.run(d)
      self.assertLess(d, 0.2)

    # Test that the test assertion agrees that the standard
    # uniform distribution has the same mean as itself.
    samples1 = rng.uniform(size=num_samples).astype(np.float32)
    samples2 = rng.uniform(size=num_samples).astype(np.float32)
    with self.test_session() as sess:
      sess.run(st.assert_true_mean_equal_by_dkwm_two_sample(
          samples1, 0., 1., samples2, 0., 1., false_fail_rate=1e-6))
    def test_dkwm_mean_two_sample_assertion_beta_1_2_false(self):
        rng = np.random.RandomState(seed=0)
        num_samples = 4000
        samples1 = rng.uniform(size=num_samples).astype(np.float32)

        # As established above, 4000 samples is enough to find discrepancies
        # of size 0.2 or more with assurance 1e-6.

        # Test that the test assertion confirms that the mean of the
        # standard uniform distribution is different from the mean of beta(1, 2).
        beta_low_samples = rng.beta(1, 2, size=num_samples).astype(np.float32)
        with self.assertRaisesOpError("true mean greater than expected"):
            self.evaluate(
                st.assert_true_mean_equal_by_dkwm_two_sample(
                    samples1,
                    0.,
                    1.,
                    beta_low_samples,
                    0.,
                    1.,
                    false_fail_rate=1e-6))
    def test_dkwm_mean_two_sample_assertion_beta_2_1_false(self):
        rng = np.random.RandomState(seed=0)
        num_samples = 4000
        samples1 = rng.uniform(size=num_samples).astype(np.float32)

        # As established above, 4000 samples is enough to find discrepancies
        # of size 0.2 or more with assurance 1e-6.

        with self.test_session() as sess:
            # Test that the test assertion confirms that the mean of the
            # standard uniform distribution is different from the mean of beta(2, 1).
            beta_high_samples = rng.beta(2, 1,
                                         size=num_samples).astype(np.float32)
            with self.assertRaisesOpError("samples1 has a smaller mean"):
                sess.run(
                    st.assert_true_mean_equal_by_dkwm_two_sample(
                        samples1,
                        0.,
                        1.,
                        beta_high_samples,
                        0.,
                        1.,
                        false_fail_rate=1e-6))