Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Pass Documentation (docstrings) For Observation Folder #76

Merged
merged 11 commits into from
Apr 15, 2024
6 changes: 3 additions & 3 deletions model/src/pyrenew/latent/i0.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any

import numpyro as npro
import numpyro.distributions as dist
Expand All @@ -21,8 +21,8 @@ class Infections0(RandomVariable):

def __init__(
self,
name: Optional[str] = "I0",
I0_dist: Optional[dist.Distribution] = dist.LogNormal(0, 1),
name: str | None = "I0",
I0_dist: dist.Distribution | None = dist.LogNormal(0, 1),
) -> None:
"""Default constructor

Expand Down
3 changes: 1 addition & 2 deletions model/src/pyrenew/model/hospitalizations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

from collections import namedtuple
from typing import Optional

from numpy.typing import ArrayLike
from pyrenew.deterministic import DeterministicVariable
Expand Down Expand Up @@ -195,7 +194,7 @@ def sample_hospitalizations_obs(
def sample(
self,
n_timepoints: int,
observed_hospitalizations: Optional[ArrayLike] = None,
observed_hospitalizations: ArrayLike | None = None,
**kwargs,
) -> HospModelSample:
"""
Expand Down
34 changes: 28 additions & 6 deletions model/src/pyrenew/observation/negativebinomial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import numbers as nums
from typing import Any

import numpyro
import numpyro.distributions as dist
Expand All @@ -9,12 +10,20 @@


class NegativeBinomialObservation(RandomVariable):
"""Negative Binomial observation"""
"""Negative Binomial observation

Methods
-------
sample(predicted, obs, **kwargs)
Sample from the negative binomial distribution
validate(concentration_prior)
Check that the concentration prior is actually a nums.Number
"""

def __init__(
self,
concentration_prior: dist.Distribution | ArrayLike,
concentration_suffix: str = "_concentration",
concentration_suffix: str | None = "_concentration",
parameter_name="negbinom_rv",
) -> None:
"""Default constructor
Expand Down Expand Up @@ -54,7 +63,7 @@ def __init__(
def sample(
self,
predicted: ArrayLike,
obs: ArrayLike = None,
obs: ArrayLike | None = None,
**kwargs,
) -> tuple:
"""Sample from the negative binomial distribution
Expand All @@ -66,8 +75,7 @@ def sample(
obs : ArrayLike, optional
Observed data, by default None.
**kwargs : dict, optional
Additional keyword arguments passed through to internal `sample()`
calls, if any
Additional keyword arguments passed through to internal sample calls, should there be any.

Returns
-------
Expand All @@ -85,7 +93,21 @@ def sample(
)

@staticmethod
def validate(concentration_prior) -> None:
def validate(concentration_prior: Any) -> None:
"""
Check that the concentration prior is actually a nums.Number

Parameters
----------
concentration_prior : Any
Numpyro distribution from which to sample the positive concentration
parameter of the negative binomial. Expected dist.Distribution or
numbers.nums

Returns
-------
None
"""
assert isinstance(
concentration_prior, (dist.Distribution, nums.Number)
)
Expand Down
19 changes: 12 additions & 7 deletions model/src/pyrenew/observation/poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@
class PoissonObservation(RandomVariable):
"""
Poisson observation process

Methods
-------
sample(predicted, obs, **kwargs)
Sample from the Poisson process
"""

def __init__(
self,
parameter_name: str = "poisson_rv",
eps: float = 1e-8,
parameter_name: str | None = "poisson_rv",
eps: float | None = 1e-8,
) -> None:
"""Default Constructor

Parameters
----------
parameter_name : str, optional
Passed to numpyro.sample.
Passed to numpyro.sample. Defaults to "poisson_rv"
eps : float, optional
Small value added to the rate parameter to avoid zero values.
Defaults to 1e-8.

Returns
-------
Expand All @@ -38,7 +44,7 @@ def __init__(
def sample(
self,
predicted: ArrayLike,
obs: ArrayLike = None,
obs: ArrayLike | None = None,
**kwargs,
) -> tuple:
"""Sample from the Poisson process
Expand All @@ -48,10 +54,9 @@ def sample(
predicted : ArrayLike
Rate parameter of the Poisson distribution.
obs : ArrayLike, optional
Observed data, by default None.
Observed data. Defaults to None.
**kwargs : dict, optional
Additional keyword arguments passed through to internal `sample()`
calls, if any
Additional keyword arguments passed through to internal sample calls, should there be any.

Returns
-------
Expand Down