eAffine#
- class eAffine(in_rep, bias=True, learnable=True, init_scheme='identity')[source]#
Bases:
ModuleEquivariant affine map with per-irrep scales and invariant bias.
Let \(\mathbf{x}\in\mathcal{X}\) with representation
\[\rho_{\mathcal{X}} = \mathbf{Q}\left( \bigoplus_{k\in[1,n_{\text{iso}}]} \bigoplus_{i\in[1,n_k]} \hat{\rho}_k \right)\mathbf{Q}^T.\]This module applies
\[\mathbf{y} = \mathbf{Q}\,\mathbf{D}_{\alpha}\,\mathbf{Q}^T\mathbf{x} + \mathbf{b},\]where \(\mathbf{D}_{\alpha}\) is diagonal in irrep-spectral basis and constant over dimensions of each irrep copy (\(\alpha_{k,i}\)), while \(\mathbf{b}\in\mathrm{Fix}(\rho_{\mathcal{X}})\) (trivial block only). Therefore:
\[\rho_{\mathcal{X}}(g)\mathbf{y} = \operatorname{eAffine}\!\left(\rho_{\mathcal{X}}(g)\mathbf{x}\right) \quad \forall g\in\mathbb{G}.\]When
learnable=Truethese DoFs are trainable parameters. Whenlearnable=False,scale_dofandbias_dofare provided at call-time (FiLM style).- Parameters:
in_rep (
Representation) –Representationdescribing the input/output space \(\rho_{\text{in}}\).bias (
bool) – include invariant biases when the trivial irrep is present. Default:True.learnable (
bool) – ifFalse, no parameters are registered andscale_dof/bias_dofmust be passed at call time. Default:True.init_scheme (
Optional[Literal['identity','random']]) – initialization for the learnable DoFs ("identity"or"random"). Set toNoneto skip init (e.g. when loading weights). Ignored whenlearnable=False.
- Shape:
Input:
(..., D)withD = in_rep.size.scale_dof(optional):(..., num_scale_dof)wheren_irrepsis the number of irreps inin_rep.bias_dof(optional):(..., num_bias_dof)whenbias=True.Output:
(..., D).
Note
Runtime behavior depends on mode. In training mode (
model.train()), the affine map is recomputed each forward pass. In inference mode (model.eval()) and withlearnable=True, the dense affine map \(\mathbf{Q}\mathbf{D}_{\alpha}\mathbf{Q}^T\) (and optional invariant bias) is cached and reused until parameters change orinvalidate_cache()is called, which is faster. UnlikeeLinear, this module is not a strict symmetry-agnostic drop-in affine block, because parameters are irrep-structured and may also be provided externally (FiLM-style viascale_dof/bias_dof).- rep_x#
Representation \(\rho_{\mathcal{X}}\) of the feature space.
- Type:
- bias_module#
Optional module handling the invariant bias.
- Type:
InvariantBias| None
- broadcast_spectral_scale_and_bias(scale_dof, bias_dof=None, input_shape=None)[source]#
Return spectral scale and bias from provided DoFs.
- Parameters:
- Returns:
Pair
(spectral_scale, spectral_bias)wherespectral_scaleis shaped(..., rep_x.size)andspectral_biasis shaped(..., rep_x.size)(orNonewhenbias=False).- Return type:
tuple[torch.Tensor, torch.Tensor | None]
- expand_affine()[source]#
Expand the per-irrep scales into an affine matrix in the original basis.
- Return type:
- forward(input, scale_dof=None, bias_dof=None)[source]#
Apply the equivariant affine transform.
When
learnable=Falsescale_dof(andbias_dofifbias=True) must be provided.- Parameters:
input (
Tensor) – Tensor \(\mathbf{x}\) whose last dimension matchesin_rep.size.scale_dof (
Tensor|None) – Optional per-irrep scaling DoFs (lengthnum_scale_dof). Required whenlearnable=Falsewith leading dims matchinginput.shape[:-1].bias_dof (
Tensor|None) – Optional invariant-bias DoFs (lengthnum_bias_dof). Required whenlearnable=Falseandbias=Truewith leading dims matchinginput.shape[:-1].
- Return type:
- load_state_dict(state_dict, strict=True)[source]#
Load parameters and invalidate cached affine expansion.
- Parameters:
strict (bool)
- property num_bias_dof: int#
Number of bias degrees of freedom (length of
bias_dof) for invariant irreps.