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

Update call to jnp.clip #136

Merged
merged 1 commit into from
Aug 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _pred_c0_kern(params, t_obs, t_peak):
c0_ytp, c0_ylo, clip_c0, clip_c1 = params
pred_c0 = _sig_slope(t_obs, XTP, c0_ytp, GLOBAL_X0, GLOBAL_K, c0_ylo, 0.0)
clip = clip_c0 + clip_c1 * t_peak
pred_c0 = jnp.clip(pred_c0, a_min=clip)
pred_c0 = jnp.clip(pred_c0, min=clip)
return pred_c0


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _pred_c1_kern(params, t_obs, t_peak):
pred_c1 = _sig_slope(t_obs, XTP, c1_ytp, GLOBAL_X0, GLOBAL_K, c1_ylo, 0.0)

clip = _sigmoid(t_peak, c1_clip_x0, CLIP_TP_K, c1_clip_ylo, c1_clip_yhi)
pred_c1 = jnp.clip(pred_c1, a_min=clip)
pred_c1 = jnp.clip(pred_c1, min=clip)
return pred_c1


Expand Down
18 changes: 18 additions & 0 deletions diffmah/diffmahpop_kernels/logm0_kernels/tests/test_logm0_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

import numpy as np
from jax import random as jran

from .. import logm0_pop as m0pop

Expand Down Expand Up @@ -66,3 +67,20 @@ def test_default_params_are_in_bounds():
val = getattr(m0pop.DEFAULT_LOGM0POP_PARAMS, key)
bound = getattr(m0pop.LGM0POP_BOUNDS, key)
assert bound[0] < val < bound[1]


def test_pred_logm0_kern():
ran_key = jran.key(0)
n_tests = 1_000
for __ in range(n_tests):
lgm_key, t_obs_key, t_peak_key, ran_key = jran.split(ran_key, 4)
lgm_obs = jran.uniform(lgm_key, minval=5, maxval=16, shape=())
t_obs = jran.uniform(t_obs_key, minval=1, maxval=20, shape=())
t_peak = jran.uniform(t_peak_key, minval=1.5, maxval=20, shape=())
lgm0 = m0pop._pred_logm0_kern(
m0pop.DEFAULT_LOGM0POP_PARAMS, lgm_obs, t_obs, t_peak
)
assert lgm0.shape == ()
assert np.isfinite(lgm0)
assert lgm0 > 0
assert lgm0 < 20
Loading