|
|
|
|
|
|
|
|
# while t in s: |
|
|
# while t in s: |
|
|
# t = np.random.randint(l, r) |
|
|
# t = np.random.randint(l, r) |
|
|
# return t |
|
|
# return t |
|
|
user = np.random.choice(1, usernum + 1) |
|
|
|
|
|
candid_item = user_train[user][np.random.randint(0, len(user_train[user]))] |
|
|
|
|
|
|
|
|
|
|
|
while candid_item in s: |
|
|
|
|
|
user = np.random.randint(1, usernum + 1) |
|
|
|
|
|
candid_item = user_train[user][np.random.randint(0, len(user_train[user]))] |
|
|
|
|
|
return candid_item |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# user = np.random.choice(1, usernum + 1) |
|
|
|
|
|
|
|
|
|
|
|
# user = random.randint(1,usernum+1) |
|
|
|
|
|
# while len(user_train[user])<3: |
|
|
|
|
|
# user = random.randint(1, usernum + 1) |
|
|
|
|
|
# candid_item = user_train[user][random.randint(0, len(user_train[user])-1)] |
|
|
|
|
|
# |
|
|
|
|
|
# while candid_item in s: |
|
|
|
|
|
# while len(user_train[user]) < 3: |
|
|
|
|
|
# user = random.randint(1, usernum + 1) |
|
|
|
|
|
# candid_item = user_train[user][random.randint(0, len(user_train[user])-1)] |
|
|
|
|
|
# return candid_item |
|
|
|
|
|
|
|
|
|
|
|
user = random.choice(list(user_train.keys())) |
|
|
|
|
|
item = random.choice(user_train[user]) |
|
|
|
|
|
|
|
|
|
|
|
while item in s: |
|
|
|
|
|
user = random.choice(list(user_train.keys())) |
|
|
|
|
|
item = random.choice(user_train[user]) |
|
|
|
|
|
return item |
|
|
|
|
|
|
|
|
def random_negetive_batch(l, r, s, user_train,usernum, batch_users): |
|
|
def random_negetive_batch(l, r, s, user_train,usernum, batch_users): |
|
|
user = np.random.choice(batch_users) |
|
|
user = np.random.choice(batch_users) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
seq = np.zeros([maxlen], dtype=np.int32) |
|
|
seq = np.zeros([maxlen], dtype=np.int32) |
|
|
pos = np.zeros([maxlen], dtype=np.int32) |
|
|
pos = np.zeros([maxlen], dtype=np.int32) |
|
|
neg = np.zeros([maxlen*number_of_neg], dtype=np.int32) |
|
|
|
|
|
|
|
|
neg = np.zeros([(maxlen-1)*number_of_neg + 1], dtype=np.int32) |
|
|
|
|
|
|
|
|
if len(user_train[user]) < maxlen: |
|
|
if len(user_train[user]) < maxlen: |
|
|
nxt_idx = len(user_train[user]) - 1 |
|
|
nxt_idx = len(user_train[user]) - 1 |
|
|
|
|
|
|
|
|
idx = maxlen - 1 |
|
|
idx = maxlen - 1 |
|
|
|
|
|
|
|
|
ts = set(user_train[user]) |
|
|
ts = set(user_train[user]) |
|
|
for i in reversed(user_train[user][min(0, nxt_idx - 1 - maxlen) : nxt_idx - 1]): |
|
|
|
|
|
|
|
|
for i in reversed(user_train[user][(nxt_idx - maxlen) : nxt_idx ]): |
|
|
seq[idx] = i |
|
|
seq[idx] = i |
|
|
pos[idx] = nxt |
|
|
pos[idx] = nxt |
|
|
# if nxt != 0: neg[idx] = random_neq(1, itemnum + 1, ts, user_train,usernum) |
|
|
# if nxt != 0: neg[idx] = random_neq(1, itemnum + 1, ts, user_train,usernum) |
|
|
|
|
|
|
|
|
# support_negative_triples.append([seq[-1], curr_rel, neg[idx]]) |
|
|
# support_negative_triples.append([seq[-1], curr_rel, neg[idx]]) |
|
|
for j in range(number_of_neg): |
|
|
for j in range(number_of_neg): |
|
|
for idx in range(maxlen-1): |
|
|
for idx in range(maxlen-1): |
|
|
support_negative_triples.append([seq[idx], curr_rel, neg[j*maxlen + idx]]) |
|
|
|
|
|
|
|
|
support_negative_triples.append([seq[idx], curr_rel, neg[j*(maxlen-1) + idx]]) |
|
|
|
|
|
|
|
|
query_triples.append([seq[-1],curr_rel,pos[-1]]) |
|
|
query_triples.append([seq[-1],curr_rel,pos[-1]]) |
|
|
negative_triples.append([seq[-1],curr_rel,neg[-1]]) |
|
|
negative_triples.append([seq[-1],curr_rel,neg[-1]]) |