Пример #1
0
 def __init__(self, vector_dim, output_shape, name, hidden_units, *, visual_net):
     super().__init__(visual_net, name=name)
     self.share = mlp(hidden_units['share'], out_layer=False)
     self.mu = mlp(hidden_units['mu'], output_shape=output_shape, out_activation=None)
     self.log_std = mlp(hidden_units['log_std'], output_shape=output_shape, out_activation='tanh')
     self.init_or_run(tf.keras.Input(shape=vector_dim + self.visual_net.hdim))
     self.update_vars()
Пример #2
0
 def __init__(self, vector_dim, action_dim, name, hidden_units, *, visual_net):
     assert len(hidden_units) > 1, "if you want to use this architecture of critic network, the number of layers must greater than 1"
     super().__init__(visual_net, name=name)
     self.feature_net = mlp(hidden_units[0:1])
     self.net = mlp(hidden_units[1:], output_shape=1, out_activation=None)
     self.init_or_run(tf.keras.Input(shape=vector_dim + self.visual_net.hdim), tf.keras.Input(shape=action_dim))
     self.update_vars()
Пример #3
0
 def __init__(self, vector_dim, action_dim, quantiles_idx, name, hidden_units, *, visual_net):
     super().__init__(visual_net, name=name)
     self.action_dim = action_dim
     self.q_net_head = mlp(hidden_units['q_net'], out_layer=False)   # [B, vector_dim]
     self.quantile_net = mlp(hidden_units['quantile'], out_layer=False)  # [N*B, quantiles_idx]
     self.q_net_tile = mlp(hidden_units['tile'], output_shape=action_dim, out_activation=None)   # [N*B, hidden_units['quantile'][-1]]
     self.init_or_run(tf.keras.Input(shape=vector_dim + self.visual_net.hdim), tf.keras.Input(shape=quantiles_idx))
     self.update_vars()
Пример #4
0
 def __init__(self, vector_dim, action_dim, atoms, name, hidden_units, *, visual_net):
     super().__init__(visual_net, name=name)
     self.action_dim = action_dim
     self.atoms = atoms
     self.share = mlp(hidden_units['share'], layer=Noisy, out_layer=False)
     self.v = mlp(hidden_units['v'], layer=Noisy, output_shape=atoms, out_activation=None)
     self.adv = mlp(hidden_units['adv'], layer=Noisy, output_shape=action_dim * atoms, out_activation=None)
     self.init_or_run(tf.keras.Input(shape=vector_dim + self.visual_net.hdim))
     self.update_vars()
Пример #5
0
 def __init__(self, vector_dim, action_dim, nums, name, hidden_units, *, visual_net):
     super().__init__(visual_net, name=name)
     self.action_dim = action_dim
     self.nums = nums
     self.net = mlp(hidden_units, output_shape=nums * action_dim, out_activation=None)
     self.init_or_run(tf.keras.Input(shape=vector_dim + self.visual_net.hdim))
     self.update_vars()
Пример #6
0
 def __init__(self, vector_dim, output_shape, name, hidden_units, *, visual_net):
     super().__init__(visual_net, name=name)
     self.masking = tf.keras.layers.Masking(mask_value=0.)
     self.lstm_net = tf.keras.layers.LSTM(hidden_units['lstm'], return_state=True, return_sequences=True)
     self.net = mlp(hidden_units['dense'], output_shape=output_shape, out_activation=None)
     self.init_or_run(tf.keras.Input(shape=(None, vector_dim + self.visual_net.hdim)))
     self.update_vars()
Пример #7
0
 def __init__(self, vector_dim, output_shape, name, hidden_units, *,
              visual_net):
     super().__init__(visual_net, name=name)
     self.logits = mlp(hidden_units,
                       output_shape=output_shape,
                       out_activation=None)
     self.init_or_run(
         tf.keras.Input(shape=vector_dim + self.visual_net.hdim))
     self.update_vars()
Пример #8
0
 def __init__(self, vector_dim, output_shape, hidden_units, is_continuous):
     super().__init__()
     self.is_continuous = is_continuous
     out_activation = 'tanh' if self.is_continuous else None
     self.net = mlp(hidden_units, act_fn='tanh', output_shape=output_shape, out_activation=out_activation, out_layer=True)
     self.weights_2dim = [[i, j] for i, j in zip([vector_dim]+hidden_units, hidden_units+[output_shape])]
     self.weights_nums = np.asarray(self.weights_2dim).prod(axis=-1).tolist()
     self.weights_total_nums = np.asarray(self.weights_2dim).prod(axis=-1).sum() + np.asarray(hidden_units).sum() + output_shape
     self(tf.keras.Input(shape=vector_dim))  # 初始化网络权重
Пример #9
0
    def __init__(self, vector_dim, output_shape, name, hidden_units,
                 visual_net, **kwargs):
        super(actor_continuous_gcn, self).__init__(name=name, **kwargs)
        self.visual_net = visual_net
        self.tv = []
        self.tv += self.visual_net.trainable_variables

        self.gcn_layers1 = GraphConvolution(input_dim=64,
                                            output_dim=64,
                                            num_features_nonzero=0,
                                            activation=tf.nn.relu,
                                            dropout=0.5,
                                            is_sparse_inputs=False,
                                            bias=False,
                                            featureless=False)
        # self.gcn_layers2 = GraphConvolution(input_dim=64,
        #                                     output_dim=64,
        #                                     num_features_nonzero=0,
        #                                     activation=tf.nn.relu,
        #                                     dropout=0.5,
        #                                     is_sparse_inputs=False,
        #                                     bias=False,
        #                                     featureless=False)
        #
        # self.attention_layer1 = MultiHeadAttention(d_model=64, num_heads=8)
        # self.attention_layer2 = MultiHeadAttention(d_model=64, num_heads=8)
        self.layer_x_embeding = Dense(64, activation='tanh')

        # self.share = mlp(hidden_units['share'], out_layer=False)
        self.layer_1 = Dense(64, activation='tanh')
        self.mu = mlp(hidden_units['mu'],
                      output_shape=output_shape,
                      out_activation=None)
        self.log_std = mlp(hidden_units['log_std'],
                           output_shape=output_shape,
                           out_activation='tanh')

        self.init_or_run(tf.keras.Input(shape=(vector_dim[0], vector_dim[0])),
                         tf.keras.Input(shape=vector_dim))
        self.update_vars()
Пример #10
0
 def __init__(self, adj_shape, x_shape, action_dim, name, hidden_units, *,
              visual_net):
     super().__init__(visual_net, name=name)
     self.gcn_layers = []
     self.gcn_layers.append(
         GraphConvolution(input_dim=x_shape[1],
                          output_dim=16,
                          num_features_nonzero=0,
                          activation=tf.nn.relu,
                          dropout=0.5,
                          is_sparse_inputs=False))
     self.attention_layer = MultiHeadAttention(d_model=16, num_heads=8)
     self.net = mlp(hidden_units, output_shape=1, out_activation=None)
     self.init_or_run(tf.keras.Input(shape=(adj_shape[0], adj_shape[1])),
                      tf.keras.Input(shape=(x_shape[0], x_shape[1])),
                      tf.keras.Input(shape=(1, adj_shape[0])),
                      tf.keras.Input(shape=action_dim))
     self.update_vars()