models/moa_model.py
def marginalize_predictions_over_own_actions(self, prev_action_logits, counterfactual_logits):
        """
        Calculates marginal policies for all other agents.
        :param prev_action_logits: The agent's own policy logits at time t-1 .
        :param counterfactual_logits: The counterfactual action predictions made at time t-1 for
        other agents' actions at t.
        :return: The marginal policies for all other agents.
        """
        # Probability of each action in original trajectory
        logits = tf.nn.softmax(prev_action_logits)

        # Normalize to reduce numerical inaccuracies
        logits = logits / tf.reduce_sum(logits, axis=-1, keepdims=True)

        # Indexing is currently [B, Agent actions, num_other_agents * other_agent_logits]
        # Change to [B, Agent actions, num other agents, other agent logits]
        counterfactual_logits = tf.reshape(
            counterfactual_logits, [-1, self.num_outputs, self.num_other_agents, self.num_outputs],
        )

        counterfactual_logits = tf.nn.softmax(counterfactual_logits)
        # Change shape to broadcast probability of each action over counterfactual actions
        logits = tf.reshape(logits, [-1, self.num_outputs, 1, 1])
        normalized_counterfactual_logits = logits * counterfactual_logits
        # Remove counterfactual action dimension
        marginal_probs = tf.reduce_sum(normalized_counterfactual_logits, axis=-3)

        # Normalize to reduce numerical inaccuracies
        marginal_probs = marginal_probs / tf.reduce_sum(marginal_probs, axis=-1, keepdims=True)

        return marginal_probs

        Calculates marginal policies for all other agents.
        :param prev_action_logits: The agent's own policy logits at time t-1 .
        :param counterfactual_logits: The counterfactual action predictions made at time t-1 for
        other agents' actions at t.
        :return: The marginal policies for all other agents.
        
Calculates marginal policies for all other agents.
Calculates marginal policies for all other agents .
def marginalize_predictions_over_own_actions(self, prev_action_logits, counterfactual_logits):
        logits = tf.nn.softmax(prev_action_logits)
        logits = logits / tf.reduce_sum(logits, axis=-1, keepdims=True)
        counterfactual_logits = tf.reshape(
            counterfactual_logits, [-1, self.num_outputs, self.num_other_agents, self.num_outputs],
        )
        counterfactual_logits = tf.nn.softmax(counterfactual_logits)
        logits = tf.reshape(logits, [-1, self.num_outputs, 1, 1])
        normalized_counterfactual_logits = logits * counterfactual_logits
        marginal_probs = tf.reduce_sum(normalized_counterfactual_logits, axis=-3)
        marginal_probs = marginal_probs / tf.reduce_sum(marginal_probs, axis=-1, keepdims=True)
        return marginal_probs
def marginalize_predictions_over_own_actions ( self , prev_action_logits , counterfactual_logits ) : logits = tf . nn . softmax ( prev_action_logits ) logits = logits / tf . reduce_sum ( logits , axis = - 1 , keepdims = True ) counterfactual_logits = tf . reshape ( counterfactual_logits , [ - 1 , self . num_outputs , self . num_other_agents , self . num_outputs ] , ) counterfactual_logits = tf . nn . softmax ( counterfactual_logits ) logits = tf . reshape ( logits , [ - 1 , self . num_outputs , 1 , 1 ] ) normalized_counterfactual_logits = logits * counterfactual_logits marginal_probs = tf . reduce_sum ( normalized_counterfactual_logits , axis = - 3 ) marginal_probs = marginal_probs / tf . reduce_sum ( marginal_probs , axis = - 1 , keepdims = True ) return marginal_probs
Calculates marginal policies for all other agents.
Calculates marginal policies for all other agents .
"""
        Calculates marginal policies for all other agents.
        :param prev_action_logits: The agent's own policy logits at time t-1 .
        :param counterfactual_logits: The counterfactual action predictions made at time t-1 for
        other agents' actions at t.
        :return: The marginal policies for all other agents.
        """ # Probability of each action in original trajectory # Normalize to reduce numerical inaccuracies # Indexing is currently [B, Agent actions, num_other_agents * other_agent_logits] # Change to [B, Agent actions, num other agents, other agent logits] # Change shape to broadcast probability of each action over counterfactual actions # Remove counterfactual action dimension # Normalize to reduce numerical inaccuracies
The marginal policies for all other agents.
The marginal policies for all other agents .
self
prev_action_logits
The agent's own policy logits at time t-1 .
The agent ' s own policy logits at time t - 1 .
counterfactual_logits
The counterfactual action predictions made at time t-1 for
other agents' actions at t.
The counterfactual action predictions made at time t - 1 for other agents ' actions at t .