def random_positive_definite_matrix(shape,
                                    dtype,
                                    force_well_conditioned=False):
    """[batch] positive definite matrix.

  Args:
    shape:  `TensorShape` or Python list.  Shape of the returned matrix.
    dtype:  `TensorFlow` `dtype` or Python dtype.
    force_well_conditioned:  Python bool.  If `True`, returned matrix has
      eigenvalues with modulus in `(1, 4)`.  Otherwise, eigenvalues are
      chi-squared random variables.

  Returns:
    `Tensor` with desired shape and dtype.
  """
    dtype = dtypes.as_dtype(dtype)
    if not contrib_tensor_util.is_tensor(shape):
        shape = tensor_shape.TensorShape(shape)
        # Matrix must be square.
        shape[-1].assert_is_compatible_with(shape[-2])

    with ops.name_scope("random_positive_definite_matrix"):
        tril = random_tril_matrix(
            shape, dtype, force_well_conditioned=force_well_conditioned)
        return math_ops.matmul(tril, tril, adjoint_b=True)
예제 #2
0
def random_positive_definite_matrix(shape, dtype, force_well_conditioned=False):
    """[batch] positive definite matrix.

  Args:
    shape:  `TensorShape` or Python list.  Shape of the returned matrix.
    dtype:  `TensorFlow` `dtype` or Python dtype.
    force_well_conditioned:  Python bool.  If `True`, returned matrix has
      eigenvalues with modulus in `(1, 4)`.  Otherwise, eigenvalues are
      chi-squared random variables.

  Returns:
    `Tensor` with desired shape and dtype.
  """
    dtype = dtypes.as_dtype(dtype)
    if not contrib_tensor_util.is_tensor(shape):
        shape = tensor_shape.TensorShape(shape)
        # Matrix must be square.
        shape[-1].assert_is_compatible_with(shape[-2])

    with ops.name_scope("random_positive_definite_matrix"):
        tril = random_tril_matrix(shape, dtype, force_well_conditioned=force_well_conditioned)
        return math_ops.matmul(tril, tril, adjoint_b=True)