Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement survival and log-survival function for the Normal distribution. #151

Merged
merged 1 commit into from
Apr 22, 2022
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
8 changes: 8 additions & 0 deletions distrax/_src/distributions/normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def log_cdf(self, value: Array) -> Array:
"""See `Distribution.log_cdf`."""
return jax.scipy.special.log_ndtr(self._standardize(value))

def survival_function(self, value: Array) -> Array:
"""See `Distribution.survival_function`."""
return jax.scipy.special.ndtr(-self._standardize(value))

def log_survival_function(self, value: Array) -> Array:
"""See `Distribution.log_survival_function`."""
return jax.scipy.special.log_ndtr(-self._standardize(value))

def _standardize(self, value: Array) -> Array:
return (value - self._loc) / self._scale

Expand Down
3 changes: 2 additions & 1 deletion distrax/_src/distributions/normal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def test_method_with_input(self, distr_params, value):
distr_params = (np.asarray(distr_params[0], dtype=np.float32),
np.asarray(distr_params[1], dtype=np.float32))
value = np.asarray(value, dtype=np.float32)
for method in ['log_prob', 'prob', 'cdf', 'log_cdf']:
for method in ['log_prob', 'prob', 'cdf', 'log_cdf', 'survival_function',
'log_survival_function']:
with self.subTest(method):
super()._test_attribute(
attribute_string=method,
Expand Down