torch_hyperbolic.nn#
Encoder/Decoder Layers#
- class torch_hyperbolic.nn.HyperbolicEncoder(manifold: str = 'PoincareBall', curvature=None)#
The encode() method of the HGCN and HNN from https://github.com/HazyResearch/hgcn/edit/master/models/encoders.py as an explicit class. This layer does not include any linear layers, it only translates the features from euclidean space onto the manifold with curvature c.
- forward(x)#
Projects x into hyperbolic space:
\[\mathbf{X}^{\prime} = \textrm{exp}_\mathbf{o}^c \left( \mathbf{X} \right)\]where exp() \(\textrm{exp} \left( \right)\) is given as
\[\textrm{exp}_\mathbf{o}^c \left( \mathbf{v} \right) = \mathbf{0} \oplus_c \left( \textrm{tanh} \left( \sqrt{|c|} \frac{\lambda_\mathbf{o}^c || \mathbf{v} || _{2}}{2} \frac{\mathbf{v}}{\sqrt{|c| \mathbf{v} || _{2}}} \right) \right)\]for PoincareBall Manifold and
\[\textrm{exp}_\mathbf{o}^c \left( \mathbf{v} \right) = \textrm{cosh} \left( \sqrt{|c|} || \mathbf{v} || _{\mathcal{L}} \right) \mathbf{0} + \mathbf{v} \frac{\textrm{sinh} \left( \sqrt{|c|} || \mathbf{v} || _{\mathcal{L}} \right) }{\sqrt{|c| || \mathbf{v} || _{\mathcal{L}}}}\]for Hyperboloid Manifold (Lorentz Model)
In case the manifold is a hyperoloid (Lorentz model), the output will have n+1 dimensions
- Parameters:
x (torch.Tensor) – The node features in euclidean space.
- Returns:
The node features in hyperbolic space.
- Return type:
torch.Tensor
- class torch_hyperbolic.nn.HyperbolicDecoder(manifold: str = 'PoincareBall', curvature=None)#
The decode() method of the LinearDecoder from https://github.com/HazyResearch/hgcn/edit/master/models/decoders.py as an explicit class. This layer doe snot include any linear layers, it only translates the features from the manifold with curvature c into euclidean space.
- forward(x)#
Projects x from hyperbolic back into euclidean space. In case the manifold is a hyperboloid (Lorentz Model), the output will have n-1 dimensions than the input
Graph Convolution Layers#
- class torch_hyperbolic.nn.HGCNConv(in_channels, out_channels, c, manifold='PoincareBall', dropout=0, use_bias=True, aggr='add', normalize=False, use_att=False, local_agg=False)#
Hyperbolic graph convolution layer.
It assumes that the input is already on the manifold and outputs the feature matrix on the manifold.
Implementation based on https://github.com/HazyResearch/hgcn/blob/master/layers/hyp_layers.py but implemented for the MessagePassing framework using the GCN template from https://pytorch-geometric.readthedocs.io/en/latest/tutorial/create_gnn.html#implementing-the-gcn-layer
- forward(x, edge_index)#
Assumes that x is already on the manifold, i.e. that features are hyperbolic
- message(x_i, x_j, norm)#
If we use local aggregation, x_i and x_j are still on the manifold, else they are in tangent space of origin
- class torch_hyperbolic.nn.HGATConv(in_channels, out_channels, c, manifold='PoincareBall', dropout=0, heads=1, use_bias=True, edge_dim=None, aggr='add', local_agg=False, concat: bool = True, negative_slope: float = 0.2, fill_value: float | Tensor | str = 'mean', **kwargs)#
Hyperbolic graph attention layer.
It assumes that the input is already on the manifold and outputs the feature matrix on the manifold.
- class torch_hyperbolic.nn.HFiLMConv(in_channels, out_channels, c, num_relations: int = 1, nn: Callable | None = None, act: Callable | None = ReLU(), manifold='PoincareBall', dropout=0, aggr='mean', local_agg=False, c_per_relation=False, c_per_relation_init_value=1, c_per_relation_trainable=True)#
Hyperbolic feature-wise linear modulation graph convolution layer.
It assumes that the input is already on the manifold and outputs the feature matrix on the manifold.
Linear Layers#
- class torch_hyperbolic.nn.HypLinear(in_channels, out_channels, c, dropout=0, manifold='PoincareBall', use_bias=True)#
Hyperbolic linear layer.
Activation Layers#
- class torch_hyperbolic.nn.HypAct(act, c_in=None, c_out=None, manifold='PoincareBall')#
Hyperbolic activation layer.
Assumes input features are on a manifold with curvature c_in, brings them into euclidean space, applies the activation, and transforms the output into hyperbolic space with curvature c_out.
In case only translation between two curvatures is desired, torch.nn.Identity() can be passed as activation.