def city_computing(): users = range(182) axis_prefs, datas = init_data(users) dimen = len(axis_prefs) # print dimen # print axis_prefs # print datas print datas.has_key(50) for key in datas: # print key data = datas[key] if len(data) == 1: continue tensor = trans(data, dimen, 2) # print tensor para = param(tensor) T = pykov.Chain(para) balance = T.steady() # print balance # print balance.sort(False) # print balance.sort(True) res = vec(balance.sort(True), dimen) print 'user'+str(key)+": "+str(res)
# #print "item:",item # parameter[item[0]] = item[1] # # print parameter preference = [] for i in range(pref_length): # print i if parameter.has_key(i): preference.append(parameter[i] * pref_length / poi_length) else: preference.append(0.0) return preference if __name__ == '__main__': axis_prefs, datas = init_poi_type_data(tuple(range(0, 182))) print "axis_prefs: ", axis_prefs for key in axis_prefs.keys(): print key, " ", axis_prefs[key] print "datas: ", datas for key in datas.keys(): data = datas[key] # print "data_length: ", len(data) if len(data) > 1: tensor = trans(data, len(axis_prefs), 2) result = param(tensor) T = pykov.Chain(result) res = T.steady() print "user" + str(key) + ": ", vec(res, len(axis_prefs))
from util.tensor_old import hosvd2 from util.util import sparse users = (1, ) train = 0.8 axis_poi, data_map, predicts, recommends = init_data(users, 0.8) print "data_map: ", data_map print "predicts: ", predicts print "recommends: ", recommends dimension = len(axis_poi) for key in data_map: data = data_map[key] # print data # tensor为列表 tensor = trans(data, dimension, 3) # print tensor # afunc(tensor) # 第二步:HOSVD,重构tensor # threshold = 0.8 # 将列表转化为高维数组 tensor = np.array(tensor) print "tensor:" print tensor # sparse(tensor)
# #print "item:",item # parameter[item[0]] = item[1] # # print parameter preference = [] for i in range(pref_length): # print i if parameter.has_key(i): preference.append(parameter[i] * pref_length / poi_length) else: preference.append(0.0) return preference if __name__ == '__main__': axis_prefs, datas = init_poi_type_data(tuple(range(0, 182))) print "axis_prefs: ", axis_prefs for key in axis_prefs.keys(): print key, " ", axis_prefs[key] print "datas: ", datas for key in datas.keys(): data = datas[key] # print "data_length: ", len(data) if len(data) > 1: tensor = trans(data, len(axis_prefs), 2) result = param(tensor) T = pykov.Chain(result) res = T.steady() print "user"+str(key)+": ", vec(res, len(axis_prefs))
from util.tensor_old import hosvd2 from util.util import sparse users = (1,) train = 0.8 axis_poi, data_map, predicts, recommends = init_data(users, 0.8) print "data_map: ", data_map print "predicts: ", predicts print "recommends: ", recommends dimension = len(axis_poi) for key in data_map: data = data_map[key] # print data # tensor为列表 tensor = trans(data, dimension, 3) # print tensor # afunc(tensor) # 第二步:HOSVD,重构tensor # threshold = 0.8 # 将列表转化为高维数组 tensor = np.array(tensor) print "tensor:" print tensor