Exemplo n.º 1
0
    def _create_lagrangian_multipliers(optimizer_dict, doo_ds):
        for v in optimizer_dict.state:
            print('LM:: {}'.format(v))
        lag_mul = []
        init_ops = []
        for v, der in zip(optimizer_dict.state, doo_ds):
            lm = slot_creator.create_slot(v.initialized_value(),
                                          utils.val_or_zero(None, v), 'alpha')
            init_op = lm.assign(utils.val_or_zero(der, v))
            lag_mul.append(lm)
            init_ops.append(init_op)
        #from IPython import embed;embed()
        #utils.val_or_zero(der, v) assign lag_mul <- utils.val_or_zero ==> op
        # merge -> return
        #

        #lag_mul = [slot_creator.create_slot(v.initialized_value(), utils.val_or_zero(None, v), 'alpha') for v, der
        #           in zip(optimizer_dict.state, doo_ds)]

        #lag_mul = [slot_creator.create_slot(tf.truncated_normal(v.shape, stddev=0.01), utils.val_or_zero(der, v), 'alpha') for v, der
        #           in zip(optimizer_dict.state, doo_ds)]

        [
            tf.add_to_collection(utils.GraphKeys.LAGRANGIAN_MULTIPLIERS, lm)
            for lm in lag_mul
        ]
        utils.remove_from_collection(utils.GraphKeys.GLOBAL_VARIABLES,
                                     *lag_mul)
        # this prevents the 'automatic' initialization with tf.global_variables_initializer.
        return lag_mul, init_ops
Exemplo n.º 2
0
 def _create_lagrangian_multipliers(optimizer_dict, doo_ds):
     lag_mul = [slot_creator.create_slot(v.initialized_value(), utils.val_or_zero(der, v), 'alpha') for v, der
                in zip(optimizer_dict.state, doo_ds)]
     [tf.add_to_collection(utils.GraphKeys.LAGRANGIAN_MULTIPLIERS, lm) for lm in lag_mul]
     utils.remove_from_collection(utils.GraphKeys.GLOBAL_VARIABLES, *lag_mul)
     # this prevents the 'automatic' initialization with tf.global_variables_initializer.
     return lag_mul
Exemplo n.º 3
0
 def _create_lagrangian_multipliers(optimizer_dict, doo_ds):
     lag_mul = [slot_creator.create_slot(v, utils.val_or_zero(der, v), 'alpha') for v, der
                in zip(optimizer_dict.state, doo_ds)]
     [tf.add_to_collection(utils.GraphKeys.LAGRANGIAN_MULTIPLIERS, lm) for lm in lag_mul]
     utils.remove_from_collection(utils.GraphKeys.GLOBAL_VARIABLES, *lag_mul)
     # this prevents the 'automatic' initialization with tf.global_variables_initializer.
     return lag_mul
Exemplo n.º 4
0
 def _create_zs(optimizer_dict, hyper, d_init_dynamics_d_hyper):
     if d_init_dynamics_d_hyper is None: d_init_dynamics_d_hyper = [None] * len(optimizer_dict)
     with tf.variable_scope('Z'):
         z = [slot_creator.create_slot(v, utils.val_or_zero(der, v), hyper.op.name) for v, der
              in zip(optimizer_dict.state, d_init_dynamics_d_hyper)]
         [tf.add_to_collection(utils.GraphKeys.ZS, lm) for lm in z]
         # in this case it is completely fine to keep zs into the global variable...
         return z
Exemplo n.º 5
0
 def _create_hypergradient_from_dodh(hyper, doo_dhypers):
     """
     Creates one hyper-gradient as a variable. doo_dhypers:  initialization, that is the derivative of
     the outer objective w.r.t this hyper
     """
     hgs = slot_creator.create_slot(hyper, utils.val_or_zero(doo_dhypers, hyper), 'hypergradient')
     utils.remove_from_collection(utils.GraphKeys.GLOBAL_VARIABLES, hgs)
     return hgs
Exemplo n.º 6
0
 def _create_z(optimizer_dict, hyper, d_init_dynamics_d_hyper):
     if d_init_dynamics_d_hyper is None: d_init_dynamics_d_hyper = [None]*len(optimizer_dict.state)
     with tf.variable_scope('Z'):
         z = [slot_creator.create_slot(v, utils.val_or_zero(der, v), hyper.op.name) for v, der
              in zip(optimizer_dict.state, d_init_dynamics_d_hyper)]
         [tf.add_to_collection(utils.GraphKeys.ZS, lm) for lm in z]
         # utils.remove_from_collection(utils.GraphKeys.GLOBAL_VARIABLES, *z)
         # in this case it is completely fine to keep zs into the global variable...
         return z
Exemplo n.º 7
0
    def _create_hypergradient(hyper, doo_dhypers):
        """
        Creates one hyper-gradient as a variable..

        :param hyper:  the relative hyperparameter
        :param doo_dhypers:  initialization, that is the derivative of the outer objective w.r.t this hyper
        :return:
        """
        hgs = slot_creator.create_slot(hyper, utils.val_or_zero(doo_dhypers, hyper), 'hypergradient')
        utils.remove_from_collection(utils.GraphKeys.GLOBAL_VARIABLES, hgs)
        return hgs