Esempio n. 1
0
    def _cond(self):
        if not self.is_self_adjoint:
            # In general the condition number is the ratio of the
            # absolute value of the largest and smallest singular values.
            vals = linalg_ops.svd(self.to_dense(), compute_uv=False)
        else:
            # For self-adjoint matrices, and in general normal matrices,
            # we can use eigenvalues.
            vals = math_ops.abs(self._eigvals())

        return (math_ops.reduce_max(vals, axis=-1) /
                math_ops.reduce_min(vals, axis=-1))
 def _assert_non_singular(self):
     """Private default implementation of _assert_non_singular."""
     logging.warn(
         "Using (possibly slow) default implementation of assert_non_singular."
         "  Requires conversion to a dense matrix and O(N^3) operations.")
     if self._can_use_cholesky():
         return self.assert_positive_definite()
     else:
         singular_values = linalg_ops.svd(self.to_dense(), compute_uv=False)
         # TODO(langmore) Add .eig and .cond as methods.
         cond = (math_ops.reduce_max(singular_values, axis=-1) /
                 math_ops.reduce_min(singular_values, axis=-1))
         return check_ops.assert_less(
             cond,
             self._max_condition_number_to_be_non_singular(),
             message="Singular matrix up to precision epsilon.")
 def _min_matrix_dim_tensor(self):
     """Minimum of domain/range dimension, as a tensor."""
     return math_ops.reduce_min(self.shape_tensor()[-2:])
Esempio n. 4
0
 def _cond(self):
     abs_diag = math_ops.abs(self.diag)
     return (math_ops.reduce_max(abs_diag, axis=-1) /
             math_ops.reduce_min(abs_diag, axis=-1))