bestscore = score besttau = tau bestwfa = copy.deepcopy(wfa) print "Tau: ",tau, " Score: ", score avruntime += wfa.buildtime nummodelsmade += 1 if metric == "WER": bestscore = bestwfa.get_WER(testdata) iohelpers.write_results(RESULTS_DIR+"co-"+wfatype+"-"+str(maxbasissize)+"-pautomac="+problem+"-"+metric+".txt", problem, wfatype+", "+"tau= "+str(besttau)+", basis size="+str(len(basisdict)), metric, bestscore, avruntime/float(nummodelsmade)) if probabilistic: iohelpers.write_pnfa_model(MODEL_DIR+"co-"+wfatype+"-"+str(maxbasissize)+"-pautomac="+problem+"-"+metric+".fsm", bestwfa) else: RESULTS_DIR = "/home/williamleif/Dropbox/icml2014-experiments/results/real/" if problem == "tree": traindata = iohelpers.parse_file("/home/williamleif/Dropbox/icml2014-experiments/datasets/treebankdata.obs") validdata = traindata[0:5000] testdata = traindata[5000:10000] traindata = traindata[10000:len(traindata)] maxK = 500
if not success: break if metric == "WER": score = wfa.get_WER(validdata) else: score = wfa.get_perplexity(validdata) if bestsize == 0: bestscore = score bestsize = i bestwfa = copy.deepcopy(wfa) elif score < bestscore and abs(score-1000) > 0.1: bestscore = score bestsize = i bestwfa = copy.deepcopy(wfa) print "Model size: ", i, " Score: ", score avruntime += wfa.buildtime nummodelsmade += 1 if metric == "WER": bestscore = bestwfa.get_WER(testdata) else: bestscore = bestwfa.get_perplexity(testdata) iohelpers.write_results(RESULTS_DIR+"tensor-"+metric+".txt", problem,"size= "+str(bestsize)+", basis size="+str(basislength), metric, bestscore, 0) iohelpers.write_pnfa_model(MODEL_DIR+"tensor-"+str(bestsize)+"-pautomac="+problem+"-"+metric+".fsm", bestwfa)