l2gv2.embedding package#
Subpackages#
Submodules#
l2gv2.embedding.embedding module#
Code for embedding individual patches using VGAE or GAE.
l2gv2.embedding.eval module#
l2gv2.embedding.train module#
TODO: module docstring for embedding/train.py.
- l2gv2.embedding.train.lr_grid_search(data, model, loss_fun, validation_loss_fun, lr_grid=(0.1, 0.01, 0.005, 0.001), num_epochs=10, runs=1, verbose=True)#
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:
GAETODO: 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:
Moduleimplements 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:
VGAEVGAE 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:
Moduleimplements 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.
- l2gv2.embedding.lr_grid_search(data, model, loss_fun, validation_loss_fun, lr_grid=(0.1, 0.01, 0.005, 0.001), num_epochs=10, runs=1, verbose=True)#
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