# Subset policy#

This example shows how to use different policies.

A policy is the rule which sets of transport maps are computed given different distributions of cells. Some problem classes require a certain policy, e.g., the MappingProblem only works with the ExternalStarPolicy meaning that all spatial batches from the AnnData object are mapped to the same single cell reference cell distribution.

Each problem class has a set of valid policies. For the LineageProblem and the TemporalProblem, we can choose among different policies as demonstrated below.

• TODO: link to other relevant examples

from moscot import datasets
from moscot.problems.time import TemporalProblem

Simulate data using simulate_data().

AnnData object with n_obs × n_vars = 80 × 60
obs: 'day', 'celltype'

This simulated dataset contains single cell data across 4 time points (0–3). The policy allows us to determine which transport maps we want to compute.

## TemporalProblem policies#

### SequentialPolicy#

We start with the default policy, which is the SequentialPolicy. The following code shows which optimal transport (OT) problems are prepared to be solved.

We see that all consecutive pairs of values in the time_key column are used to create an OT problem.

tp_sequential = tp_sequential.prepare(time_key="day", policy="sequential")
tp_sequential.problems
INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X
{(0, 1): BirthDeathProblem[stage='prepared', shape=(20, 20)],
(1, 2): BirthDeathProblem[stage='prepared', shape=(20, 20)],
(2, 3): BirthDeathProblem[stage='prepared', shape=(20, 20)]}

### TriangularPolicy#

tp_triu = tp_triu.prepare(time_key="day", policy="triu")
tp_triu.problems
INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X
{(0, 1): BirthDeathProblem[stage='prepared', shape=(20, 20)],
(1, 2): BirthDeathProblem[stage='prepared', shape=(20, 20)],
(0, 3): BirthDeathProblem[stage='prepared', shape=(20, 20)],
(2, 3): BirthDeathProblem[stage='prepared', shape=(20, 20)],
(0, 2): BirthDeathProblem[stage='prepared', shape=(20, 20)],
(1, 3): BirthDeathProblem[stage='prepared', shape=(20, 20)]}

### ExplicitPolicy#

INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X
INFO     Computing pca with n_comps=30 for xy using adata.X