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

Function matrix_solve_ls

tensorflow/python/ops/linalg_ops.py:174–306  ·  view source on GitHub ↗

r"""Solves one or more linear least-squares problems. `matrix` is a tensor of shape `[..., M, N]` whose inner-most 2 dimensions form `M`-by-`N` matrices. Rhs is a tensor of shape `[..., M, K]` whose inner-most 2 dimensions form `M`-by-`K` matrices. The computed output is a `Tensor` of shap

(matrix, rhs, l2_regularizer=0.0, fast=True, name=None)

Source from the content-addressed store, hash-verified

172@tf_export('linalg.lstsq', v1=['linalg.lstsq', 'matrix_solve_ls'])
173@deprecation.deprecated_endpoints('matrix_solve_ls')
174def matrix_solve_ls(matrix, rhs, l2_regularizer=0.0, fast=True, name=None):
175 r"""Solves one or more linear least-squares problems.
176
177 `matrix` is a tensor of shape `[..., M, N]` whose inner-most 2 dimensions
178 form `M`-by-`N` matrices. Rhs is a tensor of shape `[..., M, K]` whose
179 inner-most 2 dimensions form `M`-by-`K` matrices. The computed output is a
180 `Tensor` of shape `[..., N, K]` whose inner-most 2 dimensions form `M`-by-`K`
181 matrices that solve the equations
182 `matrix[..., :, :] * output[..., :, :] = rhs[..., :, :]` in the least squares
183 sense.
184
185 Below we will use the following notation for each pair of matrix and
186 right-hand sides in the batch:
187
188 `matrix`=\\(A \in \Re^{m \times n}\\),
189 `rhs`=\\(B \in \Re^{m \times k}\\),
190 `output`=\\(X \in \Re^{n \times k}\\),
191 `l2_regularizer`=\\(\lambda\\).
192
193 If `fast` is `True`, then the solution is computed by solving the normal
194 equations using Cholesky decomposition. Specifically, if \\(m \ge n\\) then
195 \\(X = (A^T A + \lambda I)^{-1} A^T B\\), which solves the least-squares
196 problem \\(X = \mathrm{argmin}_{Z \in \Re^{n \times k}} ||A Z - B||_F^2 +
197 \lambda ||Z||_F^2\\). If \\(m \lt n\\) then `output` is computed as
198 \\(X = A^T (A A^T + \lambda I)^{-1} B\\), which (for \\(\lambda = 0\\)) is
199 the minimum-norm solution to the under-determined linear system, i.e.
200 \\(X = \mathrm{argmin}_{Z \in \Re^{n \times k}} ||Z||_F^2 \\), subject to
201 \\(A Z = B\\). Notice that the fast path is only numerically stable when
202 \\(A\\) is numerically full rank and has a condition number
203 \\(\mathrm{cond}(A) \lt \frac{1}{\sqrt{\epsilon_{mach}}}\\) or\\(\lambda\\)
204 is sufficiently large.
205
206 If `fast` is `False` an algorithm based on the numerically robust complete
207 orthogonal decomposition is used. This computes the minimum-norm
208 least-squares solution, even when \\(A\\) is rank deficient. This path is
209 typically 6-7 times slower than the fast path. If `fast` is `False` then
210 `l2_regularizer` is ignored.
211
212 Args:
213 matrix: `Tensor` of shape `[..., M, N]`.
214 rhs: `Tensor` of shape `[..., M, K]`.
215 l2_regularizer: 0-D `double` `Tensor`. Ignored if `fast=False`.
216 fast: bool. Defaults to `True`.
217 name: string, optional name of the operation.
218
219 Returns:
220 output: `Tensor` of shape `[..., N, K]` whose inner-most 2 dimensions form
221 `M`-by-`K` matrices that solve the equations
222 `matrix[..., :, :] * output[..., :, :] = rhs[..., :, :]` in the least
223 squares sense.
224
225 Raises:
226 NotImplementedError: linalg.lstsq is currently disabled for complex128
227 and l2_regularizer != 0 due to poor accuracy.
228 """
229
230 # pylint: disable=long-lambda
231 def _use_composite_impl(fast, tensor_shape):

Callers

nothing calls this directly

Calls 3

_use_composite_implFunction · 0.85
_composite_implFunction · 0.85
get_shapeMethod · 0.45

Tested by

no test coverage detected