Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies = [
"jax>=0.7.0",
"numpy>=2.4.4",
"polars>=1.2.1",
"numpyro>=0.19.0",
"numpyro>=0.21.0",
]

[dependency-groups]
Expand Down
3 changes: 1 addition & 2 deletions pyrenew/datasets/datagen_he_CA_126.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def sample_negbinom(
Parameters
----------
mu : np.ndarray
Mean values (must be positive).
Mean values (must be non-negative).
concentration : float
Concentration parameter (higher = less overdispersion).
rng : np.random.Generator
Expand All @@ -256,7 +256,6 @@ def sample_negbinom(
np.ndarray
Integer counts.
"""
mu = np.maximum(mu, 1e-10)
p = concentration / (concentration + mu)
return rng.negative_binomial(n=concentration, p=p)

Expand Down
7 changes: 1 addition & 6 deletions pyrenew/observation/negativebinomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(
self,
name: str,
concentration_rv: RandomVariable,
eps: float = 1e-10,
) -> None:
"""
Default constructor
Expand All @@ -32,17 +31,13 @@ def __init__(
despite the fact that larger values imply that the distribution
becomes more Poissonian, while smaller ones imply a greater degree
of dispersion.
eps
Small value to add to the predicted mean to prevent numerical
instability. Defaults to 1e-10.

Returns
-------
None
"""
super().__init__(name=name)
self.concentration_rv = concentration_rv
self.eps = eps

def sample(
self,
Expand Down Expand Up @@ -71,7 +66,7 @@ def sample(
negative_binomial_sample = numpyro.sample(
name=self.name,
fn=dist.NegativeBinomial2(
mean=mu + self.eps,
mean=mu,
concentration=concentration,
),
obs=obs,
Expand Down
6 changes: 2 additions & 4 deletions pyrenew/observation/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

from pyrenew.metaclass import RandomVariable

_EPSILON = 1e-10


class CountNoise(ABC):
"""
Expand Down Expand Up @@ -127,7 +125,7 @@ def sample(
with numpyro.handlers.mask(mask=True if mask is None else mask):
return numpyro.sample(
name,
dist.Poisson(rate=predicted + _EPSILON),
dist.Poisson(rate=predicted),
obs=obs,
)

Expand Down Expand Up @@ -214,7 +212,7 @@ def sample(
return numpyro.sample(
name,
dist.NegativeBinomial2(
mean=predicted + _EPSILON,
mean=predicted,
concentration=concentration,
),
obs=obs,
Expand Down
Loading
Loading