spyrit.core.torch.regularized_pinv

spyrit.core.torch.regularized_pinv(A: tensor, regularization: str, **kwargs) tensor[source]

Returns a regularized pseudo-inverse of a tensor.

The regularizations supported are:

  • “rcond”: Uses the function torch.linalg.pinv(). Additional

    arguments can be passed to this function through the args and kwargs parameters, such as the rcond parameter.

  • “L2”: Uses the L2 regularization method. The regularization parameter

    eta must be passed as a keyword argument. It controls the amount of regularization applied to the pseudo-inverse.

  • “H1”: Uses the H1 regularization method. The regularization parameters

    eta and img_shape must be passed as keyword arguments. The eta parameter controls the amount of regularization applied to the pseudo-inverse, and the img_shape parameter is the shape of the image to which the pseudo-inverse will be applied. This is used to compute the finite difference operator.

Note

The H1 regularization method is only implemented for application to 2D images (i.e., image_shape must be 2D).

Args:

A (torch.tensor): input 2D matrix to compute the pseudo-inverse. Must be 2D.

regularization (str): Regularization method to use. Supported methods are “rcond”, “L2”, and “H1”.

**kwargs: Additional keyword arguments to pass to the regularization method. Must include the regularization parameter eta when using the “L2” and “H1” regularization methods, and the image shape img_shape when using the “H1” regularization method.

Raises:

NotImplementedError: If the regularization method is not supported.

Returns:

torch.tensor: The regularized pseudo-inverse of the input tensor.