Skip to content

simulator

Simulator

Simulation abstract class

This abstract simulator class defines the minimal methods that must be exported by every simulator in scdesigner. These methods are:

* `fit`: Given an anndata dataset object, estimate the model parameters.
* `predict`: Given experimental and biological features x in the form of
   a cell-by-features pd.DataFrame, return the parameters theta(x) of
   interest.
* `sample`: Given the same experimental/biological information x as
  `predict`, simulate hypothetical profiles associated wtih those
  samples.

Example instantiations of this class are given in the module scdesigner.base.simulators.

Examples:

>>> import scdesigner.datasets
>>>
>>> pancreas = scdesigner.datasets.pancreas()
>>> sim = Simulator()
>>> sim.parameters
>>>
>>> # this is how a subclass would run, once its fit, predict, and sample
>>> # methods are implemented.
>>> sim.fit(pancreas)
>>> sim.predict(pancreas.obs)
>>> sim.sample(pancreas.obs)
Source code in scdesigner/src/scdesigner/base/simulator.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Simulator:
    """Simulation abstract class

    This abstract simulator class defines the minimal methods that must be
    exported by every simulator in scdesigner. These methods are:

        * `fit`: Given an anndata dataset object, estimate the model parameters.
        * `predict`: Given experimental and biological features x in the form of
           a cell-by-features pd.DataFrame, return the parameters theta(x) of
           interest.
        * `sample`: Given the same experimental/biological information x as
          `predict`, simulate hypothetical profiles associated wtih those
          samples.

    Example instantiations of this class are given in the module
    `scdesigner.base.simulators`.

    Examples
    --------
    >>> import scdesigner.datasets
    >>>
    >>> pancreas = scdesigner.datasets.pancreas()
    >>> sim = Simulator()
    >>> sim.parameters
    >>>
    >>> # this is how a subclass would run, once its fit, predict, and sample
    >>> # methods are implemented.
    >>> sim.fit(pancreas) # doctest: +SKIP
    >>> sim.predict(pancreas.obs) # doctest: +SKIP
    >>> sim.sample(pancreas.obs) # doctest: +SKIP
    """
    def __init__(self):
        self.parameters = None

    @abstractmethod
    def fit(self, anndata: AnnData, **kwargs) -> None:
        """Fit the simulator

        Parameters
        ----------
        anndata : AnnData
            This is the object on which we want to estimate the simulator. This
            serves as the template for all downstream fitting.
        """
        self.template = anndata
        raise NotImplementedError

    @abstractmethod
    def predict(self, obs: DataFrame=None, **kwargs) -> Dict:
        """Predict from an obs dataframe"""
        raise NotImplementedError

    @abstractmethod
    def sample(self, obs: DataFrame=None, **kwargs) -> AnnData:
        """Generate samples."""
        raise NotImplementedError

fit(anndata, **kwargs) abstractmethod

Fit the simulator

Parameters:

Name Type Description Default
anndata AnnData

This is the object on which we want to estimate the simulator. This serves as the template for all downstream fitting.

required
Source code in scdesigner/src/scdesigner/base/simulator.py
40
41
42
43
44
45
46
47
48
49
50
51
@abstractmethod
def fit(self, anndata: AnnData, **kwargs) -> None:
    """Fit the simulator

    Parameters
    ----------
    anndata : AnnData
        This is the object on which we want to estimate the simulator. This
        serves as the template for all downstream fitting.
    """
    self.template = anndata
    raise NotImplementedError

predict(obs=None, **kwargs) abstractmethod

Predict from an obs dataframe

Source code in scdesigner/src/scdesigner/base/simulator.py
53
54
55
56
@abstractmethod
def predict(self, obs: DataFrame=None, **kwargs) -> Dict:
    """Predict from an obs dataframe"""
    raise NotImplementedError

sample(obs=None, **kwargs) abstractmethod

Generate samples.

Source code in scdesigner/src/scdesigner/base/simulator.py
58
59
60
61
@abstractmethod
def sample(self, obs: DataFrame=None, **kwargs) -> AnnData:
    """Generate samples."""
    raise NotImplementedError