assignment2_coding/starter_code/q2_linear.py
def add_update_target_op(self, q_scope, target_q_scope):
        """
        update_target_op will be called periodically
        to copy Q network weights to target Q network

        Remember that in DQN, we maintain two identical Q networks with
        2 different sets of weights. In tensorflow, we distinguish them
        with two different scopes. If you're not familiar with the scope mechanism
        in tensorflow, read the docs
        https://www.tensorflow.org/api_docs/python/tf/compat/v1/variable_scope

        Periodically, we need to update all the weights of the Q network
        and assign them with the values from the regular network.
        Args:
            q_scope: (string) name of the scope of variables for q
            target_q_scope: (string) name of the scope of variables
                        for the target network
        """
        ##############################################################
        """
        TODO:
            Add an operator self.update_target_op that for each variable in
            tf.GraphKeys.GLOBAL_VARIABLES that is in q_scope, assigns its
            value to the corresponding variable in target_q_scope

        HINT:
            You may find the following functions useful:
                - tf.get_collection
                - tf.assign
                - tf.group (the * operator can be used to unpack a list)

        (be sure that you set self.update_target_op)
        """
        ##############################################################
        ################### YOUR CODE HERE - 5-10 lines #############

        q_vars = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope=q_scope)
        tq_vars = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope=target_q_scope)
        ops = [tf.assign(tq_vars[i], q_vars[i]) for i in range(len(q_vars))]
        self.update_target_op = tf.group(*ops)

        ##############################################################
        ######################## END YOUR CODE #######################


        update_target_op will be called periodically
        to copy Q network weights to target Q network

        Remember that in DQN, we maintain two identical Q networks with
        2 different sets of weights. In tensorflow, we distinguish them
        with two different scopes. If you're not familiar with the scope mechanism
        in tensorflow, read the docs
        https://www.tensorflow.org/api_docs/python/tf/compat/v1/variable_scope

        Periodically, we need to update all the weights of the Q network
        and assign them with the values from the regular network.
        Args:
            q_scope: (string) name of the scope of variables for q
            target_q_scope: (string) name of the scope of variables
                        for the target network
        
update_target_op will be called periodically
to copy Q network weights to target Q network

Remember that in DQN, we maintain two identical Q networks with
2 different sets of weights. In tensorflow, we distinguish them
with two different scopes.

Periodically, we need to update all the weights of the Q network
and assign them with the values from the regular network.
update_target_op will be called periodically to copy Q network weights to target Q network Remember that in DQN we maintain two identical Q networks with 2 different sets of weights . In tensorflow we distinguish them with two different scopes . Periodically we need to update all the weights of the Q network and assign them with the values from the regular network .
def add_update_target_op(self, q_scope, target_q_scope):
        q_vars = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope=q_scope)
        tq_vars = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope=target_q_scope)
        ops = [tf.assign(tq_vars[i], q_vars[i]) for i in range(len(q_vars))]
        self.update_target_op = tf.group(*ops)
def add_update_target_op ( self , q_scope , target_q_scope ) : """
        TODO:
            Add an operator self.update_target_op that for each variable in
            tf.GraphKeys.GLOBAL_VARIABLES that is in q_scope, assigns its
            value to the corresponding variable in target_q_scope

        HINT:
            You may find the following functions useful:
                - tf.get_collection
                - tf.assign
                - tf.group (the * operator can be used to unpack a list)

        (be sure that you set self.update_target_op)
        """ q_vars = tf . get_collection ( tf . GraphKeys . GLOBAL_VARIABLES , scope = q_scope ) tq_vars = tf . get_collection ( tf . GraphKeys . GLOBAL_VARIABLES , scope = target_q_scope ) ops = [ tf . assign ( tq_vars [ i ] , q_vars [ i ] ) for i in range ( len ( q_vars ) ) ] self . update_target_op = tf . group ( * ops )
update_target_op will be called periodically
to copy Q network weights to target Q network
update_target_op will be called periodically to copy Q network weights to target Q network
"""
        update_target_op will be called periodically
        to copy Q network weights to target Q network

        Remember that in DQN, we maintain two identical Q networks with
        2 different sets of weights. In tensorflow, we distinguish them
        with two different scopes. If you're not familiar with the scope mechanism
        in tensorflow, read the docs
        https://www.tensorflow.org/api_docs/python/tf/compat/v1/variable_scope

        Periodically, we need to update all the weights of the Q network
        and assign them with the values from the regular network.
        Args:
            q_scope: (string) name of the scope of variables for q
            target_q_scope: (string) name of the scope of variables
                        for the target network
        """ ##############################################################
 """
        TODO:
            Add an operator self.update_target_op that for each variable in
            tf.GraphKeys.GLOBAL_VARIABLES that is in q_scope, assigns its
            value to the corresponding variable in target_q_scope

        HINT:
            You may find the following functions useful:
                - tf.get_collection
                - tf.assign
                - tf.group (the * operator can be used to unpack a list)

        (be sure that you set self.update_target_op)
        """ ##############################################################
 ################### YOUR CODE HERE - 5-10 lines #############
 ##############################################################
 ######################## END YOUR CODE #######################

self
q_scope
(string) name of the scope of variables for q
( string ) name of the scope of variables for q
target_q_scope
(string) name of the scope of variables
for the target network
( string ) name of the scope of variables for the target network