CDCgov / CDCgov/PyRenew

Add `LogitNormalVariable` as pre-specified RV

Open
#853 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
29
Forks
9
Avg merge
9d 9h
Merged PRs (30d)
8

Description

A logit normal prior is a useful distribution. Currently, it is specified via low-level classes DistributionalVariable and TransformedVariable, e.g.:

iedr_rv = TransformedVariable(
    name="iedr",
    base_rv=DistributionalVariable(
        name="logit_iedr",
        distribution=dist.Normal(
            transformation.SigmoidTransform().inv(0.004),
            0.3,
        ),
    ),
    transforms=transformation.SigmoidTransform(),
)

Instead, it should be possible to specify:

iedr_rv = LogitNormalVariable(name="iedr",  base_name="logit_iedr",  median=0.004,  scale=0.3)

Add class LogitNormalVariable to pyrenew.randomvaraible to make this a first-class PyRenew component:

from pyrenew.randomvariable import DistributionalVariable, TransformedVariable
  import pyrenew.transformation as transformation
  import numpyro.distributions as dist

  def LogitNormalVariable(
      name: str,
      median: float,
      scale: float,
      base_name: str | None = None,
  ) -> TransformedVariable:
      return TransformedVariable(
          name=name,
          base_rv=DistributionalVariable(
              name=base_name or f"logit_{name}",
              distribution=dist.Normal(
                  transformation.SigmoidTransform().inv(median),
                  scale,
              ),
          ),
          transforms=transformation.SigmoidTransform(),
      )

Tests should verify:

  • returned object is a TransformedVariable,
  • base RV uses dist.Normal(logit(median), scale),
  • samples lie in (0, 1),
  • names are recorded as expected.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the pyrenew.randomvariable module by reading DistributionalVariable and TransformedVariable, then inspect transformation.SigmoidTransform and the existing tests for these components. Add the LogitNormalVariable entry point and tests covering its return type, Normal parameters, sample bounds, and recorded names.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.