def test_dkwm_mean_one_sample_assertion(self):
        rng = np.random.RandomState(seed=0)
        num_samples = 5000

        # Test that the test assertion agrees that the mean of the standard
        # uniform distribution is 0.5.
        samples = rng.uniform(size=num_samples).astype(np.float32)
        with self.test_session() as sess:
            sess.run(
                st.assert_true_mean_equal_by_dkwm(samples,
                                                  0.,
                                                  1.,
                                                  0.5,
                                                  false_fail_rate=1e-6))

            # Test that the test assertion confirms that the mean of the
            # standard uniform distribution is not 0.4.
            with self.assertRaisesOpError("Mean confidence interval too high"):
                sess.run(
                    st.assert_true_mean_equal_by_dkwm(samples,
                                                      0.,
                                                      1.,
                                                      0.4,
                                                      false_fail_rate=1e-6))

            # Test that the test assertion confirms that the mean of the
            # standard uniform distribution is not 0.6.
            with self.assertRaisesOpError("Mean confidence interval too low"):
                sess.run(
                    st.assert_true_mean_equal_by_dkwm(samples,
                                                      0.,
                                                      1.,
                                                      0.6,
                                                      false_fail_rate=1e-6))
    def test_dkwm_mean_one_sample_assertion(self):
        rng = np.random.RandomState(seed=0)
        num_samples = 5000

        # Test that the test assertion agrees that the mean of the standard
        # uniform distribution is 0.5.
        samples = rng.uniform(size=num_samples).astype(np.float32)
        self.evaluate(
            st.assert_true_mean_equal_by_dkwm(samples,
                                              0.,
                                              1.,
                                              0.5,
                                              false_fail_rate=1e-6))

        # Test that the test assertion confirms that the mean of the
        # standard uniform distribution is not 0.4.
        with self.assertRaisesOpError("true mean greater than expected"):
            self.evaluate(
                st.assert_true_mean_equal_by_dkwm(samples,
                                                  0.,
                                                  1.,
                                                  0.4,
                                                  false_fail_rate=1e-6))

        # Test that the test assertion confirms that the mean of the
        # standard uniform distribution is not 0.6.
        with self.assertRaisesOpError("true mean smaller than expected"):
            self.evaluate(
                st.assert_true_mean_equal_by_dkwm(samples,
                                                  0.,
                                                  1.,
                                                  0.6,
                                                  false_fail_rate=1e-6))
 def testRejection2D(self):
     num_samples = int(1e5)  # Chosen for a small min detectable discrepancy
     det_bounds = np.array(
         [0.01, 0.02, 0.03, 0.04, 0.05, 0.3, 0.35, 0.4, 0.5],
         dtype=np.float32)
     exact_volumes = two_by_two_volume(det_bounds)
     (rej_weights, rej_proposal_volume
      ) = corr.correlation_matrix_volume_rejection_samples(det_bounds,
                                                           2,
                                                           [num_samples, 9],
                                                           dtype=np.float32,
                                                           seed=43)
     # shape of rej_weights: [num_samples, 9, 2, 2]
     chk1 = st.assert_true_mean_equal_by_dkwm(rej_weights,
                                              low=0.,
                                              high=rej_proposal_volume,
                                              expected=exact_volumes,
                                              false_fail_rate=1e-6)
     chk2 = check_ops.assert_less(
         st.min_discrepancy_of_true_means_detectable_by_dkwm(
             num_samples,
             low=0.,
             high=rej_proposal_volume,
             # Correct the false fail rate due to different broadcasting
             false_fail_rate=1.1e-7,
             false_pass_rate=1e-6),
         0.036)
     with ops.control_dependencies([chk1, chk2]):
         rej_weights = array_ops.identity(rej_weights)
     self.evaluate(rej_weights)
 def testRejection4D(self):
     num_samples = int(1e5)  # Chosen for a small min detectable discrepancy
     det_bounds = np.array([0.0], dtype=np.float32)
     exact_volumes = [four_by_four_volume()]
     (rej_weights, rej_proposal_volume
      ) = corr.correlation_matrix_volume_rejection_samples(det_bounds,
                                                           4,
                                                           [num_samples, 1],
                                                           dtype=np.float32,
                                                           seed=45)
     # shape of rej_weights: [num_samples, 1, 4, 4]
     chk1 = st.assert_true_mean_equal_by_dkwm(rej_weights,
                                              low=0.,
                                              high=rej_proposal_volume,
                                              expected=exact_volumes,
                                              false_fail_rate=1e-6)
     chk2 = check_ops.assert_less(
         st.min_discrepancy_of_true_means_detectable_by_dkwm(
             num_samples,
             low=0.,
             high=rej_proposal_volume,
             false_fail_rate=1e-6,
             false_pass_rate=1e-6),
         # Going for about a 10% relative error
         1.1)
     with ops.control_dependencies([chk1, chk2]):
         rej_weights = array_ops.identity(rej_weights)
     self.evaluate(rej_weights)
  def test_dkwm_mean_one_sample_assertion(self):
    rng = np.random.RandomState(seed=0)
    num_samples = 5000

    # Test that the test assertion agrees that the mean of the standard
    # uniform distribution is 0.5.
    samples = rng.uniform(size=num_samples).astype(np.float32)
    with self.test_session() as sess:
      sess.run(st.assert_true_mean_equal_by_dkwm(
          samples, 0., 1., 0.5, false_fail_rate=1e-6))

      # Test that the test assertion confirms that the mean of the
      # standard uniform distribution is not 0.4.
      with self.assertRaisesOpError("Mean confidence interval too high"):
        sess.run(st.assert_true_mean_equal_by_dkwm(
            samples, 0., 1., 0.4, false_fail_rate=1e-6))

      # Test that the test assertion confirms that the mean of the
      # standard uniform distribution is not 0.6.
      with self.assertRaisesOpError("Mean confidence interval too low"):
        sess.run(st.assert_true_mean_equal_by_dkwm(
            samples, 0., 1., 0.6, false_fail_rate=1e-6))
 def testRejection3D(self):
   num_samples = int(1e5)  # Chosen for a small min detectable discrepancy
   det_bounds = np.array([0.0], dtype=np.float32)
   exact_volumes = np.array([three_by_three_volume()], dtype=np.float32)
   (rej_weights,
    rej_proposal_volume) = corr.correlation_matrix_volume_rejection_samples(
        det_bounds, 3, [num_samples, 1], dtype=np.float32, seed=44)
   # shape of rej_weights: [num_samples, 1, 3, 3]
   chk1 = st.assert_true_mean_equal_by_dkwm(
       rej_weights, low=0., high=rej_proposal_volume, expected=exact_volumes,
       false_fail_rate=1e-6)
   chk2 = check_ops.assert_less(
       st.min_discrepancy_of_true_means_detectable_by_dkwm(
           num_samples, low=0., high=rej_proposal_volume,
           false_fail_rate=1e-6, false_pass_rate=1e-6),
       # Going for about a 3% relative error
       0.15)
   with ops.control_dependencies([chk1, chk2]):
     rej_weights = array_ops.identity(rej_weights)
   self.evaluate(rej_weights)
 def testRejection2D(self):
   num_samples = int(1e5)  # Chosen for a small min detectable discrepancy
   det_bounds = np.array(
       [0.01, 0.02, 0.03, 0.04, 0.05, 0.3, 0.35, 0.4, 0.5], dtype=np.float32)
   exact_volumes = two_by_two_volume(det_bounds)
   (rej_weights,
    rej_proposal_volume) = corr.correlation_matrix_volume_rejection_samples(
        det_bounds, 2, [num_samples, 9], dtype=np.float32, seed=43)
   # shape of rej_weights: [num_samples, 9, 2, 2]
   chk1 = st.assert_true_mean_equal_by_dkwm(
       rej_weights, low=0., high=rej_proposal_volume, expected=exact_volumes,
       false_fail_rate=1e-6)
   chk2 = check_ops.assert_less(
       st.min_discrepancy_of_true_means_detectable_by_dkwm(
           num_samples, low=0., high=rej_proposal_volume,
           # Correct the false fail rate due to different broadcasting
           false_fail_rate=1.1e-7, false_pass_rate=1e-6),
       0.036)
   with ops.control_dependencies([chk1, chk2]):
     rej_weights = array_ops.identity(rej_weights)
   self.evaluate(rej_weights)