def _get_exchanged_states(self, old_states, exchange_proposed,<EOL>exchange_proposed_n, sampled_replica_states,<EOL>sampled_replica_results):
with tf.compat.v1.name_scope('<STR_LIT>'):<EOL><INDENT>target_log_probs = []<EOL>for replica in range(self.num_replica):<EOL><INDENT>replica_log_prob = _get_field(sampled_replica_results[replica],<EOL>'<STR_LIT>')<EOL>inverse_temp = self.inverse_temperatures[replica]<EOL>target_log_probs.append(replica_log_prob / inverse_temp)<EOL><DEDENT>target_log_probs = tf.stack(target_log_probs, axis=<NUM_LIT:0>)<EOL>dtype = target_log_probs.dtype<EOL>num_state_parts = len(sampled_replica_states[<NUM_LIT:0>])<EOL>exchanged_states = [<EOL>tf.TensorArray(<EOL>dtype,<EOL>size=self.num_replica,<EOL>dynamic_size=False,<EOL>tensor_array_name='<STR_LIT>',<EOL>element_shape=sampled_replica_states[<NUM_LIT:0>][k].shape)<EOL>for k in range(num_state_parts)<EOL>]<EOL>sample_shape = tf.concat(<EOL>([self.num_replica // <NUM_LIT:2>], tf.shape(input=target_log_probs)[<NUM_LIT:1>:]),<EOL>axis=<NUM_LIT:0>)<EOL>log_uniforms = tf.math.log(<EOL>tf.random.uniform(<EOL>shape=sample_shape, dtype=dtype, seed=self._seed_stream()))<EOL>def _swap(is_exchange_accepted, x, y):<EOL><INDENT>"""<STR_LIT>"""<EOL>with tf.compat.v1.name_scope('<STR_LIT>'):<EOL><INDENT>new_x = mcmc_util.choose(is_exchange_accepted, y, x)<EOL>new_y = mcmc_util.choose(is_exchange_accepted, x, y)<EOL><DEDENT>return new_x, new_y<EOL><DEDENT>def cond(i, unused_exchanged_states):<EOL><INDENT>return i < exchange_proposed_n<EOL><DEDENT>def body(i, exchanged_states):<EOL><INDENT>"""<STR_LIT>"""<EOL>m, n = tf.unstack(exchange_proposed[i])<EOL>temp_diff = self.inverse_temperatures[m] - self.inverse_temperatures[n]<EOL>log_accept_ratio = mcmc_util.safe_sum(<EOL>[-temp_diff * target_log_probs[m], temp_diff * target_log_probs[n]])<EOL>is_exchange_accepted = log_uniforms[i] < log_accept_ratio<EOL>for k in range(num_state_parts):<EOL><INDENT>new_m, new_n = _swap(is_exchange_accepted, old_states[k].read(m),<EOL>old_states[k].read(n))<EOL>exchanged_states[k] = exchanged_states[k].write(m, new_m)<EOL>exchanged_states[k] = exchanged_states[k].write(n, new_n)<EOL><DEDENT>return i + <NUM_LIT:1>, exchanged_states<EOL><DEDENT>return tf.while_loop(<EOL>cond=cond, body=body, loop_vars=[tf.constant(<NUM_LIT:0>),<EOL>exchanged_states])[<NUM_LIT:1>]<EOL><DEDENT>
Get list of TensorArrays holding exchanged states, and zeros.