Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

torch_lstsq

Lstsq


Description

Lstsq

Usage

torch_lstsq(self, A)

Arguments

self

(Tensor) the matrix B

A

(Tensor) the m by n matrix A

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

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

If m ≥q n, torch_lstsq() solves the least-squares problem:

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

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

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

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

Note

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

Examples

if (torch_is_installed()) {

A = torch_tensor(rbind(
 c(1,1,1),
 c(2,3,4),
 c(3,5,2),
 c(4,2,5),
 c(5,4,3)
))
B = torch_tensor(rbind(
 c(-10, -3),
 c(12, 14),
 c(14, 12),
 c(16, 16),
 c(18, 16)
))
out = torch_lstsq(B, A)
out[[1]]
}

torch

Tensors and Neural Networks with 'GPU' Acceleration

v0.3.0
MIT + file LICENSE
Authors
Daniel Falbel [aut, cre, cph], Javier Luraschi [aut], Dmitriy Selivanov [ctb], Athos Damiani [ctb], Christophe Regouby [ctb], Krzysztof Joachimiak [ctb], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.