def step3(L, Sigma, mu, mun): temp2 = np.dot(-J12.T, Sigma) Sigma_21 = solve_posdef_from_cholesky(L, temp2) ExnxT = Sigma_21 + np.outer(mun, mu) ExxT = Sigma + np.outer(mu, mu) return mu, ExxT, ExnxT
def natural_sample(J, h, num_samples=None, rng=rng): sample_shape = (num_samples,) + h.shape if num_samples else h.shape J = -2*J if J.ndim == 1: return h / J + rng.normal(size=sample_shape) / np.sqrt(J) else: L = np.linalg.cholesky(J) noise = solve_triangular(L, rng.normal(size=sample_shape).T, trans='T') return solve_posdef_from_cholesky(L, h.T).T + noise.T
def natural_rts_backward_step(next_smooth, next_pred, filtered, pair_param): # p = "predicted", f = "filtered", s = "smoothed", n = "next" (Jns, hns, mun), (Jnp, hnp), (Jf, hf) = next_smooth, next_pred, filtered J11, J12, J22, _ = pair_param # convert from natural parameter to the usual J definitions Jns, Jnp, Jf, J11, J12, J22 = -2*Jns, -2*Jnp, -2*Jf, -2*J11, -J12, -2*J22 J11, J12, J22 = Jf + J11, J12, Jns - Jnp + J22 L = np.linalg.cholesky(J22) temp = solve_triangular(L, J12.T) Js = J11 - np.dot(temp.T, temp) hs = hf - np.dot(temp.T, solve_triangular(L, hns - hnp)) mu, sigma = info_to_mean((Js, hs)) ExnxT = -solve_posdef_from_cholesky(L, np.dot(J12.T, sigma)) + np.outer(mun, mu) ExxT = sigma + np.outer(mu, mu) return -1./2*Js, hs, (mu, ExxT, ExnxT)
def natural_sample(J, h, eps): L = np.linalg.cholesky(J) mu = solve_posdef_from_cholesky(L, h) noise = solve_triangular(L, eps, 'T') return mu + noise