NC (Node classification)¶
hypertorch.nc
¶
NcModule
¶
Bases: LightningModule
A LightningModule base class for multiclass node-classification models.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module. Defaults to |
classifier |
Module
|
Module that maps node features to class logits. |
loss_fn |
Module
|
Multiclass loss function. |
metrics_log_kwargs |
dict[str, Any]
|
Keyword arguments passed to metric log calls. |
train_metrics |
MetricCollection | None
|
Optional training metrics. |
val_metrics |
MetricCollection | None
|
Optional validation metrics. |
test_metrics |
MetricCollection | None
|
Optional test metrics. |
Source code in hypertorch/nc/common.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
__init__(classifier, loss_fn, encoder=None, metrics=None, metrics_log_kwargs=None)
¶
Initialize the NC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier
|
Module
|
Module producing one class-logit row per node. |
required |
loss_fn
|
Module
|
Loss function used on supervised target nodes. |
required |
encoder
|
Module | None
|
Optional encoder module. Defaults to |
None
|
metrics
|
MetricCollection | None
|
Optional metric collection cloned independently per stage. |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls. |
None
|
Source code in hypertorch/nc/common.py
CommonNeighborsNcModule
¶
Bases: NcModule
A LightningModule for the CommonNeighbors node-classification heuristic.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
Identity placeholder inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
node_to_neighbors |
dict[int, Neighborhood]
|
Precomputed training-world node neighborhoods. |
automatic_optimization |
bool
|
Disabled because this module has no trainable optimization. |
Source code in hypertorch/nc/common_neighbors_nc.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
__init__(train_hdata, num_classes, aggregation='sum', exclude_self_reference=True, classifier=None, loss_fn=None, metrics=None, metrics_log_kwargs=None)
¶
Initialize the CommonNeighbors NC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_hdata
|
HData
|
Training data used to precompute neighborhoods and labeled reference nodes. |
required |
num_classes
|
int
|
Number of node classes. |
required |
aggregation
|
Literal['mean', 'min', 'sum']
|
Method used to aggregate reference-node scores per class.
Defaults to |
'sum'
|
exclude_self_reference
|
bool
|
Whether a node should ignore itself when it also
appears among labeled reference nodes. Defaults to |
True
|
classifier
|
Module | None
|
Optional classifier module. |
None
|
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Defaults to |
None
|
Source code in hypertorch/nc/common_neighbors_nc.py
forward(global_node_ids)
¶
Compute common-neighbor class scores for the given nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
global_node_ids
|
Tensor
|
Stable node IDs matching the training-world node IDs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class scores of shape |
Source code in hypertorch/nc/common_neighbors_nc.py
on_fit_start()
¶
Warn users if they are running unnecessary training epochs.
Source code in hypertorch/nc/common_neighbors_nc.py
training_step(batch, batch_idx)
¶
Return a zero loss for the non-trainable heuristic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch, unused. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Zero scalar tensor on the module device. |
Source code in hypertorch/nc/common_neighbors_nc.py
validation_step(batch, batch_idx)
¶
Return a zero validation loss for the non-trainable heuristic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch, unused. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Zero scalar tensor on the module device. |
Source code in hypertorch/nc/common_neighbors_nc.py
test_step(batch, batch_idx)
¶
Evaluate a test batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/nc/common_neighbors_nc.py
predict_step(batch, batch_idx)
¶
Predict common-neighbor class scores for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class scores. |
Source code in hypertorch/nc/common_neighbors_nc.py
configure_optimizers()
¶
Return no optimizer for the non-trainable heuristic.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
None
|
No optimizer is configured, so always returns |
__step(batch, stage)
¶
Shared evaluation logic for all stages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
|
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/nc/common_neighbors_nc.py
__class_to_node_ids(train_hdata, num_classes)
¶
Group labeled training nodes by class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_hdata
|
HData
|
Training data containing node labels and train node mask. |
required |
num_classes
|
int
|
Number of node classes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
class_to_node_ids |
dict[int, list[int]]
|
Dictionary mapping class IDs to lists of node IDs. |
Source code in hypertorch/nc/common_neighbors_nc.py
__default_classifier(train_hdata, num_classes, aggregation, exclude_self_reference=True)
¶
Create a default CommonNeighbors classifier with a CommonNeighborsNodeScorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_hdata
|
HData
|
Training data containing node labels and train node mask. |
required |
num_classes
|
int
|
Number of node classes. |
required |
aggregation
|
Literal['mean', 'min', 'sum']
|
Method used to aggregate reference-node scores per class. |
required |
exclude_self_reference
|
bool
|
Whether a node should ignore itself when it also appears among labeled reference nodes. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
classifier |
CommonNeighbors
|
A CommonNeighbors classifier with a CommonNeighborsNodeScorer. |
Source code in hypertorch/nc/common_neighbors_nc.py
GCNNcConfig
¶
Bases: TypedDict
Configuration for the GCN classifier in GCNNcModule.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
out_channels |
int
|
Number of node classes. |
hidden_channels |
NotRequired[int]
|
Number of hidden units in intermediate GCN layers. |
num_layers |
NotRequired[int]
|
Number of GCN layers. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate applied after each hidden GCN layer. Defaults to |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
improved |
NotRequired[bool]
|
Whether to use the improved GCN normalization. Defaults to |
add_self_loops |
NotRequired[bool]
|
Whether to add self-loops before convolution. Defaults to |
normalize |
NotRequired[bool]
|
Whether to normalize the adjacency matrix in |
cached |
NotRequired[bool]
|
Whether to cache the normalized graph in |
graph_reduction_strategy |
NotRequired[GraphReductionStrategy]
|
Strategy for reducing the hypergraph to a graph.
Defaults to |
num_nodes |
NotRequired[int]
|
Optional total number of nodes to use during graph reduction. |
activation_fn |
NotRequired[ActivationFn]
|
Activation function to use after each hidden layer.
Defaults to |
activation_fn_kwargs |
NotRequired[dict]
|
Keyword arguments for the activation function. Defaults to empty dict. |
Source code in hypertorch/nc/gcn_nc.py
GCNNcModule
¶
Bases: NcModule
A LightningModule for GCN-based multiclass node classification.
Reduces the hypergraph to a graph, then applies GCN layers to produce per-node class logits.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
GCN classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/nc/gcn_nc.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the GCN NC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
GCNNcConfig
|
Configuration for the GCN classifier. |
required |
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/nc/gcn_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/nc/gcn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/nc/gcn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/nc/gcn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/nc/gcn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/nc/gcn_nc.py
HGNNNcConfig
¶
Bases: TypedDict
Configuration for the HGNN classifier in HGNNNcModule.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
hidden_channels |
int
|
Number of hidden units in the intermediate HGNN layer. |
out_channels |
int
|
Number of node classes. |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
use_batch_normalization |
NotRequired[bool]
|
Whether to use batch normalization. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate. Defaults to |
Source code in hypertorch/nc/hgnn_nc.py
HGNNNcModule
¶
Bases: NcModule
A LightningModule for HGNN-based multiclass node classification.
Uses HGNN to transform node features and hypergraph incidence structure directly into
per-node class logits. During training, validation, and testing, loss and metrics
are computed on supervised target nodes selected by HData.target_node_mask.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
HGNN classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/nc/hgnn_nc.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the HGNN NC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
HGNNNcConfig
|
Configuration for the HGNN classifier. |
required |
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/nc/hgnn_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/nc/hgnn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/nc/hgnn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/nc/hgnn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/nc/hgnn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/nc/hgnn_nc.py
HNHNNcConfig
¶
Bases: TypedDict
Configuration for the HNHN classifier in HNHNNcModule.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
hidden_channels |
int
|
Number of hidden units in the intermediate HNHN layer. |
out_channels |
int
|
Number of node classes. |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
use_batch_normalization |
NotRequired[bool]
|
Whether to use batch normalization. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate. Defaults to |
Source code in hypertorch/nc/hnhn_nc.py
HNHNNcModule
¶
Bases: NcModule
A LightningModule for HNHN-based multiclass node classification.
Uses HNHN to transform node features and hypergraph incidence structure into
per-node class logits through explicit hyperedge neurons. During training,
validation, and testing, loss and metrics are computed on supervised target
nodes selected by HData.target_node_mask.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
HNHN classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/nc/hnhn_nc.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the HNHN NC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
HNHNNcConfig
|
Configuration for the HNHN classifier. |
required |
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/nc/hnhn_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/nc/hnhn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/nc/hnhn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/nc/hnhn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/nc/hnhn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/nc/hnhn_nc.py
HGNNPNcConfig
¶
Bases: TypedDict
Configuration for the HGNN+ classifier in HGNNPNcModule.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
hidden_channels |
int
|
Number of hidden units in the intermediate HGNN+ layer. |
out_channels |
int
|
Number of node classes. |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
use_batch_normalization |
NotRequired[bool]
|
Whether to use batch normalization. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate. Defaults to |
Source code in hypertorch/nc/hgnnp_nc.py
HGNNPNcModule
¶
Bases: NcModule
A LightningModule for HGNN+-based multiclass node classification.
Uses HGNN+ to transform node features and hypergraph incidence structure directly into
per-node class logits. During training, validation, and testing, loss and metrics
are computed on supervised target nodes selected by HData.target_node_mask.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
HGNN+ classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/nc/hgnnp_nc.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the HGNN+ NC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
HGNNPNcConfig
|
Configuration for the HGNN+ classifier. |
required |
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/nc/hgnnp_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/nc/hgnnp_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/nc/hgnnp_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/nc/hgnnp_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/nc/hgnnp_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/nc/hgnnp_nc.py
HyperGCNNcConfig
¶
Bases: TypedDict
Configuration for the HyperGCN classifier in HyperGCNNcModule.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
hidden_channels |
int
|
Number of hidden units in the intermediate HyperGCN layer. |
out_channels |
int
|
Number of node classes. |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
use_batch_normalization |
NotRequired[bool]
|
Whether to use batch normalization. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate. Defaults to |
use_mediator |
NotRequired[bool]
|
Whether to use mediator nodes for hyperedge-to-edge conversion.
Defaults to |
fast |
NotRequired[bool]
|
Whether to cache the graph structure after first computation.
Defaults to |
seed |
NotRequired[int]
|
Optional random seed for the random reduction of hyperedges to edges.
Defaults to |
Source code in hypertorch/nc/hypergcn_nc.py
HyperGCNNcModule
¶
Bases: NcModule
A LightningModule for HyperGCN-based multiclass node classification.
Uses HyperGCN to transform node features and hypergraph structure directly into
per-node class logits. During training, validation, and testing, loss and metrics
are computed on supervised target nodes selected by HData.target_node_mask.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
HyperGCN classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/nc/hypergcn_nc.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the HyperGCN NC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
HyperGCNNcConfig
|
Configuration for the HyperGCN classifier. |
required |
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/nc/hypergcn_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/nc/hypergcn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/nc/hypergcn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/nc/hypergcn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/nc/hypergcn_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/nc/hypergcn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/nc/hypergcn_nc.py
MLPNcModule
¶
Bases: NcModule
A LightningModule for MLP-based multiclass node classification.
Uses an MLP classifier to map node features directly to per-node class logits.
During training, validation, and testing, loss and metrics are computed on the
supervised target nodes selected by HData.target_node_mask when present.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
MLP classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
Source code in hypertorch/nc/mlp_nc.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
__init__(classifier_config, loss_fn=None, lr=0.001, metrics=None, metrics_log_kwargs=None)
¶
Initialize the MLP NC module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
MLPNcConfig
|
Configuration for the MLP classifier. |
required |
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/nc/mlp_nc.py
forward(x)
¶
Predict node-class logits from node features.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x = [[0.1, 0.2, 0.3], # node 0 ... [0.4, 0.5, 0.6], # node 1 ... [0.7, 0.8, 0.9], # node 2 ... [1.0, 1.1, 1.2]] # node 3
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x) >>> logits.shape torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/nc/mlp_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/nc/mlp_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/nc/mlp_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/nc/mlp_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/nc/mlp_nc.py
MLPNcConfig
¶
Bases: TypedDict
Configuration for the MLP classifier in MLPNcModule.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
out_channels |
int
|
Number of node classes. |
num_layers |
NotRequired[int]
|
Number of layers in the MLP classifier. |
hidden_channels |
NotRequired[int | None]
|
Optional number of hidden units per layer. If |
activation_fn |
NotRequired[ActivationFn | None]
|
Optional activation function class to use in the MLP classifier.
If |
activation_fn_kwargs |
NotRequired[dict | None]
|
Optional dictionary of keyword arguments to pass to the activation function constructor. |
normalization_fn |
NotRequired[NormalizationFn | None]
|
Optional normalization function class to use in the MLP classifier.
If |
normalization_fn_kwargs |
NotRequired[dict | None]
|
Optional dictionary of keyword arguments to pass to the normalization function constructor. |
bias |
NotRequired[bool]
|
Whether to include bias terms in the MLP layers. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate to apply after each MLP layer except the last one.
Defaults to |