Ejemplo n.º 1
0
 def __init__(self, name="MLPGraphIndependent"):
   super(MLPGraphIndependent, self).__init__(name=name)
   with self._enter_variable_scope():
     self._network = modules.GraphIndependent(
         edge_model_fn=make_mlp_model,
         node_model_fn=make_mlp_model,
         global_model_fn=make_mlp_model)
Ejemplo n.º 2
0
 def __init__(self,
              edge_output_size=None,
              node_output_size=None,
              global_output_size=None,
              name="EncodeProcessDecode"):
   super(EncodeProcessDecode, self).__init__(name=name)
   self._encoder = MLPGraphIndependent()
   self._core = MLPGraphNetwork()
   self._decoder = MLPGraphIndependent()
   # Transforms the outputs into the appropriate shapes.
   if edge_output_size is None:
     edge_fn = None
   else:
     edge_fn = lambda: SigmoidEdgeProcessingModule(edge_output_size)
   if node_output_size is None:
     node_fn = None
   else:
     node_fn = lambda: snt.Linear(node_output_size, name="node_output")
   if global_output_size is None:
     global_fn = None
   else:
     global_fn = lambda: snt.Linear(global_output_size, name="global_output")
   with self._enter_variable_scope():
     self._output_transform = modules.GraphIndependent(edge_fn, node_fn,
                                                       global_fn)
Ejemplo n.º 3
0
    def __init__(self,
                 dimension,
                 edge_output_size=None,
                 node_output_size=None,
                 global_output_size=None,
                 name="GraphProcess"):
        super(GraphProcess, self).__init__(name=name)
        self._edge_encoder = make_rnn_model()
        self._proposition_encoder = make_rnn_model()
        self._edge_decoder = make_rnn_model()
        self._core = MLPGraphNetwork()
        self._decoder = MLPGraphIndependent()
        self._edge_size = edge_output_size
        self._dimension = dimension

        # Transforms the outputs into the appropriate shapes.
        if edge_output_size is None:
            edge_fn = None
        else:
            atom_state_edge_fn = lambda: SigmoidEdgeProcessingModule(
                edge_output_size)
        if node_output_size is None:
            node_fn = None
        else:
            node_fn = lambda: snt.Linear(node_output_size, name="node_output")
        if global_output_size is None:
            global_fn = None
        else:
            global_fn = lambda: snt.Linear(global_output_size,
                                           name="global_output")
        with self._enter_variable_scope():
            self._output_transform = modules.GraphIndependent(
                edge_model_fn=atom_state_edge_fn,
                node_model_fn=node_fn,
                global_model_fn=global_fn)
Ejemplo n.º 4
0
 def __init__(self, name="Encoder"):
   super(Encoder, self).__init__(name=name)
   with self._enter_variable_scope():
     self._network = modules.GraphIndependent(
         edge_model_fn=make_mlp_model)
Ejemplo n.º 5
0
  def __init__(self,
               dimension,
               atom_num,
               action_set_size,
               edge_output_size=None,
               node_output_size=None,
               global_output_size=None,
               name="GraphProcess"):
    super(GraphProcess, self).__init__(name=name)
    self._encoder = Encoder()
    self._core = MLPGraphNetwork()
    self._decoder = MLPGraphIndependent()
    self._edge_size = edge_output_size
    self._action_store_node = []
    self._action_store_edge = []
    self._dimension = dimension
    self._atom_num = atom_num
    self._action_model_fn = make_mlp_model()
    self._action_edges_model_fn = make_mlp_model()
    self._action_set_size = action_set_size
    self.p_node_store=[]
    self.p_node_model = make_mlp_model()
    self.output_action = []
    # Transforms the outputs into the appropriate shapes.
    if edge_output_size is None:
      edge_fn = None
    else:
      atom_state_edge_fn = lambda: SigmoidEdgeProcessingModule(edge_output_size)
    if node_output_size is None:
      node_fn = None
    else:
      node_fn = lambda: snt.Linear(node_output_size, name="node_output")
    if global_output_size is None:
      global_fn = None
    else:
      global_fn = lambda: snt.Linear(global_output_size, name="global_output")
    with self._enter_variable_scope():
      self._output_transform = modules.GraphIndependent(edge_model_fn=atom_state_edge_fn,
                                                          node_model_fn=node_fn, global_model_fn=global_fn)
    for index in range(0, self._action_set_size):
      edges = []
      nodes = (np.random.uniform(-6 / np.sqrt(self._dimension), 6 / np.sqrt(self._dimension), self._dimension))
      nodes = np.array(nodes, dtype='float32')
      nodes = tf.convert_to_tensor(nodes)
      nodes = tf.stack([nodes])
      updated_action_nodes = self._action_model_fn(nodes)
      self._action_store_node.append(updated_action_nodes)
      for vindex in range(1, self._atom_num + 1):
        temp = [np.random.uniform(-1, 1)]
        edges.append(temp)
      edges = tf.convert_to_tensor(edges)
      update_action_edges = [self._action_edges_model_fn(edges)]
      self._action_store_edge.append(update_action_edges)
    self._action_store_node = tf.concat(self._action_store_node, axis=0)
    self.output_action = self._action_store_node
    self._action_store_edge = tf.concat(self._action_store_edge, axis=0)

    nodes = (np.random.uniform(-6 / np.sqrt(self._dimension), 6 / np.sqrt(self._dimension), self._dimension*self._atom_num))
    nodes = np.reshape(nodes, (atom_num, dimension))
    nodes = np.array(nodes, dtype='float32')
    nodes = tf.convert_to_tensor(nodes)
    nodes = tf.stack(nodes)
    self.p_node_store = self.p_node_model(nodes)