add `pydantic` validators capable of handling `numpyro.distributions` objects
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13
- Forks
- 3
- Avg merge
- 19h 43m
- Merged PRs (30d)
- 1
Description
imagine a basic pydantic class such as
from pydantic import BaseModel, NonNegativeFloat
from numpyro.distributions import Distribution
from dynode import DeterministicParameter
from jax.typing import ArrayLike
class Strain(BaseModel):
r0: Union[NonNegativeFloat, ArrayLike, Distribution, DeterministicParameter]
this class takes static values (NonNegativeFloat), it takes linked deterministic values (DeterministicParameter), it takes prior distributions (Distribution), as well as sampled jax values from said prior distribution (ArrayLike).
Currently there is no validators checking that the support of the Distribution object is actually non-negative. Thus we can pass a prior such as Normal(0, 1) which will be accepted and fit on, however occasionally produce negative R0s and likely break our ODEs. Because of the just-in-time nature of jax, we cannot easily validate the value after it has been sampled (BooleanConversionError), so it is best to validate the distributions themselves.
To mark this issue as complete please add custom distribution types such as NonNegativeDistribution or PositiveDistribution to dynode.typing, similar to dynode.typing.DynodeName
I would recommend building simple greater-than and less-than functions, then combining them together, this will allow us to build more complex validators in the future with the building blocks.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/dynode/typing/typing.py and inspect DynodeName, then trace how the Strain example's Union fields are validated against numpyro.distributions objects. Define the requested custom distribution types and their greater-than or less-than support checks. Done means invalid distribution supports are rejected while valid distributions remain usable in the shown model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100