pseudodynamics.functions.eval_funs¶
Functions
|
Normalize the density and compute the KL-divergence between observation and prediction |
|
Normalize the density and compute the Wasserstein distance between observation and prediction. |
|
Normalize the density and compute the Wasserstein distance between observation and prediction. |
|
Aggregate dynamic parameters by specific cell state label |
|
|
|
|
|
Predict the continuous change of dynamic parameters. |
|
simulate density for each cells for any two consecutive timepoints |
|
Given the setup dataset, evalute the behavior functions |
|
Compute MMD with Laplace kernel between two distributions. |
|
|
|
Project the parameters to the pseudotime and aggregate them by bins |
|
|
|
- pseudodynamics.functions.eval_funs.KLD_density(u_b, u_simulate, sanity_check=True)[source]¶
Normalize the density and compute the KL-divergence between observation and prediction
- Parameters:
u_b (ndarray, [n_time, n_cell] , observed density)
u_simulate (ndarray, [n_time, n_cell], inferred desity)
sanity_check (bool, whether check shape and positivity)
- Returns:
KLD_ls : ndarray, [n_time, ]
- pseudodynamics.functions.eval_funs.W_distance(u_b, u_simulate, p=2, log_transform=False)[source]¶
Normalize the density and compute the Wasserstein distance between observation and prediction. Log-density is supported, pass log_transform = True
- pseudodynamics.functions.eval_funs.W_log_distance(u_b, u_simulate, p=2, log_transform=False)[source]¶
Normalize the density and compute the Wasserstein distance between observation and prediction. Log-density is supported, pass log_transform = True
- pseudodynamics.functions.eval_funs.agg_param(adata, param, groupby_key='cell_type', timepoints=None, timepoint_key='timepoint_tx_days', cellcount_threshold=10, agg_fn='mean')[source]¶
Aggregate dynamic parameters by specific cell state label
Args:¶
adata (AnnData): Annotated data matrix param (str): Parameter name groupby_key (str): Cell state label timepoints (list): Timepoints to aggregate timepoint_key (str): Anndata.obs key in which the time label is stored cellcount_threshold (int) : the min number of cells in the cell type to be considered
Returns:¶
- :
(DataFrame): Aggregated parameters
- Parameters:
param (ndarray)
- pseudodynamics.functions.eval_funs.assign_nearest_cell(input_ay, adata, cellstate_key, n_dimension=None, n_trees=10, n_neighbors=None, annotation=None, return_model=False, idx=None)[source]¶
- pseudodynamics.functions.eval_funs.continuous_params(pde_model, DataSet, param='g', n_interval=10, groupby_key=None, agg_fun='mean', chunk_size=1000, device='cpu')[source]¶
Predict the continuous change of dynamic parameters. The cellstate observed at the last timepoint is used.
Args:¶
pde_model : nn.Module, sub-class of pdp.models.pde_params_base DataSet : sub-class of pdp.readers.HighdimAnnDS param : str, one of [‘g’, ‘v’, ‘D’, ‘u’] n_interval : number of intermediate point between two timepoints groupby_key : str, aggregate the predicted param according to cell type or cluster, one of the obs_key of the adata agg_fun : aggregtion function chunk_size : int, minibatch size device : str, on which device to compute the parameters i.e. cpu or cuda:0, cuda:1 …
- pseudodynamics.functions.eval_funs.density_shortterm_simulation(pde_model, DataSet, timepoint_idx=None, time_span=1, timepoints=None, cellstate=None, return_all=False)[source]¶
simulate density for each cells for any two consecutive timepoints
Args:¶
pde_model : nn.Module, sub-class of pdp.models.pde_params_base DataSet : sub-class of pdp.readers.HighdimAnnDS timepoint_idx : list of index , default the full timepoints defined in DataSet time_span : int , how many step of the timepoint index return_all : bool, if return the other output
Return:¶
- :
u_int_all : np.ndarry [n_timepoints, n_cells]
- pseudodynamics.functions.eval_funs.forward_get_params(pde_model, DataSet, t_ts=None, s_ts=None, timepoint_label=None)[source]¶
Given the setup dataset, evalute the behavior functions
Args:¶
pde_model : nn.Module, sub-class of pdp.models.pde_params_base DataSet : sub-class of pdp.readers.HighdimAnnDS t_ts : None , time point tensor s_ts : None , cell state tensor
- pseudodynamics.functions.eval_funs.mmd_laplace(X, Y, gamma=None)[source]¶
Compute MMD with Laplace kernel between two distributions.
- Parameters:
X (Samples from the two distributions (shape: [n_samples, n_features]).)
(array-like) (Y)
(float (gamma)
optional) (Bandwidth parameter. If None, uses median heuristic.)
- Returns:
float: MMD distance.
- pseudodynamics.functions.eval_funs.project_params_to_pseudotime(adata, params, param_names='g v2', timepoints=None, pseudotime_key='pseudotime_scaled', nbins=100, return_y=True)[source]¶
Project the parameters to the pseudotime and aggregate them by bins
- Parameters:
adata (AnnData object, the adata with pseudotime and obs)
params (list of np.ndarray, each array is the parameters for one timepoint)
param_names (str, the names of the parameters, e.g. 'g v2')
timepoints (list of int, the timepoints for the parameters, if None, use the timepoints in adata.uns['pop']['t'])
pseudotime_key (str, the key of the pseudotime in adata.obs, default 'pseudotime_scaled')
nbins (int, the number of bins to aggregate the pseudotime, default 100)
return_y (bool, if True, return the smoothed y values, otherwise return the figure and axes)
Return:¶
- :
fig, axs : matplotlib figure and axes, the figure with the aggregated parameters
if return_y : y_smooths
Example
>>> nbins =30 >>> y = pdp.tl.project_params_to_pseudotime(adata, params = adata.obs["vnorm_v1"].values.reshape(1,-1), param_names = 'v_v1', timepoints = adata.uns['pop']['t'][[0]], pseudotime_key = 'pseudotime_scaled', nbins = nbins+1, return_y = True)