scfocus.focus.focus
- class scfocus.focus.focus(f, hidden_dim=128, n=8, max_steps=5, pct_samples=0.125, n_states=2, err_scale=1, bins=15, capacity=10000.0, actor_lr=0.0001, critic_lr=0.001, alpha_lr=0.0001, target_entropy=-1, tau=0.005, gamma=0.99, num_episodes=1000.0, batch_size=64, res=0.05, device=device(type='cpu'))[source]
Focus class for performing advanced reinforcement learning-based analysis on single-cell data.
This class utilizes the Soft Actor-Critic (SAC) reinforcement learning framework to enhance cell subtype discrimination and identify distinct lineage branches within single-cell data. It manages the environment, memory buffers, and the ensemble of SAC agents to train and evaluate the model over multiple episodes.
- Parameters:
f (array-like) – Latent space of the original data, with shape (num_samples, num_features).
hidden_dim (int, optional) – Number of hidden units in the neural networks, by default 128.
n (int, optional) – Number of agents or parallel environments, by default 8.
max_steps (int, optional) – Maximum number of steps per episode, by default 5.
pct_samples (float, optional) – Percentage of samples to use for each state, by default 0.125.
n_states (int, optional) – Number of state variables, by default 2.
err_scale (float, optional) – Error scaling factor for reward calculation, by default 1.
bins (int, optional) – Number of bins for histogram-based state discretization, by default 15.
capacity (float, optional) – Capacity of the replay buffer, by default 1e4.
actor_lr (float, optional) – Learning rate for the actor network, by default 1e-4.
critic_lr (float, optional) – Learning rate for the critic network, by default 1e-3.
alpha_lr (float, optional) – Learning rate for the entropy coefficient, by default 1e-4.
target_entropy (float, optional) – Target entropy for the SAC algorithm, by default -1.
tau (float, optional) – Soft update coefficient for target networks, by default 5e-3.
gamma (float, optional) – Discount factor for future rewards, by default 0.99.
num_episodes (int, optional) – Number of training episodes, by default 1000.
batch_size (int, optional) – Batch size for training, by default 64.
res (float, optional) – Resolution parameter for merging focus patterns, by default 0.05.
device (torch.device, optional) – Device to run the computations on (e.g., CPU or GPU), by default torch.device(‘cpu’).
- __init__(f, hidden_dim=128, n=8, max_steps=5, pct_samples=0.125, n_states=2, err_scale=1, bins=15, capacity=10000.0, actor_lr=0.0001, critic_lr=0.001, alpha_lr=0.0001, target_entropy=-1, tau=0.005, gamma=0.99, num_episodes=1000.0, batch_size=64, res=0.05, device=device(type='cpu'))[source]
Initialize the Focus class.
- Parameters:
f (array-like) – Latent space of the original data, with shape (num_samples, num_features).
hidden_dim (int, optional) – Number of hidden units in the neural networks, by default 128.
n (int, optional) – Number of agents or parallel environments, by default 8.
max_steps (int, optional) – Maximum number of steps per episode, by default 5.
pct_samples (float, optional) – Percentage of samples to use for each state, by default 0.125.
n_states (int, optional) – Number of state variables, by default 2.
err_scale (float, optional) – Error scaling factor for reward calculation, by default 1.
bins (int, optional) – Number of bins for histogram-based state discretization, by default 15.
capacity (float, optional) – Capacity of the replay buffer, by default 1e4.
actor_lr (float, optional) – Learning rate for the actor network, by default 1e-4.
critic_lr (float, optional) – Learning rate for the critic network, by default 1e-3.
alpha_lr (float, optional) – Learning rate for the entropy coefficient, by default 1e-4.
target_entropy (float, optional) – Target entropy for the SAC algorithm, by default -1.
tau (float, optional) – Soft update coefficient for target networks, by default 5e-3.
gamma (float, optional) – Discount factor for future rewards, by default 0.99.
num_episodes (int, optional) – Number of training episodes, by default 1000.
batch_size (int, optional) – Batch size for training, by default 64.
res (float, optional) – Resolution parameter for merging focus patterns, by default 0.05.
device (torch.device, optional) – Device to run the computations on (e.g., CPU or GPU), by default torch.device(‘cpu’).
Methods
__init__(f[, hidden_dim, n, max_steps, ...])Initialize the Focus class.
focus_diff()Calculate entropy and pseudotime based on merged focus patterns.
focus_fit(episodes)Fit the focus model over a specified number of episodes.
merge_fp()Merge focus patterns based on similarity thresholds.
merge_fp2()Merge focus patterns by performing two levels of merging.
meta_fit()Perform a single meta fitting step by training a new SAC agent and updating memory.
meta_focusing(n)Perform meta focusing by iteratively fitting the ensemble and refining focus.