Skip to content

Conversation

@vanAmsterdam
Copy link
Contributor

@vanAmsterdam vanAmsterdam commented Oct 6, 2025

Implements LeftCensoredDistribution and RightCensoredDistribution

These distributions take any base_dist with a cdf method implemented and allow for handling left-or-right censored data. See Issue #1909.

Current status

  • implementation
  • standard tests
  • censored distribution specific tests

@vanAmsterdam vanAmsterdam changed the title Implement LeftCensoredDistribution and RightCensoredDistribution [WIP] Implement LeftCensoredDistribution and RightCensoredDistribution Oct 6, 2025
@vanAmsterdam vanAmsterdam marked this pull request as ready for review October 10, 2025 12:06
@vanAmsterdam
Copy link
Contributor Author

I've removed the tutorial / notebook from this PR to chop up the work

@vanAmsterdam vanAmsterdam changed the title [WIP] Implement LeftCensoredDistribution and RightCensoredDistribution Implement LeftCensoredDistribution and RightCensoredDistribution Oct 10, 2025
@vanAmsterdam
Copy link
Contributor Author

anyone up for a review? @juanitorduz @fehiepsi ?

@juanitorduz
Copy link
Collaborator

juanitorduz commented Oct 12, 2025

Great! I will take a look! In the meantime I think we need to add these distribution into the docs: https://github.com/pyro-ppl/numpyro/blob/master/docs/source/distributions.rst (you can use make docs to generate the docs locally)

Also, I think @fehiepsi 's review is key ;)

Copy link
Collaborator

@juanitorduz juanitorduz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @vanAmsterdam ! This looks great! Here are some initial comments :)

Question:
This PR handles left and right censoring. Are there plans for interval censoring (where we know the event occurred in an interval [a, b])? Or can we add a uni-test so see if we can do this already from this implementation?

@vanAmsterdam
Copy link
Contributor Author

Question: This PR handles left and right censoring. Are there plans for interval censoring (where we know the event occurred in an interval [a, b])? Or can we add a uni-test so see if we can do this already from this implementation?

I've code for this on a branch that's now out of sync (see https://github.com/vanAmsterdam/numpyro/blob/95fd78dee8fe794d6e59517ad4e3c09804fcdc5a/numpyro/distributions/censored.py#L220)
I wanted to split the work up in 2 PRs for easier review, but happy to go either way
the interval censoring needs some additional work, especially on tests

@juanitorduz
Copy link
Collaborator

Question: This PR handles left and right censoring. Are there plans for interval censoring (where we know the event occurred in an interval [a, b])? Or can we add a uni-test so see if we can do this already from this implementation?

I've code for this on a branch that's now out of sync (see https://github.com/vanAmsterdam/numpyro/blob/95fd78dee8fe794d6e59517ad4e3c09804fcdc5a/numpyro/distributions/censored.py#L220) I wanted to split the work up in 2 PRs for easier review, but happy to go either way the interval censoring needs some additional work, especially on tests

perfect! makes total sense 🙌

@juanitorduz
Copy link
Collaborator

@vanAmsterdam I created a PR to your branch to try to fix the docstrings (it now works fine for me) vanAmsterdam#2

@juanitorduz juanitorduz requested a review from fehiepsi October 13, 2025 17:58
@juanitorduz juanitorduz added the enhancement New feature or request label Oct 13, 2025
@juanitorduz
Copy link
Collaborator

You can try ruining make doctest locally to make the debugging easier :)

@vanAmsterdam
Copy link
Contributor Author

You can try ruining make doctest locally to make the debugging easier :)

yes figured this one out a little too late :) but it's passing now so I think we're set for a review. thanks for the help!

@juanitorduz
Copy link
Collaborator

@fehiepsi I think this one is ready for your review :)

Copy link
Member

@fehiepsi fehiepsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @vanAmsterdam and @juanitorduz!

Copy link
Member

@fehiepsi fehiepsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I have some minor comments.

def sample(
self, key: Optional[jax.dtypes.prng_key], sample_shape: tuple[int, ...] = ()
) -> ArrayLike:
return self.base_dist.sample(key, sample_shape)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need self.base_dict.expand(self.batch_shape).sample(...).

def sample(
self, key: Optional[jax.dtypes.prng_key], sample_shape: tuple[int, ...] = ()
) -> ArrayLike:
return self.base_dist.sample(key, sample_shape)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need self.base_dict.expand(self.batch_shape).sample(...). promote_shapes does not broadcast the parameters, it only adds some missing singleton dimensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch; updated in newest commit and also added a test

@fehiepsi fehiepsi merged commit f6e2675 into pyro-ppl:master Oct 19, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants