torch_lstsq {torch}R Documentation

Lstsq

Description

Lstsq

Arguments

self

(Tensor) the matrix BB

A

(Tensor) the mm by nn matrix AA

lstsq(input, A, out=NULL) -> Tensor

Computes the solution to the least squares and least norm problems for a full rank matrix AA of size (m×n)(m \times n) and a matrix BB of size (m×k)(m \times k).

If mnm \geq n, torch_lstsq() solves the least-squares problem:

minXAXB2. \begin{array}{ll} \min_X & \|AX-B\|_2. \end{array}

If m<nm < n, torch_lstsq() solves the least-norm problem:

minXX2\mboxsubjecttoAX=B. \begin{array}{llll} \min_X & \|X\|_2 & \mbox{subject to} & AX = B. \end{array}

Returned tensor XX has shape (\mboxmax(m,n)×k)(\mbox{max}(m, n) \times k). The first nn rows of XX contains the solution. If mnm \geq n, the residual sum of squares for the solution in each column is given by the sum of squares of elements in the remaining mnm - n rows of that column.

Note

The case when \eqn{m < n} is not supported on the GPU.

[Package torch version 0.13.0 Index]