Xtest = np.array(Xtest) Ptest = np.array(Ptest) X = np.array(X) P = np.array(P) print str(Xtest.shape[0]) + " test sequences" print str(X.shape[0]) + " training sequences" if "1" in sys.argv[8]: L1 = True else: L1 = False if "y" in sys.argv[4]: model = MLFKTModel(X, P, intermediate_states, 0, L1) else: model = MLFKTModel(X, P, intermediate_states, 0.1, L1) mcmc = MCMCSampler(model, 0.15) burn = int(sys.argv[1]) for c in range(20): mcmc.burnin(int(math.ceil((burn + 0.0) / 20))) print ("finished burn-in #: " + str((c + 1) * burn / 20)) num_iterations = int(sys.argv[2]) loop = 20 per_loop = int(math.ceil((num_iterations + 0.0) / loop)) for c in range(loop): a = time.time()
newX = [] newP = [] for c in range(X.shape[0]): if X[c,-1] >= maxl-1: newX.append(X[c,:]) newP.append(P[c,:]) X = np.array(newX) P = np.array(newP) start = time.time() if 'y' in sys.argv[4]: model = MLFKTModel(X, P, intermediate_states, 0) else: model = MLFKTModel(X, P, intermediate_states, 0.1) mcmc = MCMCSampler(model, 0.15) burn = int(sys.argv[1]) for c in range(20): mcmc.burnin(int(math.ceil((burn+0.0) / 20))) print("finished burn-in #: " + str((c+1)*burn/20)) num_iterations = int(sys.argv[2]) loop = 20 per_loop = int(math.ceil((num_iterations+0.0) / loop)) for c in range(loop): a = time.time()
def run_learned_model(skill, diff_params = None): intermediate_states = 0 fname = skill.replace(" ","_") fname = fname.replace("\"","") X = np.loadtxt(open("dump/observations_" + fname + ".csv", "rb"), delimiter=",") P = np.loadtxt(open("dump/problems_" + fname + ".csv","rb"),delimiter=",") k = 5 #split 1/kth into test set N = X.shape[0] Xtest = [] Xnew = [] Ptest = [] Pnew = [] for c in range(N): if c % k == 0:#random.random() < 1 / (k+0.0): Xtest.append(X[c,:]) Ptest.append(P[c,:]) else: Xnew.append(X[c,:]) Pnew.append(P[c,:]) X = Xnew Xtest = np.array(Xtest) P = Pnew Ptest = np.array(Ptest) model = MLFKTModel(X, P, 0, 0.1) predl = [] errl = [] for c in range(3): param_dict = json.load(open("feb20_exps/PARAMS_"+skill+"_2states_500iter.json","r")) param_dict = param_dict[c] params = model.get_parameters() for k, v in param_dict.iteritems(): #print k, v if k == "Pi": val = np.array(v) params["L"].set(val) params["L"].save() elif k == "Trans": val = np.array(v) params["T"].set(val) params["T"].save() elif k == "Emit": G = scipy.special.logit(v[0][1]) S = scipy.special.logit(v[1][0]) params["G_0"].set(G) params["S"].set(S) params["G_0"].save() params["S"].save() else: if diff_params is None: params[k].set(v) params[k].save() else: params[k].set(diff_params[k]) params[k].save() params['Dsigma'].save() model.load_test_split(Xtest, Ptest) preds = model.get_predictions() err = preds - Xtest predl.append(preds) errl.append(err) return Xtest, Ptest, np.mean(predl,0), np.mean(errl,0)