MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / pinv

Function pinv

tensorflow/python/ops/linalg/linalg_impl.py:698–823  ·  view source on GitHub ↗

Compute the Moore-Penrose pseudo-inverse of one or more matrices. Calculate the [generalized inverse of a matrix]( https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse) using its singular-value decomposition (SVD) and including all large singular values. The pseudo-inverse of a matr

(a, rcond=None, validate_args=False, name=None)

Source from the content-addressed store, hash-verified

696
697@tf_export('linalg.pinv')
698def pinv(a, rcond=None, validate_args=False, name=None):
699 """Compute the Moore-Penrose pseudo-inverse of one or more matrices.
700
701 Calculate the [generalized inverse of a matrix](
702 https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse) using its
703 singular-value decomposition (SVD) and including all large singular values.
704
705 The pseudo-inverse of a matrix `A`, is defined as: 'the matrix that 'solves'
706 [the least-squares problem] `A @ x = b`,' i.e., if `x_hat` is a solution, then
707 `A_pinv` is the matrix such that `x_hat = A_pinv @ b`. It can be shown that if
708 `U @ Sigma @ V.T = A` is the singular value decomposition of `A`, then
709 `A_pinv = V @ inv(Sigma) U^T`. [(Strang, 1980)][1]
710
711 This function is analogous to [`numpy.linalg.pinv`](
712 https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.pinv.html).
713 It differs only in default value of `rcond`. In `numpy.linalg.pinv`, the
714 default `rcond` is `1e-15`. Here the default is
715 `10. * max(num_rows, num_cols) * np.finfo(dtype).eps`.
716
717 Args:
718 a: (Batch of) `float`-like matrix-shaped `Tensor`(s) which are to be
719 pseudo-inverted.
720 rcond: `Tensor` of small singular value cutoffs. Singular values smaller
721 (in modulus) than `rcond` * largest_singular_value (again, in modulus) are
722 set to zero. Must broadcast against `tf.shape(a)[:-2]`.
723 Default value: `10. * max(num_rows, num_cols) * np.finfo(a.dtype).eps`.
724 validate_args: When `True`, additional assertions might be embedded in the
725 graph.
726 Default value: `False` (i.e., no graph assertions are added).
727 name: Python `str` prefixed to ops created by this function.
728 Default value: 'pinv'.
729
730 Returns:
731 a_pinv: (Batch of) pseudo-inverse of input `a`. Has same shape as `a` except
732 rightmost two dimensions are transposed.
733
734 Raises:
735 TypeError: if input `a` does not have `float`-like `dtype`.
736 ValueError: if input `a` has fewer than 2 dimensions.
737
738 #### Examples
739
740 ```python
741 import tensorflow as tf
742 import tensorflow_probability as tfp
743
744 a = tf.constant([[1., 0.4, 0.5],
745 [0.4, 0.2, 0.25],
746 [0.5, 0.25, 0.35]])
747 tf.matmul(tf.linalg..pinv(a), a)
748 # ==> array([[1., 0., 0.],
749 [0., 1., 0.],
750 [0., 0., 1.]], dtype=float32)
751
752 a = tf.constant([[1., 0.4, 0.5, 1.],
753 [0.4, 0.2, 0.25, 2.],
754 [0.5, 0.25, 0.35, 3.]])
755 tf.matmul(tf.linalg..pinv(a), a)

Callers

nothing calls this directly

Calls 12

_maybe_validate_matrixFunction · 0.85
get_dim_sizeFunction · 0.85
maximumMethod · 0.80
maxFunction · 0.50
svdFunction · 0.50
name_scopeMethod · 0.45
control_dependenciesMethod · 0.45
identityMethod · 0.45
castMethod · 0.45
matmulMethod · 0.45
set_shapeMethod · 0.45
concatenateMethod · 0.45

Tested by

no test coverage detected