def obtainCompressedCSV(readingsNormalized): """ Compresses teh sensor data """ T_in = dtensor(readingsNormalized.reshape(necessary, 3, 3)) T_out, fit, itr, _ = als(T_in, 3) final_Compressed = "\n".join( [",".join([str(k) for k in n]) for n in T_out.U[0]] + [",".join([str(k) for k in n]) for n in T_out.U[1]] + [",".join([str(k) for k in n]) for n in T_out.U[2]] + [",".join([str(n) for n in T_out.lmbda])]) return final_Compressed
def cp_cpt(sparse_data, rank, W): time_s = time.time() est_data = sparse_data.copy() dshape = np.shape(est_data) SD = dtensor(sparse_data.copy()) U = [] P, fit, itr, arr = cp.als(SD, rank) loc_data = P.totensor() est_data = W * est_data + (W == False) * loc_data time_e = time.time() print('-' * 8 + 'cp' + '-' * 8) print('exec_time:' + str(time_e - time_s) + 's') return est_data
index_movies.append(movie_list.index(m[0])) index_genres.append(genre_list.index(m[1])) index_tags.append(tag_list.index(m[3])) for i in range(len(index_tags)): mat[index_movies[i]][index_tags[i]][index_genres[i]] = 1 arr = mat return (arr, movie_list, movie_timestamp) tensor, m, seeds = load() T = dtensor(tensor) # SCIKIT TENSOR REPRESENTATION ### CP-DECOMPOSITION ### P, fit, itr, exectimes = cp.als(T, 5, init='random') ### FACTOR MATRICES GENERATED ### Factor1 = P.U[0] Factor2 = P.U[1] Factor3 = P.U[2] UF = ktensor.totensor(P) UF1 = dtensor.unfold(UF, 0) #print(UF1.shape) U, s, V = linalg.svd(UF1) U = U[:, :10] #print(U.shape) D_T = np.transpose(U) movie_movie = np.dot(U, D_T)
for i in range(len(index_tags)): mat[index_movies[i]][index_tags[i]][index_genres[i]] = 1 arr = mat tensor,m, user_movies = arr,movie_list,movie_timestamp irrel = [] while(True): m = movie_list #user_movies = list(user_movies.keys()) m, user_movies = movie_list,movie_timestamp #user_movies = list(user_movies.keys()) T = dtensor(tensor) # SCIKIT TENSOR REPRESENTATION seeds = movie_timestamp ### CP-DECOMPOSITION ### P, fit, itr, exectimes = cp.als(T, 5, init = 'nvecs') ### FACTOR MATRICES GENERATED ### Factor1 = P.U[0] DP = ktensor.totensor(P) UF = dtensor.unfold(DP,0) U, s, V = linalg.svd(UF) U = U[:,:10] #print(U.shape) D_T = np.transpose(U) movie_movie = np.dot(U, D_T) seeds = sorted(seeds.items(), key=operator.itemgetter(1), reverse=True) seeds_weight = {}