spyrit.core.meas.HadamSplit
- class spyrit.core.meas.HadamSplit(M: int, h: int, Ord: tensor = None)[source]
Bases:
LinearSplitSimulates splitted measurements \(y = \begin{bmatrix}{H_{+}}\\{H_{-}}\end{bmatrix}x\) with \(H\) a Hadamard matrix.
Computes linear measurements from incoming images: \(y = Px\), where \(P\) is a linear operator (matrix) and \(x\) is a vectorized image or batch of vectorized images.
The matrix \(P\) contains only positive values and is obtained by splitting a Hadamard-based matrix \(H\) such that \(P\) has a shape of \((2M, N)\) and P[0::2, :] = H_{+} and P[1::2, :] = H_{-}, where \(H_{+} = \max(0,H)\) and \(H_{-} = \max(0,-H)\).
\(H\) is obtained by selecting a re-ordered subsample of \(M\) rows of a “full” Hadamard matrix \(F\) with shape \((N^2, N^2)\). \(N\) must be a power of 2.
- Args:
M(int): Number of measurements. It determines the size of the Hadamard matrix subsample \(H\).h(int): Measurement pattern height. The width is taken to be equal to the height, so the measurement pattern is square. The Hadamard matrix will have shape \((h^2, h^2)\).Ord(torch.tensor, optional): Order matrix used to reorder the rows of the measurement matrix \(H\). The first new row of \(H\) will correspond to the highest value in \(Ord\). Must contain \(M\) values. If some values repeat, the order is kept. Defaults to None.- Attributes:
H(torch.tensor): The learnable measurement matrix of shape \((M, N)\).H_static(torch.tensor): alias forH.P(torch.tensor): The splitted measurement matrix of shape \((2M, N)\).H_pinv(torch.tensor, optional): The learnable pseudo inverse measurement matrix \(H^\dagger\) of shape \((N, M)\).M(int): Number of measurements performed by the linear operator. Is equal to the parameterM.N(int): Number of pixels in the image, is equal to \(h^2\).h(int): Measurement pattern height.w(int): Measurement pattern width. Is equal to \(h\).meas_shape(tuple): Shape of the measurement patterns (height, width). Is equal to (self.h, self.h).indices(torch.tensor): Indices used to sort the rows of H. It is used by the methodreindex().Ord(torch.tensor): Order matrix used to sort the rows of H. It is used bysort_by_significance().
Note
The computation of a Hadamard transform \(Fx\) benefits a fast algorithm, as well as the computation of inverse Hadamard transforms.
Note
\(H = H_{+} - H_{-}\)
- Example:
>>> h = 32 >>> Ord = torch.randn(h, h) >>> meas_op = HadamSplit(400, h, Ord) >>> print(meas_op) HadamSplit( (M): 400 (N): 1024 (H.shape): torch.Size([400, 1024]) (meas_shape): (32, 32) (H_pinv): True (P.shape): torch.Size([800, 1024]) )
Methods
adjoint(x)Applies adjoint transform to incoming measurements \(y = H^{T}x\)
forward(x)Applies linear transform to incoming images: \(y = Px\).
forward_H(x)Applies linear transform to incoming images: \(m = Hx\).
get_H()Deprecated method.
inverse(y)Inverse transform of Hadamard-domain images \(x = H_{had}^{-1}G y\).
pinv(x[, reg, eta])Computes the pseudo inverse solution \(y = H^\dagger x\).
reindex(x[, axis, inverse_permutation])Sorts a tensor along a specified axis using the indices tensor.
set_H_pinv([rtol])Used to set the pseudo inverse of the measurement matrix \(H\) using torch.linalg.pinv.