import sys from collections import OrderedDict sys.path.append("../..") import ktensor import tensorTools def loadJSON(fn): with open(fn, 'rb') as outfile: jsonDict = json.load(outfile) outfile.close() return jsonDict MBias = ktensor.loadTensor( "../results/pred-raw-bias-marble-{0}.dat".format(run)) M = ktensor.loadTensor("../results/pred-raw-marble-{0}.dat".format(run)) MCP = ktensor.loadTensor("../results/pred-raw-cpapr-{0}.dat".format(run)) X, axisDict, classDict = tensorTools.loadSingleTensor( "../data/cms-tensor-{0}.dat") cptLevel = loadJSON("../data/cpt-level2.json") icdLevel = loadJSON("../data/icd-level2.json") ## lookup values def lookupDict(idx, n, axisDict, levelDict): ivAxis = {v: k for k, v in axisDict[n].items()} modeCat = [levelDict[str(ivAxis[k])] for k in idx] return modeCat
import json import sys from collections import OrderedDict sys.path.append("../..") import ktensor import tensorTools def loadJSON(fn): with open(fn, 'rb') as outfile: jsonDict = json.load(outfile) outfile.close() return jsonDict MBias = ktensor.loadTensor("../results/pred-raw-bias-marble-{0}.dat".format(run)) M = ktensor.loadTensor("../results/pred-raw-marble-{0}.dat".format(run)) MCP = ktensor.loadTensor("../results/pred-raw-cpapr-{0}.dat".format(run)) X, axisDict, classDict = tensorTools.loadSingleTensor("../data/cms-tensor-{0}.dat") cptLevel = loadJSON("../data/cpt-level2.json") icdLevel = loadJSON("../data/icd-level2.json") ## lookup values def lookupDict(idx, n, axisDict, levelDict): ivAxis = {v: k for k, v in axisDict[n].items()} modeCat = [levelDict[str(ivAxis[k])] for k in idx] return modeCat ## get the top k from MBias
import ktensor import numpy import decompTools caseX = ktensor.loadTensor("results/apr-raw-1.dat") controlX = ktensor.loadTensor("results/apr-raw-2.dat") allX = ktensor.loadTensor("results/apr-raw-200.dat") ## since they don't share the same axis, remove one of the factors caseX.U = [caseX.U[1], caseX.U[2]] caseX = decompTools.zeroSmallFactors(caseX, 1e-2) controlX.U = [controlX.U[1], controlX.U[2]] controlX = decompTools.zeroSmallFactors(controlX, 1e-2) allX.U = [allX.U[1], allX.U[2]] allX = decompTools.zeroSmallFactors(allX, 1e-2) fms = caseX.greedy_fms(controlX) numpy.savetxt("plots/case-control.csv", fms, delimiter=",") allFMS = caseX.greedy_fms(allX) numpy.savetxt("plots/case-all.csv", allFMS, delimiter=",")
import ktensor import numpy; import decompTools caseX = ktensor.loadTensor("results/apr-raw-1.dat") controlX = ktensor.loadTensor("results/apr-raw-2.dat") allX = ktensor.loadTensor("results/apr-raw-200.dat") ## since they don't share the same axis, remove one of the factors caseX.U = [caseX.U[1], caseX.U[2]] caseX = decompTools.zeroSmallFactors(caseX, 1e-2) controlX.U = [controlX.U[1], controlX.U[2]] controlX = decompTools.zeroSmallFactors(controlX, 1e-2) allX.U = [allX.U[1], allX.U[2]] allX = decompTools.zeroSmallFactors(allX, 1e-2) fms = caseX.greedy_fms(controlX) numpy.savetxt("plots/case-control.csv", fms, delimiter=",") allFMS = caseX.greedy_fms(allX) numpy.savetxt("plots/case-all.csv", allFMS, delimiter=",")
import numpy as np import json import sys sys.path.append("../..") import ktensor import tensorTools dataOut = [] bins = [None, None, None] for run in range(400, 409): M = ktensor.loadTensor("../results/pred-raw-cpapr-{0}.dat".format(run)) for n in range(M.ndims()): factVals = M.U[n].flatten() nnzIdx = np.nonzero(factVals) factVals = factVals[nnzIdx] if bins[n] == None: factHist = np.histogram(factVals, bins=10) bins[n] = factHist[1] else: factHist = np.histogram(factVals, bins=bins[n]) dataOut.append({"expt": run, "mode": n, "count": factHist[0].tolist(), "bins": factHist[1].tolist()}) with open("cpapr-hist.json", "w") as outfile: json.dump(dataOut, outfile)
import numpy as np import json import sys sys.path.append("../..") import ktensor import tensorTools dataOut = [] bins = [None, None, None] for run in range(400, 409): M = ktensor.loadTensor("../results/pred-raw-cpapr-{0}.dat".format(run)) for n in range(M.ndims()): factVals = M.U[n].flatten() nnzIdx = np.nonzero(factVals) factVals = factVals[nnzIdx] if bins[n] == None: factHist = np.histogram(factVals, bins=10) bins[n] = factHist[1] else: factHist = np.histogram(factVals, bins=bins[n]) dataOut.append({ "expt": run, "mode": n, "count": factHist[0].tolist(), "bins": factHist[1].tolist() }) with open("cpapr-hist.json", 'w') as outfile: json.dump(dataOut, outfile)