Skip to content

Commit 48c41f9

Browse files
committed
doc: Various fixes
* Replace references to private functions * Fix some typos and formatting Closes #3062.
1 parent d1de05d commit 48c41f9

File tree

8 files changed

+145
-33
lines changed

8 files changed

+145
-33
lines changed

python/sdist/amici/_symbolic/de_model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class DEModel:
181181
partial derivative in the next recursion. prevents infinite recursion
182182
183183
:ivar _simplify:
184-
If not None, this function will be used to simplify symbolic
184+
If not ``None``, this function will be used to simplify symbolic
185185
derivative expressions. Receives sympy expressions as only argument.
186186
To apply multiple simplifications, wrap them in a lambda expression.
187187
@@ -219,8 +219,7 @@ def __init__(
219219
see :meth:`DEModel._simplify`
220220
221221
:param cache_simplify:
222-
Whether to cache calls to the simplify method. Can e.g. decrease
223-
import times for models with events.
222+
Whether to cache calls to the simplify method.
224223
"""
225224
self._differential_states: list[DifferentialState] = []
226225
self._algebraic_states: list[AlgebraicState] = []

python/sdist/amici/importers/antimony/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77
from pathlib import Path
88

9-
__all__ = ["antimony2sbml", "antimony2amici"]
9+
from ..utils import MeasurementChannel
10+
11+
__all__ = [
12+
"antimony2sbml",
13+
"antimony2amici",
14+
"MeasurementChannel",
15+
]
1016

1117

1218
def antimony2sbml(ant_model: str | Path) -> str:

python/sdist/amici/importers/bngl/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
from pysb.importers.bngl import model_from_bngl
99

1010
from ..pysb import pysb2amici
11+
from ..utils import MeasurementChannel
1112

12-
__all__ = ["bngl2amici"]
13+
__all__ = [
14+
"bngl2amici",
15+
"MeasurementChannel",
16+
]
1317

1418

1519
def bngl2amici(bngl_model: str, *args, **kwargs) -> None:

python/sdist/amici/importers/petab/_petab_importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def import_module(self, force_import: bool = False) -> amici.ModelModule:
582582
self.outdir,
583583
)
584584

585-
def create_model(self) -> amici.Model:
585+
def create_model(self) -> amici.sim.sundials.Model:
586586
"""Create a :class:`amici.Model` instance from the imported model."""
587587
return self.import_module().get_model()
588588

python/sdist/amici/importers/pysb/__init__.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"pysb_model_from_path",
5555
"pysb2amici",
5656
"pysb2jax",
57+
"MeasurementChannel",
5758
]
5859

5960
CL_Prototype = dict[str, dict[str, Any]]
@@ -89,11 +90,12 @@ def pysb2jax(
8990
simulations.
9091
9192
:param model:
92-
pysb model, :attr:`pysb.core.Model.name` will determine the name of the
93-
generated module
93+
PySB model, :class:`model.name <pysb.core.Model>` will determine the
94+
name of the generated module.
9495
9596
:param output_dir:
96-
see :meth:`amici.de_export.ODEExporter.set_paths`
97+
The directory where the generated model code is stored.
98+
Will be created if it does not exist.
9799
98100
:param observation_model:
99101
The different measurement channels that make up the observation
@@ -113,13 +115,15 @@ def pysb2jax(
113115
if set to ``True``, conservation laws are automatically computed and
114116
applied such that the state-jacobian of the ODE right-hand-side has
115117
full rank. This option should be set to ``True`` when using the Newton
116-
algorithm to compute steadystates
118+
algorithm to compute steady states.
117119
118120
:param simplify:
119-
see :attr:`amici.DEModel._simplify`
121+
If not ``None``, this function will be used to simplify symbolic
122+
derivative expressions. Receives sympy expressions as only argument.
123+
To apply multiple simplifications, wrap them in a lambda expression.
120124
121125
:param cache_simplify:
122-
see :func:`amici.DEModel.__init__`
126+
Whether to cache calls to the simplify method.
123127
Note that there are possible issues with PySB models:
124128
https://github.com/AMICI-dev/AMICI/pull/1672
125129
@@ -190,11 +194,12 @@ def pysb2amici(
190194
simulations.
191195
192196
:param model:
193-
pysb model, :attr:`pysb.core.Model.name` will determine the name of the
194-
generated module
197+
PySB model, :class:`model.name <pysb.core.Model>` will determine the
198+
name of the generated module.
195199
196200
:param output_dir:
197-
see :meth:`amici.de_export.ODEExporter.set_paths`
201+
The directory where the generated model code is stored.
202+
Will be created if it does not exist.
198203
199204
:param observation_model:
200205
The different measurement channels that make up the observation
@@ -234,12 +239,14 @@ def pysb2amici(
234239
just generate the source code.
235240
236241
:param simplify:
237-
see :attr:`amici.DEModel._simplify`
242+
If not ``None``, this function will be used to simplify symbolic
243+
derivative expressions. Receives sympy expressions as only argument.
244+
To apply multiple simplifications, wrap them in a lambda expression.
238245
239246
:param cache_simplify:
240-
see :func:`amici.DEModel.__init__`
241-
Note that there are possible issues with PySB models:
242-
https://github.com/AMICI-dev/AMICI/pull/1672
247+
Whether to cache calls to the simplify method.
248+
Note that there are possible issues with PySB models:
249+
https://github.com/AMICI-dev/AMICI/pull/1672
243250
244251
:param generate_sensitivity_code:
245252
if set to ``False``, code for sensitivity computation will not be
@@ -341,12 +348,14 @@ def ode_model_from_pysb_importer(
341348
see :func:`amici.importers.pysb.pysb2amici`
342349
343350
:param simplify:
344-
see :attr:`amici.DEModel._simplify`
351+
If not ``None``, this function will be used to simplify symbolic
352+
derivative expressions. Receives sympy expressions as only argument.
353+
To apply multiple simplifications, wrap them in a lambda expression.
345354
346355
:param cache_simplify:
347-
see :func:`amici.DEModel.__init__`
348-
Note that there are possible issues with PySB models:
349-
https://github.com/AMICI-dev/AMICI/pull/1672
356+
Whether to cache calls to the simplify method.
357+
Note that there are possible issues with PySB models:
358+
https://github.com/AMICI-dev/AMICI/pull/1672
350359
351360
:param verbose: verbosity level for logging, True/False default to
352361
:attr:`logging.DEBUG`/:attr:`logging.ERROR`
@@ -1599,7 +1608,8 @@ def _get_changed_stoichiometries(
15991608

16001609

16011610
def pysb_model_from_path(pysb_model_file: str | Path) -> pysb.Model:
1602-
"""Load a pysb model module and return the :class:`pysb.Model` instance
1611+
"""
1612+
Load a PySB model module and return the :class:`pysb.core.Model` instance.
16031613
16041614
:param pysb_model_file: Full or relative path to the PySB model module
16051615
:return: The pysb Model instance

python/sdist/amici/importers/sbml/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,14 @@ def sbml2amici(
349349
case of stoichiometric coefficients with many significant digits.
350350
351351
:param simplify:
352-
See :attr:`amici.DEModel._simplify`.
352+
If not ``None``, this function will be used to simplify symbolic
353+
derivative expressions. Receives sympy expressions as only argument.
354+
To apply multiple simplifications, wrap them in a lambda expression.
353355
354356
:param cache_simplify:
355-
See :meth:`amici.DEModel.__init__`.
357+
Whether to cache calls to the simplify method.
358+
Note that there are possible issues with PySB models:
359+
https://github.com/AMICI-dev/AMICI/pull/1672
356360
357361
:param generate_sensitivity_code:
358362
If ``False``, the code required for sensitivity computation will
@@ -486,10 +490,14 @@ def sbml2jax(
486490
case of stoichiometric coefficients with many significant digits.
487491
488492
:param simplify:
489-
see :attr:`amici.DEModel._simplify`
493+
If not ``None``, this function will be used to simplify symbolic
494+
derivative expressions. Receives sympy expressions as only argument.
495+
To apply multiple simplifications, wrap them in a lambda expression.
490496
491497
:param cache_simplify:
492-
see :meth:`amici.DEModel.__init__`
498+
Whether to cache calls to the simplify method.
499+
Note that there are possible issues with PySB models:
500+
https://github.com/AMICI-dev/AMICI/pull/1672
493501
494502
:param hybridization:
495503
dict representation of the hybridization information in the PEtab YAML file, see

python/sdist/amici/importers/utils.py

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,87 @@ def __init__(
141141
"""
142142
Initialize a measurement channel.
143143
144+
145+
146+
The noise distributions listed in the following are supported.
147+
:math:`m` denotes the measurement, :math:`y` the simulation,
148+
and :math:`\\sigma` a distribution scale parameter
149+
(currently, AMICI only supports a single distribution parameter).
150+
151+
- `'normal'`, `'lin-normal'`: A normal distribution:
152+
153+
.. math::
154+
\\pi(m|y,\\sigma) = \\frac{1}{\\sqrt{2\\pi}\\sigma}\\
155+
exp\\left(-\\frac{(m-y)^2}{2\\sigma^2}\\right)
156+
157+
- `'log-normal'`: A log-normal distribution (i.e. log(m) is
158+
normally distributed):
159+
160+
.. math::
161+
\\pi(m|y,\\sigma) = \\frac{1}{\\sqrt{2\\pi}\\sigma m}\\
162+
exp\\left(-\\frac{(\\log m - \\log y)^2}{2\\sigma^2}\\right)
163+
164+
- `'log10-normal'`: A log10-normal distribution (i.e. log10(m) is
165+
normally distributed):
166+
167+
.. math::
168+
\\pi(m|y,\\sigma) = \\frac{1}{\\sqrt{2\\pi}\\sigma m \\log(10)}\\
169+
exp\\left(-\\frac{(\\log_{10} m - \\log_{10} y)^2}{2\\sigma^2}\\right)
170+
171+
- `'laplace'`, `'lin-laplace'`: A laplace distribution:
172+
173+
.. math::
174+
\\pi(m|y,\\sigma) = \\frac{1}{2\\sigma}
175+
\\exp\\left(-\\frac{|m-y|}{\\sigma}\\right)
176+
177+
- `'log-laplace'`: A log-Laplace distribution (i.e. log(m) is Laplace
178+
distributed):
179+
180+
.. math::
181+
\\pi(m|y,\\sigma) = \\frac{1}{2\\sigma m}
182+
\\exp\\left(-\\frac{|\\log m - \\log y|}{\\sigma}\\right)
183+
184+
- `'log10-laplace'`: A log10-Laplace distribution (i.e. log10(m) is
185+
Laplace distributed):
186+
187+
.. math::
188+
\\pi(m|y,\\sigma) = \\frac{1}{2\\sigma m \\log(10)}
189+
\\exp\\left(-\\frac{|\\log_{10} m - \\log_{10} y|}{\\sigma}\\right)
190+
191+
- `'binomial'`, `'lin-binomial'`: A (continuation of a discrete) binomial
192+
distribution, parameterized via the success probability
193+
:math:`p=\\sigma`:
194+
195+
.. math::
196+
\\pi(m|y,\\sigma) = \\operatorname{Heaviside}(y-m) \\cdot
197+
\\frac{\\Gamma(y+1)}{\\Gamma(m+1) \\Gamma(y-m+1)}
198+
\\sigma^m (1-\\sigma)^{(y-m)}
199+
200+
- `'negative-binomial'`, `'lin-negative-binomial'`: A (continuation of a
201+
discrete) negative binomial distribution, with `mean = y`,
202+
parameterized via success probability `p`:
203+
204+
.. math::
205+
206+
\\pi(m|y,\\sigma) = \\frac{\\Gamma(m+r)}{\\Gamma(m+1) \\Gamma(r)}
207+
(1-\\sigma)^m \\sigma^r
208+
209+
where
210+
211+
.. math::
212+
r = \\frac{1-\\sigma}{\\sigma} y
213+
214+
The distributions above are for a single data point.
215+
For a collection :math:`D=\\{m_i\\}_i` of data points and corresponding
216+
simulations :math:`Y=\\{y_i\\}_i` and noise parameters
217+
:math:`\\Sigma=\\{\\sigma_i\\}_i`, AMICI assumes independence,
218+
i.e. the full distributions is
219+
220+
.. math::
221+
\\pi(D|Y,\\Sigma) = \\prod_i\\pi(m_i|y_i,\\sigma_i)
222+
223+
AMICI uses the logarithm :math:`\\log(\\pi(m|y,\\sigma)`.
224+
144225
.. note::
145226
146227
When providing expressions for (event) observables and their sigmas
@@ -167,10 +248,14 @@ def __init__(
167248
and parameters.
168249
:param noise_distribution:
169250
Noise distribution associated with the observable.
170-
This is usually a string identifier (e.g., 'normal', 'log-normal';
171-
see
172-
:func:`amici.importers.utils.noise_distribution_to_cost_function`).
173-
If ``None``, a normal distribution is assumed.
251+
This is usually a string identifier:
252+
253+
{`'normal'`, `'lin-normal'`, `'log-normal'`, `'log10-normal'`,
254+
`'laplace'`, `'lin-laplace'`, `'log-laplace'`, `'log10-laplace'`,
255+
`'binomial'`, `'lin-binomial'`, `'negative-binomial'`,
256+
`'lin-negative-binomial'`}
257+
258+
For the meaning of the values see above.
174259
175260
Alternatively, a callable can be passed to account for a
176261
custom noise model. The callable must take a single argument

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ allowlist_externals =
2020
rm
2121
commands =
2222
rm -rf amici_models/ _doxyoutput_amici_cpp/ _exhale_cpp_api/ _exhale_matlab_api/ generated/ _build/
23-
sphinx-build -T -E -W --keep-going -b html -d _build/doctrees-readthedocs -D language=en . _build/html
23+
sphinx-build -T -E -W --keep-going -n -b html -d _build/doctrees-readthedocs -D language=en . _build/html

0 commit comments

Comments
 (0)