def sample_mjp_path(t, vt, thi, lam, y_nil, f_loglik, ome): n_cond = ome.choice(list(range(len(t) - 1)), 1) t_cond = np.sort(ome.choice(t, n_cond, replace=False)) y_nil_part = mjp_skel.partition_skeleton(y_nil, t_cond) y_prime_part = mjp_skel.mutate_partition(mjp_skel.partition_skeleton(y_nil, t_cond), lam, ome) break_i = [0] + list(np.where(np.isin(t, t_cond))[0] + 1) + [len(t) - 1] y_acc_part = [sample_mjp_section(t[i:j+1] - t[i], vt[i:j+1], thi, lam, y_nil_part[i], y_prime_part[i], f_loglik, ome) for i, j in zip(break_i, break_i[1:])] return mjp_skel.paste_partition(y_acc_part)
def eval_log_lik(t, vt, y, bet, sig): if np.any(bet <= 0) or np.any(sig <= 0): return -np.inf return sum([ eval_log_trans(dt, v0, v1, y_, bet, sig) for dt, v0, v1, y_ in zip( np.diff(t), vt, vt[1:], skeleton.partition_skeleton(y, t[1:-1])) ])
def propose(self, lam: np.ndarray, t: np.ndarray, ome: np.random.Generator) -> (mjp_skel.Skeleton, np.ndarray): p_cond = 1 / (1 + np.exp(self.log_prop_scale[-1])) t_cond = t[1:-1][ome.uniform(size=len(t) - 2) < p_cond] prop = mjp_skel.paste_partition( mjp_skel.mutate_partition( mjp_skel.partition_skeleton(self.state, t_cond), lam, ome)) return (prop, t_cond)
def sample_aug( thi: np.ndarray, y: mjp_skel.Skeleton, t: np.ndarray, vt: np.ndarray, ome: np.random.Generator) -> (sde_seed.Partition, types.Anchorage): xt = reduce(vt) y_part = mjp_skel.partition_skeleton(y, t[1:-1]) xtt = np.hstack([ dereduce(sample_anchors(thi, t_, yt_, fin_t_, x0, xt, ome)) for (t_, yt_, fin_t_), x0, xt in zip(y_part, xt, xt[1:]) ] + [vt[-1]]) tt = np.append(np.hstack([t0 + y_.t for t0, y_ in zip(t, y_part)]), t[-1]) ytt = np.append(np.hstack([y_.xt for y_ in y_part]), y.xt[-1]) vtt = dereduce(xtt) z = [ sde_seed.sample_raw_seed(bounds_x, normop, inv_normop, ome) for (normop, inv_normop) in gen_normops(thi, tt, ytt, vtt) ] return z, types.Anchorage(tt, ytt, vtt)
def sample_path(t, init_v, y, bet, sig, ome): vt = [init_v] for y_ in skeleton.partition_skeleton(y, t[:-1]): vt.append(sample_trans(vt[-1], y_, bet, sig, ome)) return np.array(vt[1:])