def compute_forward_posterior(self, az, bz, ax, bx): # estimate x from x = sgn(z) x_pos = +bz / np.sqrt(az) x_neg = -bz / np.sqrt(az) delta = 2 * bx + phi_0(x_pos) - phi_0(x_neg) rx = np.tanh(delta / 2) v = 1 - rx**2 vx = np.mean(v) return rx, vx
def compute_forward_posterior(self, az, bz, ax, bx): # estimate x from x = relu(z) a = ax + az x_pos = (bx + bz) / np.sqrt(a) x_neg = - bz / np.sqrt(az) delta = phi_0(x_pos) - phi_0(x_neg) + 0.5 * np.log(az / a) sigma_pos = sigmoid(+delta) sigma_neg = sigmoid(-delta) r_pos = phi_1(x_pos) / np.sqrt(a) v_pos = phi_2(x_pos) / a # NB: r_neg = 0 and v_neg = 0 rx = sigma_pos * r_pos Dx = r_pos**2 v = sigma_pos * sigma_neg * Dx + sigma_pos * v_pos vx = np.mean(v) return rx, vx
def compute_backward_posterior(self, az, bz, ax, bx): # estimate z from x = sgn(z) x_pos = +bz / np.sqrt(az) x_neg = -bz / np.sqrt(az) delta = 2 * bx + phi_0(x_pos) - phi_0(x_neg) sigma_pos = sigmoid(+delta) sigma_neg = sigmoid(-delta) r_pos = +phi_1(x_pos) / np.sqrt(az) # NB: + phi'(x_pos) r_neg = -phi_1(x_neg) / np.sqrt(az) # NB: + phi'(x_pos) v_pos = phi_2(x_pos) / az v_neg = phi_2(x_neg) / az rz = sigma_pos * r_pos + sigma_neg * r_neg Dz = (r_pos - r_neg)**2 v = sigma_pos * sigma_neg * Dz + sigma_pos * v_pos + sigma_neg * v_neg vz = np.mean(v) return rz, vz
def compute_backward_posterior(self, az, bz, ax, bx): # estimate z from x = relu(z) a = ax + az x_pos = (bx + bz) / np.sqrt(a) x_neg = - bz / np.sqrt(az) delta = phi_0(x_pos) - phi_0(x_neg) + 0.5 * np.log(az / a) sigma_pos = sigmoid(+delta) sigma_neg = sigmoid(-delta) r_pos = + phi_1(x_pos) / np.sqrt(a) # NB: + phi'(x_pos) r_neg = - phi_1(x_neg) / np.sqrt(az) # NB: - phi'(x_pos) v_pos = phi_2(x_pos) / a v_neg = phi_2(x_neg) / az rz = sigma_pos * r_pos + sigma_neg * r_neg Dz = (r_pos - r_neg)**2 v = sigma_pos * sigma_neg * Dz + sigma_pos * v_pos + sigma_neg * v_neg vz = np.mean(v) return rz, vz
def compute_forward_posterior(self, az, bz, ax, bx): # estimate x from x = abs(z) a = ax + az x_pos = (bx + bz) / np.sqrt(a) x_neg = (bx - bz) / np.sqrt(a) delta = phi_0(x_pos) - phi_0(x_neg) sigma_pos = sigmoid(+delta) sigma_neg = sigmoid(-delta) r_pos = phi_1(x_pos) / np.sqrt(a) r_neg = phi_1(x_neg) / np.sqrt(a) v_pos = phi_2(x_pos) / a v_neg = phi_2(x_neg) / a rx = sigma_pos * r_pos + sigma_neg * r_neg Dx = (r_pos - r_neg)**2 v = sigma_pos * sigma_neg * Dx + sigma_pos * v_pos + sigma_neg * v_neg vx = np.mean(v) return rx, vx
def compute_backward_posterior(self, az, bz, ax, bx): # estimate z from x = leaky_relu(z) a_pos = az + ax a_neg = az + (self.slope**2) * ax b_pos = bz + bx b_neg = -bz - self.slope * bx x_pos = b_pos / np.sqrt(a_pos) x_neg = b_neg / np.sqrt(a_neg) delta = phi_0(x_pos) - phi_0(x_neg) + 0.5 * np.log(a_neg / a_pos) sigma_pos = sigmoid(+delta) sigma_neg = sigmoid(-delta) r_pos = phi_1(x_pos) / np.sqrt(a_pos) r_neg = -phi_1(x_neg) / np.sqrt(a_neg) v_pos = phi_2(x_pos) / a_pos v_neg = phi_2(x_neg) / a_neg rz = sigma_pos * r_pos + sigma_neg * r_neg Dz = (r_pos - r_neg)**2 v = sigma_pos * sigma_neg * Dz + sigma_pos * v_pos + sigma_neg * v_neg vz = np.mean(v) return rz, vz