CardamomOT.inference.network_final

PyTorch version of network inference using Adam optimizer Simplified version focusing on core inference without refinement

Classes

GRNInference

PyTorch module for Gene Regulatory Network inference

Functions

base_kon_torch(→ torch.Tensor)

PyTorch version of base_kon with numerical stability

smoothed_l1_loss(→ torch.Tensor)

Smoothed L1 penalization

l2_loss(tensor, l2_weight)

L2 penalization

elasticnet_loss(tensor, weight)

Elastic net: combination of L1 and L2

compute_main_loss(y_pred, y_true[, loss_type])

Compute main loss (L1, L2, or Cross-Entropy)

inference_pytorch(y_samples, y_kon, y_proba, y_prot, ...)

PyTorch-based network inference using Adam optimizer

inference_network_pytorch([basal_init, ref_network, ...])

Main entry point for PyTorch network inference

Module Contents

CardamomOT.inference.network_final.base_kon_torch(theta_basal, theta_inter, y_prot) torch.Tensor

PyTorch version of base_kon with numerical stability

Parameters:
  • theta_basal – (n_networks,) basal parameters

  • theta_inter – (G, n_networks) interaction parameters

  • y_prot – (n_cells, G) protein expression values

Returns:

(n_cells, n_networks+1) probabilities for each network state

CardamomOT.inference.network_final.smoothed_l1_loss(tensor, l1_weight) torch.Tensor

Smoothed L1 penalization

CardamomOT.inference.network_final.l2_loss(tensor, l2_weight)

L2 penalization

CardamomOT.inference.network_final.elasticnet_loss(tensor, weight)

Elastic net: combination of L1 and L2

CardamomOT.inference.network_final.compute_main_loss(y_pred, y_true, loss_type='CE')

Compute main loss (L1, L2, or Cross-Entropy)

Parameters:
  • y_pred – predicted values

  • y_true – true values

  • loss_type – ‘l1’, ‘l2’, or ‘CE’

class CardamomOT.inference.network_final.GRNInference(G, n_networks, inter_init, basal_init, ref_network)

Bases: torch.nn.Module

PyTorch module for Gene Regulatory Network inference

forward(y_prot) torch.Tensor

Forward pass: compute network probabilities

Parameters:

y_prot – (n_cells, G) protein expression

Returns:

(n_cells, n_networks+1) network probabilities

Return type:

sigma

compute_loss(y_samples, y_proba, y_prot, y_prot_prev, y_kon, ks, proba, l_pen, weight_prev=0.5, loss_type='CE')

Compute total loss including data fitting and regularization

Parameters:
  • y_samples – (n_cells,) sample/batch indices

  • y_proba – (n_cells, n_networks+1) target probabilities (if proba=True)

  • y_prot – (n_cells, G) protein expression current timepoint

  • y_prot_prev – (n_cells, G) protein expression previous timepoint

  • y_kon – (n_cells,) target kon values (if proba=False)

  • ks – (n_networks+1,) network activation rates

  • proba – bool, whether to predict probabilities or kon

  • l_pen – penalization weight

  • weight_prev – weight for previous timepoint loss

  • loss_type – ‘l1’, ‘l2’, or ‘CE’

  • final – bool, use elastic net if True

CardamomOT.inference.network_final.inference_pytorch(y_samples, y_kon, y_proba, y_prot, y_prot_prev, ks, inter_init, basal_init, ref_network, inter_ref=None, basal_ref=None, proba=True, scale=100, weight_prev=0.5, loss_type='CE', lr=0.001, n_epochs=1000, verbose=True, device='cuda' if torch.cuda.is_available() else 'cpu')

PyTorch-based network inference using Adam optimizer

Parameters:
  • y_samples – (n_cells,) sample/batch indices

  • y_kon – (n_cells,) target kon values

  • y_proba – (n_cells, n_networks+1) target network probabilities

  • y_prot – (n_cells, G) protein expression (current)

  • y_prot_prev – (n_cells, G) protein expression (previous)

  • ks – (n_networks+1,) network activation rates

  • inter_init – (G, n_networks) initial interaction parameters

  • basal_init – (n_networks,) initial basal parameters

  • ref_network – (G, n_networks) reference network structure

  • inter_ref – (G, n_networks) reference interaction parameters (defaults to inter_init)

  • basal_ref – (n_networks,) reference basal parameters (defaults to basal_init)

  • proba – bool, predict probabilities (True) or kon values (False)

  • scale – scaling factor for penalization

  • weight_prev – weight for previous timepoint in loss

  • loss_type – ‘l1’, ‘l2’, or ‘CE’

  • lr – learning rate for Adam

  • n_epochs – number of training epochs

  • final – use elastic net regularization

  • verbose – print progress

  • device – ‘cuda’ or ‘cpu’

Returns:

(G, n_networks) inferred interaction parameters basal: (n_networks,) inferred basal parameters losses: list of loss values during training

Return type:

inter

CardamomOT.inference.network_final.inference_network_pytorch(vect_t, times, y_samples, y_kon, y_proba, y_prot, y_prot_prev, ks, inter_init=np.zeros(2), basal_init=np.zeros(2), ref_network=np.zeros(2), inter_ref=None, basal_ref=None, proba=True, scale=100, weight_prev=0.5, loss='CE', lr=0.01, n_epochs=1000, verbose=True, final=1, device='cuda' if torch.cuda.is_available() else 'cpu') Any

Main entry point for PyTorch network inference Simplified version without temporal dynamics and refinement

Parameters:
  • y_samples – (n_cells,) sample indices

  • y_kon – (n_cells, G) target kon values for all genes

  • y_proba – (n_cells, G, n_networks+1) target probabilities for all genes

  • y_prot – (n_cells, G) protein expression (current)

  • y_prot_prev – (n_cells, G) protein expression (previous)

  • ks – (G, n_networks+1) activation rates per gene

  • inter_init – (G, G, n_networks) initial interaction parameters

  • basal_init – (G, n_networks) initial basal parameters

  • ref_network – (G, G, n_networks) reference network structure

  • inter_ref – (G, G, n_networks) reference interaction parameters

  • basal_ref – (G, n_networks) reference basal parameters

  • proba – predict probabilities or kon

  • scale – penalization scaling

  • weight_prev – weight for previous timepoint

  • loss_type – ‘l1’, ‘l2’, or ‘CE’

  • lr – learning rate

  • n_epochs – training epochs

  • final – use elastic net

  • verbose – print progress

  • device – computation device

Returns:

(G, G, n_networks) inferred interaction matrix basal: (G, n_networks) inferred basal parameters all_losses: dict with losses per gene

Return type:

inter