Invert the CDF defined by (t, w) at the points specified by u in [0, 1).
(u, t, w_logits)
| 162 | |
| 163 | |
| 164 | def invert_cdf_np(u, t, w_logits): |
| 165 | """Invert the CDF defined by (t, w) at the points specified by u in [0, 1).""" |
| 166 | # Compute the PDF and CDF for each weight vector. |
| 167 | w = np.exp(w_logits) / np.exp(w_logits).sum(axis=-1, keepdims=True) |
| 168 | cw = integrate_weights_np(w) |
| 169 | # Interpolate into the inverse CDF. |
| 170 | interp_fn = np.interp |
| 171 | t_new = interp_fn(u, cw, t) |
| 172 | return t_new |
| 173 | |
| 174 | |
| 175 | def sample(rand, |
no test coverage detected