校正以下代码的语法错误 def encode_edge(self, mode, node_history, node_history_st, edge_type, neighbors, neighbors_edge_value, first_history_indices, batch_size): max_hl = self.hyperparams['maximum_history_length'] max_neighbors = 0 for neighbor_states in neighbors: max_neighbors = max(max_neighbors, len(neighbor_states)) edge_states_list = list() # list of [#of neighbors, max_ht, state_dim] for i, neighbor_states in enumerate(neighbors): # Get neighbors for timestep in batch if len(neighbor_states) == 0: # There are no neighbors for edge type # TODO necessary? neighbor_state_length = int( np.sum([len(entity_dims) for entity_dims in self.state[edge_type[1]].values()]) ) edge_states_list.append(torch.zeros((1, max_hl + 1, neighbor_state_length), device=self.device)) else: edge_states_list.append(torch.stack(neighbor_states, dim=0).to(self.device)) # if self.hyperparams['edge_state_combine_method'] == 'sum': # Used in Structural-RNN to combine edges as well. op_applied_edge_states_list = list() for neighbors_state in edge_states_list: op_applied_edge_states_list.append(torch.sum(neighbors_state, dim=0))#torch.sum combined_neighbors = torch.stack(op_applied_edge_states_list, dim=0) # 获取combined_neighbors的第一个维度,代表邻接边的总数 combined_neighbors_0 = combined_neighbors.shape[0] # 创建全零矩阵s_next,形状为[batch_size, max_neighbors, combined_neighbors_0] s_next = torch.zeros((batch_size, max_neighbors, combined_neighbors_0), device=self.device) # 为s_next矩阵中每一行赋值为对应的combined_neighbors # for b in range(batch_size): # s_next[b, :len(neighbors[b]), :] = combined_neighbors[first_history_indices[b]] for i in range(batch_size): s_next[0, i, :] = batch_size[:] for i in range(max_neighbors): s_next[1, i, :] = max_neighbors[i, :] for i in range(combined_neighbors.shape[0]): s_next[2, i, :] = combined_neighbors
时间: 2023-03-01 20:35:50 浏览: 254
encode_geohash.rar_geohash_geohash encode_matlab与geohash
代码中缺少冒号,不是合法的 Python 代码。正确的代码应该是这样的:
```
def encode_edge(self, mode, node_history, node_history_st, edge_type, neighbors, neighbors_edge_value, first_history_indices, batch_size):
max_hl = self.hyperparams['maximum_history_length']
max_neighbors = 0
for neighbor_states in neighbors:
max_neighbors = max(max_neighbors, len(neighbor_states))
edge_states_list = list()
```
阅读全文