MCPcopy Create free account
hub / github.com/alibaba/bigcomputing / gen_neg_hist

Method gen_neg_hist

DIEN/data_iterator.py:115–144  ·  view source on GitHub ↗
(self, length)

Source from the content-addressed store, hash-verified

113 return neg_item, neg_cate, neg_shop, neg_node, neg_product, neg_brand
114
115 def gen_neg_hist(self, length):
116 if len(self.neg_hist_catch.get(length, [1])) == self.max_catch_num:
117 index = int(random.random()*self.max_catch_num)
118 return self.neg_hist_catch[length][index]
119 else:
120 #generate a new neg hist
121 neg_item_hist = []
122 neg_cate_hist = []
123 neg_shop_hist = []
124 neg_node_hist = []
125 neg_product_hist = []
126 neg_brand_hist = []
127 for i in range(length):
128 item_idx = int(random.random()*self.num_items)
129 neg_item = self.all_items[item_idx]
130 neg_cate = self.map_cate(self.item_info[neg_item][0])
131 neg_cate_hist.append(neg_cate)
132 neg_shop = self.map_shop(self.item_info[neg_item][1])
133 neg_shop_hist.append(neg_shop)
134 neg_node = self.map_node(self.item_info[neg_item][2])
135 neg_node_hist.append(neg_node)
136 neg_product = self.map_product(self.item_info[neg_item][3])
137 neg_product_hist.append(neg_product)
138 neg_brand = self.map_brand(self.item_info[neg_item][4])
139 neg_brand_hist.append(neg_brand)
140 neg_item = self.map_item(self.all_items[item_idx])#map origin item to item_id
141 neg_item_hist.append(neg_item)
142 self.neg_hist_catch[length] = self.neg_hist_catch.get(length, [])
143 self.neg_hist_catch[length].append([neg_item_hist, neg_cate_hist, neg_shop_hist, neg_node_hist, neg_product_hist, neg_brand_hist])
144 return [neg_item_hist, neg_cate_hist, neg_shop_hist, neg_node_hist, neg_product_hist, neg_brand_hist]
145
146 def fill_ndarray(self, hist):
147 nd_his = numpy.ones(self.maxlen) * -1

Callers 1

nextMethod · 0.95

Calls 6

map_cateMethod · 0.95
map_shopMethod · 0.95
map_nodeMethod · 0.95
map_productMethod · 0.95
map_brandMethod · 0.95
map_itemMethod · 0.95

Tested by

no test coverage detected