def aggregate(self, user_embeddings, entities, relations):
    'For each item, aggregate the entity representation and its neighborhood representation into a single vector.\n\n        Args:\n            user_embeddings(torch.FloatTensor): The embeddings of users, shape: [batch_size, embedding_size]\n            entities(list): entities is a list of i-iter (i = 0, 1, ..., n_iter) neighbors for the batch of items.\n                            dimensions of entities: {[batch_size, 1],\n                            [batch_size, n_neighbor],\n                            [batch_size, n_neighbor^2],\n                            ...,\n                            [batch_size, n_neighbor^n_iter]}\n            relations(list): relations is a list of i-iter (i = 0, 1, ..., n_iter) corresponding relations for entities.\n                             relations have the same shape as entities.\n\n        Returns:\n            item_embeddings(torch.FloatTensor): The embeddings of items, shape: [batch_size, embedding_size]\n\n        '
    entity_vectors = [self.entity_embedding(i) for i in entities]
    relation_vectors = [self.relation_embedding(i) for i in relations]
    for i in range(self.n_iter):
        entity_vectors_next_iter = []
        for hop in range((self.n_iter - i)):
            shape = (self.batch_size, (- 1), self.neighbor_sample_size, self.embedding_size)
            self_vectors = entity_vectors[hop]
            neighbor_vectors = torch.reshape(entity_vectors[(hop + 1)], shape)
            neighbor_relations = torch.reshape(relation_vectors[hop], shape)
            user_embeddings = torch.reshape(user_embeddings, (self.batch_size, 1, 1, self.embedding_size))
            user_relation_scores = torch.mean((user_embeddings * neighbor_relations), dim=(- 1))
            user_relation_scores_normalized = torch.unsqueeze(self.softmax(user_relation_scores), dim=(- 1))
            neighbors_agg = torch.mean((user_relation_scores_normalized * neighbor_vectors), dim=2)
            if (self.aggregator_class == 'sum'):
                output = torch.reshape((self_vectors + neighbors_agg), ((- 1), self.embedding_size))
            elif (self.aggregator_class == 'neighbor'):
                output = torch.reshape(neighbors_agg, ((- 1), self.embedding_size))
            elif (self.aggregator_class == 'concat'):
                output = torch.cat([self_vectors, neighbors_agg], dim=(- 1))
                output = torch.reshape(output, ((- 1), (self.embedding_size * 2)))
            else:
                raise Exception(('Unknown aggregator: ' + self.aggregator_class))
            output = self.linear_layers[i](output)
            output = torch.reshape(output, [self.batch_size, (- 1), self.embedding_size])
            if (i == (self.n_iter - 1)):
                vector = self.Tanh(output)
            else:
                vector = self.ReLU(output)
            entity_vectors_next_iter.append(vector)
        entity_vectors = entity_vectors_next_iter
    res = torch.reshape(entity_vectors[0], (self.batch_size, self.embedding_size))
    return res
For each item, aggregate the entity representation and its neighborhood representation into a single vector.

Args:
    user_embeddings(torch.FloatTensor): The embeddings of users, shape: [batch_size, embedding_size]
    entities(list): entities is a list of i-iter (i = 0, 1, ..., n_iter) neighbors for the batch of items.
                    dimensions of entities: {[batch_size, 1],
                    [batch_size, n_neighbor],
                    [batch_size, n_neighbor^2],
                    ...,
                    [batch_size, n_neighbor^n_iter]}
    relations(list): relations is a list of i-iter (i = 0, 1, ..., n_iter) corresponding relations for entities.
                     relations have the same shape as entities.

Returns:
    item_embeddings(torch.FloatTensor): The embeddings of items, shape: [batch_size, embedding_size]
def aggregate(self, user_embeddings, entities, relations):
    'For each item, aggregate the entity representation and its neighborhood representation into a single vector.\n\n        Args:\n            user_embeddings(torch.FloatTensor): The embeddings of users, shape: [batch_size, embedding_size]\n            entities(list): entities is a list of i-iter (i = 0, 1, ..., n_iter) neighbors for the batch of items.\n                            dimensions of entities: {[batch_size, 1],\n                            [batch_size, n_neighbor],\n                            [batch_size, n_neighbor^2],\n                            ...,\n                            [batch_size, n_neighbor^n_iter]}\n            relations(list): relations is a list of i-iter (i = 0, 1, ..., n_iter) corresponding relations for entities.\n                             relations have the same shape as entities.\n\n        Returns:\n            item_embeddings(torch.FloatTensor): The embeddings of items, shape: [batch_size, embedding_size]\n\n        '
    entity_vectors = [self.entity_embedding(i) for i in entities]
    relation_vectors = [self.relation_embedding(i) for i in relations]
    for i in range(self.n_iter):
        entity_vectors_next_iter = []
        for hop in range((self.n_iter - i)):
            shape = (self.batch_size, (- 1), self.neighbor_sample_size, self.embedding_size)
            self_vectors = entity_vectors[hop]
            neighbor_vectors = torch.reshape(entity_vectors[(hop + 1)], shape)
            neighbor_relations = torch.reshape(relation_vectors[hop], shape)
            user_embeddings = torch.reshape(user_embeddings, (self.batch_size, 1, 1, self.embedding_size))
            user_relation_scores = torch.mean((user_embeddings * neighbor_relations), dim=(- 1))
            user_relation_scores_normalized = torch.unsqueeze(self.softmax(user_relation_scores), dim=(- 1))
            neighbors_agg = torch.mean((user_relation_scores_normalized * neighbor_vectors), dim=2)
            if (self.aggregator_class == 'sum'):
                output = torch.reshape((self_vectors + neighbors_agg), ((- 1), self.embedding_size))
            elif (self.aggregator_class == 'neighbor'):
                output = torch.reshape(neighbors_agg, ((- 1), self.embedding_size))
            elif (self.aggregator_class == 'concat'):
                output = torch.cat([self_vectors, neighbors_agg], dim=(- 1))
                output = torch.reshape(output, ((- 1), (self.embedding_size * 2)))
            else:
                raise Exception(('Unknown aggregator: ' + self.aggregator_class))
            output = self.linear_layers[i](output)
            output = torch.reshape(output, [self.batch_size, (- 1), self.embedding_size])
            if (i == (self.n_iter - 1)):
                vector = self.Tanh(output)
            else:
                vector = self.ReLU(output)
            entity_vectors_next_iter.append(vector)
        entity_vectors = entity_vectors_next_iter
    res = torch.reshape(entity_vectors[0], (self.batch_size, self.embedding_size))
    return res