R = args.rank seed = args.seed iter = args.iterations innerIter = 10 tol = 1e-2 zeroThr = 1e-5 # input file and output file inputFile = args.inputFile.format("data") yaxis = decompTools.loadAxisInfo(args.inputFile.format("info")) print "Starting Tensor Factorization with ID:{0}".format(exptID) X = sptensor.loadTensor(inputFile) np.random.seed(seed) Y, ls = CP_ALS.cp_als(X, R, tol=tol, maxiters=iter) ll = CP_APR.loglikelihood(X, Y) # normalize the factors using the 1 norm and then sort in descending order Y.normalize_sort(1) Y = decompTools.zeroSmallFactors(Y, zeroThr=zeroThr) Y.writeRawFile("results/als-raw-{0}.dat".format(exptID)) Youtfile = "results/als-db-{0}-{1}.csv".format(exptID, iter) Ysqlfile = "results/als-sql-{0}.sql".format(exptID) # save the decomposition into the format Yout = decompTools.getDBOutput(Y, yaxis) Yout = np.column_stack((np.repeat(exptID, Yout.shape[0]), Yout)) np.savetxt(Youtfile, Yout, fmt="%s", delimiter="|") sqlOut = file(Ysqlfile, "w") sqlOut.write("load client from /home/joyceho/workspace/tensor/{0} of del modified by coldel| insert into joyceho.tensor_factors;\n".format(Youtfile))
R = args.rank seed = args.seed iter = args.iterations innerIter = 10 tol = 1e-2 zeroThr = 1e-5 # input file and output file inputFile = args.inputFile.format("data") yaxis = decompTools.loadAxisInfo(args.inputFile.format("info")) print "Starting Tensor Factorization with ID:{0}".format(exptID) X = sptensor.loadTensor(inputFile) np.random.seed(seed) Y, ls = CP_ALS.cp_als(X, R, tol=tol, maxiters=iter) ll = CP_APR.loglikelihood(X, Y) # normalize the factors using the 1 norm and then sort in descending order Y.normalize_sort(1) Y = decompTools.zeroSmallFactors(Y, zeroThr=zeroThr) Y.writeRawFile("results/als-raw-{0}.dat".format(exptID)) Youtfile = "results/als-db-{0}-{1}.csv".format(exptID, iter) Ysqlfile = "results/als-sql-{0}.sql".format(exptID) # save the decomposition into the format Yout = decompTools.getDBOutput(Y, yaxis) Yout = np.column_stack((np.repeat(exptID, Yout.shape[0]), Yout)) np.savetxt(Youtfile, Yout, fmt="%s", delimiter="|") sqlOut = file(Ysqlfile, "w") sqlOut.write(
def logLikelihood(self): ## calculate the log likelihood for each tensor ll = [CP_APR.loglikelihood(self.X[i], self.M[i]) for i in range(len(self.X))] return np.sum(np.array(ll))