grb.defense

grb.defense.adv_trainer

class grb.defense.adv_trainer.AdvTrainer(dataset, optimizer, loss, feat_norm=None, attack=None, attack_mode='injection', lr_scheduler=None, lr_patience=100, lr_factor=0.75, lr_min=1e-05, early_stop=None, early_stop_patience=100, early_stop_epsilon=1e-05, eval_metric=<function eval_acc>, device='cpu')[source]

Bases: object

evaluate(model, mask=None)[source]

Evaluation of a GNN model.

Parameters
  • model (torch.nn.module) – Model implemented based on torch.nn.module.

  • mask (torch.tensor, optional) – Mask of target nodes. Default: None.

Returns

score – Score on masked nodes.

Return type

float

inference(model)[source]

Inference of a GNN model.

Parameters

model (torch.nn.module) – Model implemented based on torch.nn.module.

Returns

logits – Output logits of model.

Return type

torch.Tensor

train(model, n_epoch, save_dir=None, save_name=None, eval_every=10, save_after=0, train_mode='trasductive', verbose=True)[source]
class grb.defense.adv_trainer.EarlyStop(patience=1000, epsilon=1e-05)[source]

Bases: object

grb.defense.base

class grb.defense.base.Defense[source]

Bases: object

Abstract class for defense.

abstract defense(model, adj, features, **kwargs)[source]
Parameters
  • model (torch.nn.module) – Model implemented based on torch.nn.module.

  • adj (scipy.sparse.csr.csr_matrix) – Adjacency matrix in form of N * N sparse matrix.

  • features (torch.FloatTensor) – Features in form of N * D torch float tensor.

  • kwargs – Keyword-only arguments.

grb.defense.gcnsvd

class grb.defense.gcnsvd.GCNSVD(in_features, out_features, hidden_features, n_layers, activation=<function relu>, layer_norm=False, feat_norm=None, adj_norm_func=None, residual=False, dropout=0.0, k=50)[source]

Bases: Module

forward(x, adj)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

property model_type
training: bool
truncatedSVD(adj, k=50)[source]

grb.defense.gnnguard

class grb.defense.gnnguard.GATGuard(in_features, out_features, hidden_features, n_layers, n_heads, activation=<function leaky_relu>, layer_norm=False, feat_norm=None, adj_norm_func=<function GCNAdjNorm>, drop=False, attention=True, dropout=0.0)[source]

Bases: Module

att_coef(features, adj)[source]
forward(x, adj)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

property model_type
training: bool
class grb.defense.gnnguard.GCNGuard(in_features, out_features, hidden_features, n_layers, activation=<function relu>, layer_norm=False, dropout=True, feat_norm=None, adj_norm_func=<function GCNAdjNorm>, drop=0.0, attention=True)[source]

Bases: Module

att_coef(features, adj)[source]
forward(x, adj)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

property model_type
reset_parameters()[source]
training: bool