mcmc.MH(per_loop)
        b = time.time()
        print ("finished iteration: " + str((c + 1) * per_loop) + " in " + str(int(b - a)) + " seconds")

    end = time.time()

    print ("Finished burnin and " + str(num_iterations) + " iterations in " + str(int(end - start)) + " seconds.")

    folder = "plots_" + fname
    # plotting samples will also load the MAP estimates
    # mcmc.plot_samples(folder + "/", str(num_iterations) + '_iterations')

    # load up test data and run predictions
    model.load_test_split(Xtest, Ptest, True)

    pred = model.get_predictions()
    num = model.get_num_predictions()
    mast = model.get_mastery()

    err = pred - Xtest
    rmse = np.sqrt(np.sum(err ** 2) / num)

    errl = np.zeros(num)
    predl = np.zeros(num)
    mastl = np.zeros(num)
    xtestl = np.zeros(num)
    i = 0
    for n in range(pred.shape[0]):
        for t in range(pred.shape[1]):
            if pred[n][t] == -1:
                break
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)