def _log_abs_determinant(self):
    if self._is_spd:
      diag = array_ops.matrix_diag_part(self._chol)
      return 2 * math_ops.reduce_sum(math_ops.log(diag), reduction_indices=[-1])

    if self.dtype.is_complex:
      abs_det = math_ops.complex_abs(self.determinant())
    else:
      abs_det = math_ops.abs(self.determinant())
    return math_ops.log(abs_det)
  def _assert_non_singular(self):
    if self.dtype.is_complex:
      should_be_nonzero = math_ops.complex_abs(self._diag)
    else:
      should_be_nonzero = self._diag

    nonzero_diag = math_ops.reduce_all(
        math_ops.logical_not(math_ops.equal(should_be_nonzero, 0)))

    return control_flow_ops.Assert(
        nonzero_diag,
        data=["Singular operator: diag contained zero values.", self._diag])
예제 #3
0
    def _assert_non_singular(self):
        if self.dtype.is_complex:
            should_be_nonzero = math_ops.complex_abs(self._diag)
        else:
            should_be_nonzero = self._diag

        nonzero_diag = math_ops.reduce_all(
            math_ops.logical_not(math_ops.equal(should_be_nonzero, 0)))

        return control_flow_ops.Assert(
            nonzero_diag,
            data=[
                "Singular operator: diag contained zero values.", self._diag
            ])
예제 #4
0
    def _testGrad(self, shape, dtype=None, max_error=None, bias=None, sigma=None):
        np.random.seed(7)
        if dtype in (dtypes.complex64, dtypes.complex128):
            value = math_ops.complex(
                self._biasedRandN(shape, bias=bias, sigma=sigma), self._biasedRandN(shape, bias=bias, sigma=sigma)
            )
        else:
            value = ops.convert_to_tensor(self._biasedRandN(shape, bias=bias), dtype=dtype)

        with self.test_session(use_gpu=True):
            if dtype in (dtypes.complex64, dtypes.complex128):
                output = math_ops.complex_abs(value)
            else:
                output = math_ops.abs(value)
            error = gradient_checker.compute_gradient_error(value, shape, output, output.get_shape().as_list())
        self.assertLess(error, max_error)
예제 #5
0
  def _testGrad(self, shape, dtype=None, max_error=None, bias=None, sigma=None):
    np.random.seed(7)
    if dtype in (dtypes.complex64, dtypes.complex128):
      value = math_ops.complex(
          self._biasedRandN(
              shape, bias=bias, sigma=sigma),
          self._biasedRandN(
              shape, bias=bias, sigma=sigma))
    else:
      value = ops.convert_to_tensor(
          self._biasedRandN(
              shape, bias=bias), dtype=dtype)

    with self.test_session(use_gpu=True):
      if dtype in (dtypes.complex64, dtypes.complex128):
        output = math_ops.complex_abs(value)
      else:
        output = math_ops.abs(value)
      error = gradient_checker.compute_gradient_error(
          value, shape, output, output.get_shape().as_list())
    self.assertLess(error, max_error)
def assert_no_entries_with_modulus_zero(
    x, message=None, name="assert_no_entries_with_modulus_zero"):
  """Returns `Op` that asserts Tensor `x` has no entries with modulus zero.

  Args:
    x:  Numeric `Tensor`, real, integer, or complex.
    message:  A string message to prepend to failure message.
    name:  A name to give this `Op`.

  Returns:
    An `Op` that asserts `x` has no entries with modulus zero.
  """
  with ops.name_scope(name, values=[x]):
    x = ops.convert_to_tensor(x, name="x")
    dtype = x.dtype.base_dtype

    if dtype.is_complex:
      should_be_nonzero = math_ops.complex_abs(x)
    else:
      should_be_nonzero = math_ops.abs(x)

    zero = ops.convert_to_tensor(0, dtype=dtype.real_dtype)

    return check_ops.assert_less(zero, should_be_nonzero, message=message)
예제 #7
0
def assert_no_entries_with_modulus_zero(
        x, message=None, name="assert_no_entries_with_modulus_zero"):
    """Returns `Op` that asserts Tensor `x` has no entries with modulus zero.

  Args:
    x:  Numeric `Tensor`, real, integer, or complex.
    message:  A string message to prepend to failure message.
    name:  A name to give this `Op`.

  Returns:
    An `Op` that asserts `x` has no entries with modulus zero.
  """
    with ops.name_scope(name, values=[x]):
        x = ops.convert_to_tensor(x, name="x")
        dtype = x.dtype.base_dtype

        if dtype.is_complex:
            should_be_nonzero = math_ops.complex_abs(x)
        else:
            should_be_nonzero = math_ops.abs(x)

        zero = ops.convert_to_tensor(0, dtype=dtype.real_dtype)

        return check_ops.assert_less(zero, should_be_nonzero, message=message)