faninsar.NSBAS.inversion.censored_lstsq#
- faninsar.NSBAS.inversion.censored_lstsq(G: np.ndarray | torch.Tensor, d: np.ndarray | torch.Tensor, dtype: torch.dtype = torch.float64, device: str | torch.device | None = None, return_numpy: bool = True) NDArray[np.floating] | torch.Tensor[source]#
Solves least squares problem subject to missing data.
Reference: http://alexhwilliams.info/itsneuronalblog/2018/02/26/censored-lstsq/.
Note
This function is used for solving the least squares problem with missing data. The missing data is represented by nan values in the data matrix
d. If there are no nan values in d, you are recommended to usetorch.linalg.lstsq()instead.- Parameters:
G (np.ndarray | torch.Tensor,) – model field matrix in shape of (n_im, n_param) or (n_pt, n_im, n_param). If G is 3D, the first dimension is the G matrix for each pixel.
d (np.ndarray | torch.Tensor, (n_im, n_pt) matrix) – data field matrix.
dtype (torch.dtype) – dtype of torch.tensor used for computation.
device (Optional[str | torch.device]) – device of torch.tensor used for computation. If None, use GPU if available, otherwise use CPU.
return_numpy (bool, optional) – If True, return a numpy array, otherwise return a torch tensor.
- Returns:
X – (n_im x n_pt) matrix that minimizes norm(M*(GX - d)). If return_numpy is True, return a numpy array, otherwise return a torch tensor.
- Return type:
np.ndarray | torch.Tensor