l2gv2.embedding package#

Subpackages#

Submodules#

l2gv2.embedding.embedding module#

Code for embedding individual patches using VGAE or GAE.

class l2gv2.embedding.embedding.EmbeddingModel(model, dim)#

Bases: object

Base class for embedding models.

fit(data)#
fit_transform(data)#
transform(data)#

l2gv2.embedding.eval module#

l2gv2.embedding.train module#

TODO: module docstring for embedding/train.py.

grid search over learning rate values

Parameters:
  • data – input data

  • model – model to train

  • loss_fun – training loss takes model and data as input

  • validation_loss_fun – function to compute validation loss input: (model, data)

  • lr_grid – learning rate values to try

  • num_epochs – number of epochs for training

  • runs – number of training runs to average over for selecting best learning rate

  • verbose – if True, output training progress

Returns:

best learning rate, validation loss for all runs

l2gv2.embedding.train.train(data: ~torch_geometric.data.data.Data, model: ~torch.nn.modules.module.Module, loss_fun: ~typing.Callable, num_epochs: int = 10000, patience: int = 20, lr: float = 0.01, weight_decay: float = 0.0, verbose: bool = True, logger: ~typing.Callable = <function <lambda>>)#

Train an embedding model

Parameters:
  • data – input data

  • model – model to train

  • loss_fun – loss function

  • num_epochs – number of epochs to train

  • patience – patience for early stopping

  • lr – learning rate

  • weight_decay – weight decay

l2gv2.embedding.utils module#

Code for embedding individual patches using VGAE or GAE.

l2gv2.embedding.utils.get_embedding(patches: list[Patch], result: AlignmentProblem)#

Get the embedding of the patches after alignment.

Parameters:
  • patches – List of patches to embed.

  • result – Result of the alignment.

l2gv2.embedding.utils.patch_embeddings(patch_data: list[Data], model: str = 'VGAE', dim: int = 64, hidden_dim: int = 128, num_epochs: int = 100, device: str = 'cpu', lr: float = 0.01)#

Embed patches using VGAE or GAE.

Parameters:
  • patch_data – List of patches to embed.

  • model – Model to use for embedding.

  • dim – Dimension of the embedding.

  • hidden_dim – Hidden dimension of the embedding.

  • num_epochs – Number of epochs to train the model.

Module contents#

class l2gv2.embedding.GAE(dim, hidden_dim, num_features, dist=False)#

Bases: GAE

TODO: class docstring for GAE.

l2gv2.embedding.GAE_loss(model: Module, data: Data)#

loss function for use with GAE_model()

Parameters:
  • model

  • data

Returns:

reconstruction loss

class l2gv2.embedding.GAEconv(dim, num_node_features, hidden_dim=32, cached=True, bias=True, add_self_loops=True, normalize=True)#

Bases: Module

implements the convolution operator for use with tg.nn.GAE

forward(data)#

compute coordinates given data

class l2gv2.embedding.VGAE(dim, hidden_dim, num_features, dist=False)#

Bases: VGAE

VGAE model.

l2gv2.embedding.VGAE_loss(model: Module, data: Data)#

loss function for use with VGAE_model()

Parameters:
  • model

  • data

Returns:

reconstruction loss

class l2gv2.embedding.VGAEconv(dim, num_node_features, hidden_dim=32, cached=True, bias=True, add_self_loops=True, normalize=True)#

Bases: Module

implements the convolution operator for use with torch_geometric.nn.VGAE

forward(data: Data)#

compute mean and variance given data

Parameters:

[type] (data) – input data

Returns:

mu, sigma

l2gv2.embedding.get_embedding(patches: list[Patch], result: AlignmentProblem)#

Get the embedding of the patches after alignment.

Parameters:
  • patches – List of patches to embed.

  • result – Result of the alignment.

grid search over learning rate values

Parameters:
  • data – input data

  • model – model to train

  • loss_fun – training loss takes model and data as input

  • validation_loss_fun – function to compute validation loss input: (model, data)

  • lr_grid – learning rate values to try

  • num_epochs – number of epochs for training

  • runs – number of training runs to average over for selecting best learning rate

  • verbose – if True, output training progress

Returns:

best learning rate, validation loss for all runs

l2gv2.embedding.patch_embeddings(patch_data: list[Data], model: str = 'VGAE', dim: int = 64, hidden_dim: int = 128, num_epochs: int = 100, device: str = 'cpu', lr: float = 0.01)#

Embed patches using VGAE or GAE.

Parameters:
  • patch_data – List of patches to embed.

  • model – Model to use for embedding.

  • dim – Dimension of the embedding.

  • hidden_dim – Hidden dimension of the embedding.

  • num_epochs – Number of epochs to train the model.

l2gv2.embedding.train(data: ~torch_geometric.data.data.Data, model: ~torch.nn.modules.module.Module, loss_fun: ~typing.Callable, num_epochs: int = 10000, patience: int = 20, lr: float = 0.01, weight_decay: float = 0.0, verbose: bool = True, logger: ~typing.Callable = <function <lambda>>)#

Train an embedding model

Parameters:
  • data – input data

  • model – model to train

  • loss_fun – loss function

  • num_epochs – number of epochs to train

  • patience – patience for early stopping

  • lr – learning rate

  • weight_decay – weight decay