smoother.models.impute
Impute spatial feature of interest with spatial loss
Classes
Class for different implementations of spatial imputation. |
|
Imputation solver implemented using pytorch. |
|
Imputation solver implemented using cvxpy. |
Module Contents
- class smoother.models.impute.ImputeModel(y_obs, spatial_loss_all: smoother.losses.SpatialLoss, fixed_obs=True, nonneg=False, **kwargs)
Class for different implementations of spatial imputation.
This class is designed for coorperative inheritance (mixin).
- y_obs
Observed spatial feature matrix, n_obs x n_feature.
- Type:
2D tensor
- spatial_loss_all
Spatial loss object build from the combined spatial coordinates containing both observed (the first n_obs rows) and missing spots (the rest rows).
- Type:
- var_obs
Observed spatial feature matrix, n_obs x n_feature.
- var_missing
Missing spatial feature matrix to impute, n_missing x n_feature.
- var_all
Concatenated observed and missing spatial feature matrix, n_all x n_feature.
- y_obs = None
- spatial_loss_all = None
- fixed_obs = None
- nonneg = None
- n_feature = None
- n_obs = None
- n_all = None
- n_missing = None
- var_obs = None
- var_missing = None
- var_all = None
- impute_configs = None
- impute_time = 0
- set_params(y_obs, spatial_loss_all, fixed_obs=True, nonneg=False)
Set configuration parameters and initialize variables.
- abstract set_variables()
Set variables to impute.
- abstract get_recon_loss()
Get reconstruction loss.
- abstract get_sp_loss()
Get spatial loss (weighted by lambda_spatial_loss).
- abstract get_results()
Get spatial features after imputation.
- class smoother.models.impute.ImputeTorch(y_obs, spatial_loss_all: smoother.losses.SpatialLoss, fixed_obs=True, nonneg=False, **kwargs)
Bases:
ImputeModel,torch.nn.ModuleImputation solver implemented using pytorch.
- var_obs
Observed spatial feature matrix, n_obs x n_feature.
- Type:
2D tensor
- var_missing
Missing spatial feature matrix to impute, n_missing x n_feature.
- Type:
2D tensor
- var_all
Concatenated observed and missing spatial feature matrix, n_all x n_feature.
- Type:
2D tensor
- See super class attributes for additional arguments.
- impute_flag = False
- set_variables()
Initialize torch parameters to estimate.
- forward(y_obs, **kwargs)
Run imputation for a new set of spatial features.
- get_recon_loss()
Calculate loss of deviation from observation.
If the observed data is not fixed, then the loss is used to make sure data does not deviate too much from the observed value after imputation.
- get_sp_loss()
Calculate loss of spatial smoothness.
- get_results()
Get spatial features of all spots after imputation.
The first n_obs spots are the observed spots and the rest are the missing ones. If fixed_obs is True, then the returned observed data is not updated.
- final_sanity_check()
- impute(lambda_spatial_loss=1.0, lr=0.001, max_epochs=1000, patience=10, tol=1e-05, verbose=True, quiet=False) bool
Run imputation algorithm.
- Parameters:
lambda_spatial_loss (float) – Specifies the strength of the spatial smoothing.
lr (float) – Learning rate.
max_epochs (int) – Maximum number of training epochs. If -1, iterate until convergence (d_loss < tol).
patient (int) – Number of epochs to wait for the loss to decrease before stopping.
tol (float) – Tolerance of loss convergence.
verbose (bool) – If True, print out loss while training.
quiet (bool) – If True, no output printed.
- Returns:
True if imputation is successful.
- Return type:
- class smoother.models.impute.ImputeConvex(y_obs, spatial_loss_all: smoother.losses.SpatialLoss, fixed_obs=True, nonneg=False, **kwargs)
Bases:
ImputeModelImputation solver implemented using cvxpy.
- var_obs
Observed spatial feature matrix, n_obs x n_feature.
- var_missing
Missing spatial feature matrix to impute, n_missing x n_feature.
- var_all
Concatenated observed and missing spatial feature matrix, n_all x n_feature.
- recon_loss_exp
Reconstruction loss expression.
- Type:
cp.Expression
- sp_loss_exp
Spatial loss expression.
- Type:
cp.Expression
- See super class attributes for additional arguments.
- recon_loss_exp = None
- spatial_loss_exp = None
- impute_flag = False
- set_variables()
Initialize parameters to estimate.
- set_recon_loss()
Set loss expression of deviation from observation.
If the observed data is not fixed, then the loss is used to make sure data does not deviate too much from the observed value after imputation.
- set_sp_loss()
Set spatial loss expression (before weighted by lambda_spatial_loss).
- get_recon_loss()
Calculate loss of deviation from observation.
If the observed data is not fixed, then the loss is used to make sure data does not deviate too much from the observed value after imputation.
- get_sp_loss()
Calculate loss of spatial smoothness (weighted by lambda_spatial_loss).
- get_results()
Get spatial features of all spots after imputation.
The first n_obs spots are the observed spots and the rest are the missing ones. If fixed_obs is True, then the returned observed data is not updated.