spyrit.core.meas.HadamSplit2d
- class spyrit.core.meas.HadamSplit2d(h: int, M: int = None, order: tensor = None, fast: bool = True, reshape_output: bool = False, *, noise_model=Identity(), dtype: dtype = torch.float32, device: device = device(type='cpu'))[source]
Bases:
LinearSplitSimulate 2D Hadamard split acquisitions.
Considering the acquisition of \(2M\) square DMD patterns of size \(h\), it computes
\[y =\mathcal{N}\left(\mathcal{S}\left(AXA^T\right)\right),\]where \(\mathcal{N} \colon\, \mathbb{R}^{2M} \to \mathbb{R}^{2M}\) represents a noise operator (e.g., Gaussian), \(\mathcal{S} \colon\, \mathbb{R}^{2h\times 2h} \to \mathbb{R}^{2M}\) is a subsampling operator, \(A \in \mathbb{R}_+^{2h\times h}\) is the acquisition matrix that contains the positive and negative components of a Hadamard matrix, \(X \in \mathbb{R}^{h\times h}\) is the (2D) image.
The matrix \(A\) is obtained by splitting a Hadamard matrix \(H\in\mathbb{R}^{h\times h}\) such that \(A[0::2, :] = H_{+}\) and \(A[1::2, :] = H_{-}\), where \(H_{+} = \max(0,H)\) and \(H_{-} = \max(0,-H)\).
Note
\(H_{+} - H_{-} = H\).
The subsampling operator keeps the pixels that correspond to the \(M\) largest values in the order matrix \(O\in\mathbb{R}^{h^2 \times h^2}\).
Note
Subsampling applies to \(H_{+}XH_{+}^T\) and \(H_{-}XH_{-}^T\) the same way, independently.
Note
The operator \(\mathcal{S}\) returns a vector. In the case \(M=h^2\) (no subsampling), \(\mathcal{S}\) is the vectorization operator.
- Args:
h(int): Image size \(h\). Must be a power of 2.order(torch.tensor, optional): Order matrix \(O\) that defines the measurements to keep. The first component of \(y\) will correspond to the index whereorderis the highest.fast(bool, optional): Whether to use the fast Hadamard transform algorithm. If False, it uses matrix-vector products. Defaults to True.reshape_output(bool, optional): Whether reshape the output of adjoint and pinv methods to images. If False, output are vectors.noise_model (see
spyrit.core.noise): Noise model \(\mathcal{N}\). Defaults to torch.nn.Identity().dtype (
torch.dtype, optional): Data type of the measurement matrix. Defaults to torch.float32.device (
torch.device, optional): Device of the measurement matrix. Defaults to torch.device(“cpu”).
Attributes:
H(torch.tensor): The 2D measurement matrix given by \(H\otimes H\).A(torch.tensor): The 2D acquisition matrix given by \(A\otimes A\).M(int): Number of measurements \(M\).N(int): Number of pixels in the image equal to \(h^2\).meas_shape(torch.Size): Shape of the measurement patterns. Is equal to \((h, h)\).meas_dims(torch.Size): Dimensions of the image the acquisition matrix applies to. Is equal to (-2, -1).H_static(torch.tensor): alias forH.H_pinv(torch.tensor, optional): The learnable pseudo inverse measurement matrix \(H^\dagger\) of shape \((N, M)\).order(torch.tensor): Order matrix \(O\). It is used bysort_by_significance(). Defaults to rectangular order (e.g., linear indices).indices(torch.tensor): Indices used to reorder the measurement vector. It is used by the methodreindex().- Example:
>>> import spyrit.core.meas as meas >>> h = 32 >>> meas_op = meas.HadamSplit2d(h, 400) >>> print(meas_op.H1d.shape) torch.Size([32, 32]) >>> print(meas_op.M) 400
Methods
adjoint(y[, unvectorize])Apply adjoint of matrix A.
adjoint_H(m[, unvectorize])Apply the adjoint of matrix H.
Return the pseudo inverse of the matrix H
fast_measure(x)Simulate noiseless measurements from matrix A.
Simulate noiseless measurements from matrix H.
fast_pinv(m[, vectorize])Apply the pseudo inverse of H.
forward(x)Simulate noisy measurements from matrix A.
forward_H(x)Simulate noisy measurements from matrix H.
measure(x)Simulate noiseless measurements from matrix A.
measure_H(x)Simulate noiseless measurements from matrix H.
reindex(x[, axis, inverse_permutation])Sorts a tensor along a specified axis using the indices tensor.
set_matrix_to_inverse(matrix_name)unvectorize(input)Unflatten the measured dimensions.
vectorize(input)Flatten the measured dimensions.