Randomized SVD

class linalg.svd_rsvd.RSVD[source]
static backward(self, dU, dS, dV)[source]

Defines a formula for differentiating the operation.

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by as many outputs did forward() return, and it should return as many tensors, as there were inputs to forward(). Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input.

The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E.g., backward() will have ctx.needs_input_grad[0] = True if the first input to forward() needs gradient computated w.r.t. the output.

static forward(self, M, k, p=20, q=2, s=1, vnum=1)[source]
Parameters
  • M (torch.tensor) – input matrix

  • k (int) – desired rank

  • p (int) – oversampling rank. Total rank sampled k+p

  • q (int) – number of matrix-vector multiplications for power scheme

  • s (int) – reorthogonalization

  • vnum (int) –

    ???

Returns

approximate leading k left eigenvectors U, singular values S, and right eigenvectors V

Return type

torch.tensor, torch.tensor, torch.tensor

Performs approximate truncated SVD using randomized sampling. Based on the implementation in https://arxiv.org/abs/1502.05366