Skip to content

leafletfa.model

leafletfa.model.LeafletFA

__init__(adata, K=10, junc_specific_prior=True, input_conc_prior=None, delta_fixed=None, waypoints_use=True, fixed_psi=None, use_dense_mode=None, pi_init=None, alpha_pi_init=None, log_wandb=False, eps=1e-06, lr=0.01, gamma=0.05, num_epochs=500, print_epochs=10, ELBO_num_particles=1, patience=5, min_delta=0.01, num_samples=10, loss_plot=True, output_dir=None, enable_cpu_optimization=True)

Initialize the LeafletFA model with CPU optimizations.

Parameters: - adata (AnnData): AnnData object containing single-cell splicing data. - K (int): Number of factors. - junc_specific_prior (bool): Whether to learn a global prior over junctions. - input_conc_prior: Concentration prior (can be either 'None' or 'torch.tensor(np.inf)'). - waypoints_use (bool): Whether to use waypoints for initialization. - pi_init (torch.Tensor): Initialization for the pi vector. - alpha_pi_init (torch.Tensor): Initialization for the alpha_pi vector. - fixed_psi (torch.Tensor): Fix PSI during inference by using an existing PSI latent variable from previous model training. - use_dense_mode (bool): Whether to use dense mode for computation. - eps (float): Small value to prevent numerical issues. - lr (float): Learning rate. - gamma (float): Learning rate decay. - num_epochs (int): Number of training epochs. - print_epochs (int): Print loss every 'print_epochs' epochs. - ELBO_num_particles (int): Number of particles for ELBO calculation. - patience (int): Early stopping patience. - min_delta (float): Minimum improvement for early stopping. - num_samples (int): Number of samples to collect from the guide. - loss_plot (bool): Whether to plot loss. - output_dir (str): Directory to save results. - enable_cpu_optimization (bool): Whether to enable CPU-specific optimizations.

from_anndata(float_type=None)

Process an AnnData object and return PyTorch sparse tensors for junction and cluster counts. Optimized for CPU with better memory patterns.

train(num_initializations=3, seeds=None, psi_init=None, phi_init=None, save_to_file=False, file_prefix=None)

Train the model using SVI with CPU optimizations, collect samples, and return results. Main function to fit our Leaflet Bayesian beta-dirichlet factor model.

Parameters: - num_initializations (int): Number of random initializations. - seeds (list, optional): List of seeds for random initializations. - psi_init (torch.Tensor, optional): Pre-initialized values for psi. - phi_init (torch.Tensor, optional): Pre-initialized values for assign (phi). - save_to_file (bool): Whether to save the results to a file. - file_prefix (str, optional): Prefix for the saved file name.

Returns: - all_results (list): List of results containing losses, latent variables, and summary statistics. - variable_sizes (dict): Dictionary containing sizes of model variables.

get_all_variables(initialization=None)

Extract all variables from the best initialization: This includes PSI, PI, BB_CONC, and the latent representation PHI.