lampe.masks#
Masking helpers.
Functions#
Classes#
Creates a distribution \(P(b)\) over all binary masks \(b\) in the hypercube \(\{0, 1\}^D\) such that each bit \(b_i\) has a probability \(p_i\) of being positive. |
|
Creates a mask distribution \(P(b)\), uniform over a selection of binary masks \(\mathcal{B} \subseteq \{0, 1\}^D\). |
Descriptions#
- lampe.masks.mask2str(b)#
Represents a binary mask as a string.
- Parameters
b (BoolTensor) – A binary mask \(b\), with shape \((D,)\).
Example
>>> b = torch.tensor([True, True, False, True, False]) >>> mask2str(b) '11010'
- lampe.masks.str2mask(string)#
Parses the string representation of a binary mask into a tensor.
- Parameters
string (str) – A binary mask string representation.
Example
>>> str2mask('11010') tensor([True, True, False, True, False])
- class lampe.masks.BernoulliMask(p)#
Creates a distribution \(P(b)\) over all binary masks \(b\) in the hypercube \(\{0, 1\}^D\) such that each bit \(b_i\) has a probability \(p_i\) of being positive.
\[P(b) = \prod^D_{i = 1} p_i^{b_i} (1 - p_i)^{1 - b_i}\]- Parameters
p (Tensor) – The probability vector \(p\), with shape \((*, D)\).
Example
>>> d = BernoulliMask(torch.tensor([0.4, 0.1, 0.9])) >>> d.sample() tensor([True, False, True])
- class lampe.masks.SelectionMask(selection)#
Creates a mask distribution \(P(b)\), uniform over a selection of binary masks \(\mathcal{B} \subseteq \{0, 1\}^D\).
\[\begin{split}P(b) = \begin{cases} \frac{1}{|\mathcal{B}|} & \text{if } b \in \mathcal{B} \\ 0 & \text{otherwise} \end{cases}\end{split}\]- Parameters
selection (BoolTensor) – A binary mask selection \(\mathcal{B}\), with shape \((N, D)\).
Example
>>> selection = torch.tensor([ ... [True, False, False], ... [False, True, False], ... [False, False, True], ... ]) >>> d = SelectionMask(selection) >>> d.sample() tensor([False, True, False])