text
stringlengths
1
93.6k
neg_his_nodes_list.append(neg_his_nodes)
neg_his_times_list.append(neg_his_times)
# neg_his_len.append(len(neg_his))
neg_his_nodes_list = np.array(neg_his_nodes_list).astype(int)
neg_his_times_list = np.array(neg_his_times_list)
neg_his_idx_list = []
for i in range(self.neg_size):
his_idx_list = []
for j in range(self.hist_len):
neg_node_his = self.node2hist[neg_his_nodes_list[i][j]]
if neg_node_his ==[]:
his_idx = 0
elif np.array([list(i) for i in neg_node_his])[:, 1][0] > e_time:
his_idx = 0
else:
his_idx = np.argwhere(np.array([list(i) for i in neg_node_his])[:, 1] <= neg_his_times_list[i][j])[-1].item()
his_idx_list.append(his_idx+1)
neg_his_idx_list.append(his_idx_list)
neg_his_idx_list = np.array(neg_his_idx_list)
neg_his_his_nodes_list = []
neg_his_his_times_list = []
for i in range(self.neg_size):
neg_h_h_nodes_list = []
neg_h_h_times_list = []
for j in range(self.hist_len):
if len(self.node2hist[neg_his_nodes_list[i][j]][0:neg_his_idx_list[i][j]]) == 0:
neg_his_his_nodes = np.array(neg_his_nodes_list[i][j]).repeat(self.hist_len)
neg_his_his_times = np.array(e_time).repeat(self.hist_len)
else:
if neg_his_idx_list[i][j] < self.hist_len:
neg_his_his_idx = np.random.choice(len(self.node2hist[neg_his_nodes_list[i][j]][0:neg_his_idx_list[i][j]]), self.hist_len, replace=True)
else:
neg_his_his_idx = np.random.choice(len(self.node2hist[neg_his_nodes_list[i][j]][0:neg_his_idx_list[i][j]]), self.hist_len, replace=False)
neg_his_his = [(self.node2hist[neg_his_nodes_list[i][j]][0:neg_his_idx_list[i][j]])[a] for a in neg_his_his_idx]
neg_his_his_nodes = [h[0] for h in neg_his_his]
neg_his_his_times = [h[1] for h in neg_his_his]
neg_h_h_nodes_list.append(neg_his_his_nodes)
neg_h_h_times_list.append(neg_his_his_times)
neg_h_h_nodes_list = np.array(neg_h_h_nodes_list)
neg_h_h_times_list = np.array(neg_h_h_times_list)
neg_his_his_nodes_list.append(neg_h_h_nodes_list)
neg_his_his_times_list.append(neg_h_h_times_list)
neg_his_his_nodes_list = np.array(neg_his_his_nodes_list).astype(int)
neg_his_his_times_list = np.array(neg_his_his_times_list)
s_self_feat = self.node_features[s_node]
s_one_hop_feat = self.node_features[s_his_nodes]
s_two_hop_feat = []
for i in range(self.hist_len):
s_two_feat = self.node_features[s_his_his_nodes_list[i]]
s_two_hop_feat.append(s_two_feat)
s_two_hop_feat = np.array(s_two_hop_feat)
t_self_feat = self.node_features[t_node]
t_one_hop_feat = self.node_features[t_his_nodes]
t_two_hop_feat = []
for i in range(self.hist_len):
t_two_feat = self.node_features[t_his_his_nodes_list[i]]
t_two_hop_feat.append(t_two_feat)
t_two_hop_feat = np.array(t_two_hop_feat)
neg_self_feat = self.node_features[neg_s_nodes]
neg_one_hop_feat = []
for i in range(self.neg_size):
neg_one_feat = self.node_features[neg_his_nodes_list[i]]
neg_one_hop_feat.append(neg_one_feat)
neg_one_hop_feat = np.array(neg_one_hop_feat)
neg_two_hop_feat = []
for i in range(self.neg_size):
neg_two_h_feat = []
for j in range(self.hist_len):
neg_t_h_f = self.node_features[neg_his_his_nodes_list[i][j]]
neg_two_h_feat.append(neg_t_h_f)
neg_two_h_feat = np.array(neg_two_h_feat)
neg_two_hop_feat.append(neg_two_h_feat)
neg_two_hop_feat = np.array(neg_two_hop_feat)
s_edge_rate = len(self.node_time_nodes[s_node][e_time])
sample = {
's_node': s_node, # e.g., 5424
't_node': t_node, # e.g., 5427
'neg_s_nodes':neg_s_nodes,
'event_time': e_time,
's_history_times': s_his_times, # e.g., [0.88462, 0.88462, 0.92308, 0.92308, 0.92308]
't_history_times': t_his_times,
's_his_his_times_list': s_his_his_times_list,
't_his_his_nodes_list': t_his_his_nodes_list,
't_his_his_times_list': t_his_his_times_list,
's_self_feat': s_self_feat,
's_one_hop_feat': s_one_hop_feat,