Skip to content

Add LogitNormalVariable as pre-specified RV #853

Description

@cdc-mitzimorris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions