grb.defense

grb.defense.adv_trainer

class grb.defense.adv_trainer.AdvTrainer(dataset, optimizer, loss, attack=None, adj_norm_func=None, feat_norm=None, lr_scheduler=None, early_stop=None, eval_metric=<function eval_acc>, device='cpu')[source]

Bases: object

inference(model)[source]
train(model, n_epoch, save_dir=None, save_name=None, eval_every=10, save_after=0, train_mode='trasductive', dropout=0, 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, activation=<function relu>, layer_norm=False, dropout=True, k=50)[source]

Bases: torch.nn.modules.module.Module

forward(x, adj, dropout=0)[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, verbose=False)[source]

grb.defense.gnnguard

class grb.defense.gnnguard.GATGuard(in_features, out_features, hidden_features, num_heads, activation=<function leaky_relu>, layer_norm=False, drop=False, attention=True)[source]

Bases: torch.nn.modules.module.Module

att_coef(features, adj)[source]
forward(x, adj, dropout=0)[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, activation=<function relu>, layer_norm=False, dropout=True, drop=False, attention=True)[source]

Bases: torch.nn.modules.module.Module

att_coef(features, adj)[source]
forward(x, adj, dropout=0)[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