rnaglib.learning¶
Models¶
- class rnaglib.learning.models.Embedder(dims, infeatures_dim=0, num_rels=20, num_bases=None, conv_output=True, self_loop=True, verbose=False)[source]¶
Bases:
ModuleThis is an exemple RGCN for unsupervised learning, going from one element of “dims” to the other
It maps the “features” of an input graph to an “h” node attribute and returns the corresponding tensor.
- Parameters:
dims – The succesive dimensions of the embeddings, should be an iterable or an int
infeatures_dim – The dimension of the input features
num_rels – The number of relations that are to be found in the graphs. Defaults to the 20 base pair types
num_bases – This is to use the basis sharing trick used in RGCN in general
conv_output – Whether to use a convolution at the end of the embedding or simply a linear layer
self_loop – Whether each node is also connected to itself
verbose – blah
- property current_device¶
current device this model is on
- Type:
return
- forward(g)[source]¶
Define 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class rnaglib.learning.models.Classifier(embedder, classif_dims=None, num_rels=20, num_bases=None, conv_output=True, self_loop=True, verbose=False)[source]¶
Bases:
ModuleThis is an exemple RGCN for supervised learning, that uses the previous Embedder network
- Parameters:
embedder – An embedder network as defined above
classif_dims – An iterable of the successive embedding dimensions, similarly to the dims of the Embedder
num_rels – The number of relations that are to be found in the graphs. Defaults to the 20 base pair types
num_bases – This is to use the basis sharing trick used in RGCN in general
conv_output – Whether to use a convolution at the end of the embedding or simply a linear layer
self_loop – Whether each node is also connected to itself
verbose – blah
- property current_device¶
current device this model is on
- Type:
return
- forward(g)[source]¶
Define 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class rnaglib.learning.models.DotPredictor[source]¶
Bases:
ModuleGiven node embeddings and a connectivity, predict a dot product score for each edge
- forward(g, h)[source]¶
Define 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class rnaglib.learning.models.BasePairPredictor(encoder, decoder=DotPredictor( (norm): Sigmoid() ))[source]¶
Bases:
ModuleThis is an exemple RGCN for link prediction, that uses the previous Embedder network Predict the probability that two nucleotides are base paired, based on the dot product of the node embeddings
- Parameters:
encoder – An Embedder network as defined above
decoder – A tool to compute the dot products of a given connectivity.
- forward(g, negative_graph=None)[source]¶
- Predicts the probability that each edge exists.
If negative graph is not None, we embed the real graph and then predict the negative graph connectivity
- Parameters:
g – The real graph to compute node embeddings and edge likelihood over
negative_graph – A decoy connectivity to compute edge likelihood over
- Returns:
The score for the edge likelihood
Learning¶
- rnaglib.learning.learn.pretrain_unsupervised(model, train_loader, optimizer, node_sim=None, learning_routine=<rnaglib.learning.learning_utils.LearningRoutine object>, rec_params={'hops': 2, 'normalize': False, 'similarity': True, 'use_graph': False})[source]¶
Perform the pretraining routine to get embeddings from graph nodes, that correlate with a node kernel.
- Parameters:
model – The model to train
optimizer – the optimizer to use (eg SGD or Adam)
train_loader – The loader to use for training, as defined in GraphLoader
node_sim – If None, we just rely on the node_sim in the data loader.
learning_routine – A LearningRoutine object, if we want to also use a validation phase and early stopping
rec_params – These are parameters useful for the loss computation and further explained in learning_utils.rec_loss
- Returns:
The best loss obtained
- rnaglib.learning.learn.train_supervised(model, optimizer, train_loader, learning_routine=<rnaglib.learning.learning_utils.LearningRoutine object>)[source]¶
Performs the entire training routine for a supervised task
- Parameters:
model – The model to train
optimizer – the optimizer to use (eg SGD or Adam)
train_loader – The loader to use for training, as defined in dataset/GraphLoader
learning_routine – A LearningRoutine object, if we want to also use a validation phase and early stopping
- Returns:
The best loss obtained
- rnaglib.learning.learn.train_linkpred(model, optimizer, train_loader_generator, validation_loader_generator)[source]¶
Train a link prediction model : given RNA graphs, predict whether nodes are bound
- Parameters:
model – The model to train
optimizer – the optimizer to use (eg SGD or Adam)
train_loader_generator – The edge loader to use for training, as defined in dataset/GraphLoader
validation_loader_generator – The edge loader to use for training, as defined in dataset/GraphLoader
- Returns:
The best loss obtained