Пример #1
0
inputFile = args.inputFile.format("data")
yaxis = decompTools.loadAxisInfo(args.inputFile.format("info"))

print "Starting Tensor Factorization with ID:{0}".format(exptID)
np.random.seed(seed)
Y, ystats, mstats = decompTools.decomposeCountTensor(inputFile,
                                                     R,
                                                     outerIters=iter,
                                                     innerIters=innerIter,
                                                     convergeTol=tol,
                                                     zeroTol=zeroThr)
Y.writeRawFile("results/apr-raw-{0}.dat".format(exptID))
Youtfile = "results/apr-db-{0}-{1}.csv".format(exptID, iter)
Ysqlfile = "results/apr-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 data local infile '/home/joyce/workspace//Health/analysis/tensor/{0}' into table tensor_factors fields terminated by '|'  ;\n"
    .format(Youtfile))
sqlOut.write(
    "insert into tensor_models(expt_ID, label_ID, description, rank, iterations, inner_iterations, seed, least_squares, log_likelihood, kkt_violation) values({0}, {1}, \'{2}\', {3}, {4}, {5}, {6}, {7}, {8}, {9});\n"
    .format(exptID, labelID, exptDesc, R, iter, innerIter, seed, mstats['LS'],
            mstats['LL'], mstats['KKT']))
sqlOut.close()

print "Completed Tensor Factorization with ID:{0}".format(exptID)
print "Import sql file " + Ysqlfile
Пример #2
0
    idx = np.flatnonzero(pf[:, 0])
    dbOut = np.column_stack((axis[idx], np.repeat(0, len(idx)), pf[idx, 0]))
    for col in range(1, factors):
        idx = np.flatnonzero(pf[:, col])
        dbOut = np.vstack((dbOut, np.column_stack((axis[idx], np.repeat(col, len(idx)), pf[idx, col]))))
    return dbOut


refX = sptensor.loadTensor(inputFile.format(0, "data"))
refAxis = decompTools.loadAxisInfo(inputFile.format(0, "info"))
## Find the factors for the first one
klp, M, mstats = findFactors(refX, R=rank, outerIter=outerIter, innerIter=10)

## Store off the factors to be loaded into a database
M.writeRawFile(MrawFile)
Mout = decompTools.getDBOutput(M, refAxis)
Mout = np.column_stack((np.repeat(exptID, Mout.shape[0]), Mout))
np.savetxt(Moutfile, Yout, fmt="%s", delimiter="|")

sqlOut = file(Ysqlfile, "w")
## write the factors and the models into the database
sqlOut.write(
    "load client from /home/joyceho/workspace/tensor/{0} of del modified by coldel| insert into joyceho.tensor_factors;\n".format(
        Youtfile
    )
)
sqlOut.write(
    "insert into joyceho.tensor_models values({0}, {1}, '{2}','{3}', {4}, {5}, {6}, {7}, {8});\n".format(
        exptID, labelID, patientSet, exptDesc, iter, innerIter, mstats["LS"], mstats["LL"], mstats["KKT"]
    )
)
Пример #3
0
sqlOutfile = "results/rank-sql-{0}.sql".format(exptID)
rawFilePattern = "results/rank-raw-{0}-{1}.dat"
dbOutPattern = "results/rank-db-{0}-{1}.dat"
dbTimePattern = "results/rank-time-db-{0}-{1}.dat"

print "Starting Tensor Rank Experiment with ID:{0}".format(exptID)

sqlOut = file(sqlOutfile, "w")
for r in R:
    np.random.seed(seed)
    Y, ystats, mstats = decompTools.decomposeCountTensor(inputFile, R=r, outerIters=iter, innerIters=innerIter, convergeTol=tol, zeroTol=zeroThr)
    Y.writeRawFile(rawFilePattern.format(exptID, r)) # output the raw file
    # output the saved db file
    dbYFile = dbOutPattern.format(exptID, r)
    Yout = decompTools.getDBOutput(Y, yaxis)
    Yout = np.column_stack((np.repeat(exptID, Yout.shape[0]), Yout))
    np.savetxt(dbYFile, Yout, fmt="%s", delimiter="|")
    sqlOut.write("load client from /home/joyceho/workspace/tensor/{0} of del modified by coldel| insert into joyceho.tensor_rank_factors;\n".format(dbYFile))
    # output the rank_times
    timeStats = np.delete(ystats, range(2,6), axis=1)
    timeStats = np.column_stack((np.repeat(exptID, timeStats.shape[0]), np.repeat(r, timeStats.shape[0]), timeStats))
    timeFile = dbTimePattern.format(exptID, r)
    np.savetxt(timeFile, timeStats, delimiter="|")
    sqlOut.write("load client from /home/joyceho/workspace/tensor/{0} of del modified by coldel| insert into joyceho.tensor_rank_times;\n".format(timeFile))
    # output the model results
    sqlOut.write("insert into joyceho.tensor_rank_models values({0},{1},\'{2}\',{3},{4},{5},{6},{7},{8});\n".format(exptID, labelID, exptDesc, iter, innerIter, r, mstats['LS'], mstats['LL'], mstats['KKT']))

sqlOut.close()
print "Complete Tensor Rank Experiment with ID:{0}".format(exptID)
print "Import sql file " + sqlOutfile
Пример #4
0
        idx = np.flatnonzero(pf[:, col])
        dbOut = np.vstack(
            (dbOut,
             np.column_stack((axis[idx], np.repeat(col, len(idx)), pf[idx,
                                                                      col]))))
    return dbOut


refX = sptensor.loadTensor(inputFile.format(0, "data"))
refAxis = decompTools.loadAxisInfo(inputFile.format(0, "info"))
## Find the factors for the first one
klp, M, mstats = findFactors(refX, R=rank, outerIter=outerIter, innerIter=10)

## Store off the factors to be loaded into a database
M.writeRawFile(MrawFile)
Mout = decompTools.getDBOutput(M, refAxis)
Mout = np.column_stack((np.repeat(exptID, Mout.shape[0]), Mout))
np.savetxt(Moutfile, Yout, fmt="%s", delimiter="|")

sqlOut = file(Ysqlfile, "w")
## write the factors and the models into the database
sqlOut.write(
    "load client from /home/joyceho/workspace/tensor/{0} of del modified by coldel| insert into joyceho.tensor_factors;\n"
    .format(Youtfile))
sqlOut.write(
    "insert into joyceho.tensor_models values({0}, {1}, \'{2}\',\'{3}\', {4}, {5}, {6}, {7}, {8});\n"
    .format(exptID, labelID, patientSet, exptDesc, iter, innerIter,
            mstats['LS'], mstats['LL'], mstats['KKT']))

output = np.zeros((1, 4))
for i in timeRange: