예제 #1
0
파일: tco.py 프로젝트: davmre/treegp
def main():

    tco_dir = os.path.join(os.getenv("SIGVISA_HOME"), "papers", "product_tree", "tco_learned")

    # gen_tco(tco_dir)
    tco_train_X, tco_train_y, tco_test_X, tco_test_y = load_tco(tco_dir=tco_dir)

    # hyperparams = learn_hyperparams(tco_dir, tco_train_X, tco_train_y, hyperparams=np.array([1, 100, 100, 100], dtype=float), dfn_str='lld', sparse_invert=True, k=1000)
    hyperparams = np.array([95.140702, 12552.9422512, 1257.77376988, 100.0], dtype=float)
    # hyperparams = np.array([95.140702,  12552.9422512, 100.0,  100.], dtype=float)

    np.save(os.path.join(tco_dir, "testX.npy"), tco_test_X)
    np.save(os.path.join(tco_dir, "testy.npy"), tco_test_y)
    np.save(os.path.join(tco_dir, "hyperparams.npy"), hyperparams)

    print "loaded data"
    train_realdata_gp(
        tco_dir,
        tco_train_X,
        tco_train_y,
        hyperparams=hyperparams,
        dfn_str="lld",
        sparse_invert=False,
        basisfns=[lambda x: 1],
        param_cov=np.array(((10000,),)),
        param_mean=np.array((0,)),
    )
    print "trained model"
    test_predict(tco_dir)
    print "evaluated predictions"

    # eval_gp(bdir=tco_dir, test_n=100)
    print "timings finished"
예제 #2
0
파일: sarcos.py 프로젝트: davmre/treegp
def main():

    sarcos_dir = os.path.join(os.getenv("SIGVISA_HOME"), "papers", "product_tree", "sarcos")

    sarcos_train_X, sarcos_train_y, sarcos_test_X, sarcos_test_y, hyperparams = load_sarcos(sdir=sarcos_dir)
    np.save(os.path.join(sarcos_dir, "testX.npy"), sarcos_test_X)
    np.save(os.path.join(sarcos_dir, "testy.npy"), sarcos_test_y)
    np.save(os.path.join(sarcos_dir, "hyperparams.npy"), hyperparams)
    print "loaded sarcos data and converted to numpy format"

    train_realdata_gp(sarcos_dir, sarcos_train_X, sarcos_train_y, hyperparams)
    print "trained model"
    test_predict(sarcos_dir)
    print "evaluated predictions"

    eval_gp(bdir=sarcos_dir, test_n=100)
    print "timings finished"
예제 #3
0
파일: plot_fitz.py 프로젝트: davmre/treegp
def learn_gp(X, y):

    p = np.random.permutation(len(y))
    train_n = int(len(y) * 0.2)
    trainX = X[p[:train_n], :]
    trainy = y[p[:train_n]]
    testX = X[p[train_n:], :]
    testy = y[p[train_n:]]

    fitz_dir = os.path.join(os.getenv("SIGVISA_HOME"), "papers", "product_tree", "fitz_learned")

    # hyperparams = np.array([0.5,  3.0, 50.0,  50.0], dtype=float)
    # hyperparams = learn_hyperparams(fitz_dir, trainX, trainy, dfn_str='lld', hyperparams=hyperparams, sparse_invert=False, basisfns = [lambda x : 1,], param_cov=np.array(((10000,),)), param_mean = np.array((0,)), k=1000)

    # print "got hyperparams", hyperparams

    # hyperparams = np.array([1.16700753,    2.53145332,  212.46536884,157.68719303], dtype=float)

    np.save(os.path.join(fitz_dir, "testX.npy"), testX)
    np.save(os.path.join(fitz_dir, "testy.npy"), testy)
    np.save(os.path.join(fitz_dir, "hyperparams.npy"), hyperparams)

    print "loaded data"

    train_realdata_gp(
        fitz_dir,
        trainX,
        trainy,
        hyperparams=hyperparams,
        sparse_invert=False,
        basisfns=[lambda x: 1],
        param_cov=np.array(((10000,),)),
        param_mean=np.array((0,)),
        dfn_str="lld",
    )
    test_predict(fitz_dir)
    eval_gp(bdir=fitz_dir, test_n=100)
def main(n_max=18000):

    rundir = sys.argv[1]
    task_name = sys.argv[2]



    basedir = os.path.join(os.getenv('SIGVISA_HOME'), 'papers', 'product_tree', 'run', rundir)
    basename = os.path.join(basedir, task_name)
    X_train = np.loadtxt(basename + '_X_train.txt', delimiter=',')
    y_train = np.loadtxt(basename + '_y_train.txt',  delimiter=',')

    n_X = X_train.shape[0]
    if n_X > n_max:
        X_train = np.array(X_train[:n_max,:], copy=True)
        y_train = np.array(y_train[:n_max], copy=True)
        print "using restricted subset of %d training points" % (n_max)
    actual_n = min(n_X, n_max)


    X_test = np.loadtxt(basename + '_X_test.txt',  delimiter=',')
    y_test = np.loadtxt(basename + '_y_test.txt',  delimiter=',')

    """
    #for nu in (90,):
    nu = 90
    csficbase = basename + '_csfic_%d' % nu if nu is not None else basename + '_csfic'
    csficmodel_dir = basename + "_py_csfic_%d" % nu if nu is not None else basename + "_py_csfic"
    print csficmodel_dir
    #if not os.path.exists(csficbase):
    #    continue
    csgp = os.path.join(csficmodel_dir, 'trained_%d.gp' % actual_n)

    mkdir_p(csficmodel_dir)
    if os.path.exists(csgp):
        gp_csfic = SparseGP_CSFIC(fname=csgp, build_tree=True, leaf_bin_size=15)
    else:
        gp_csfic = load_matlab_csficmodel(csficbase, X_train, y_train)
        gp_csfic.save_trained_model(csgp)

    #print "testing predictions"
    #test_predict(csficmodel_dir, sgp=gp_csfic, testX=X_test, testy=y_test)

    #print "testing cutoff rule 0"
    #eval_gp(bdir=csficmodel_dir, testX=X_test, test_n=200, gp=gp_csfic, cutoff_rule=0)
    #print "testing cutoff rule 1"
    #eval_gp(bdir=csficmodel_dir, testX=X_test, test_n=200, gp=gp_csfic, cutoff_rule=1)
    #print "testing cutoff rule 2"
    #eval_gp(bdir=csficmodel_dir, testX=X_test, test_n=200, gp=gp_csfic, cutoff_rule=2)

    print "testing leaf bins 15"
    gp_csfic10 = SparseGP_CSFIC(fname=csgp, build_tree=True, leaf_bin_size=10)
    eval_gp(bdir=csficmodel_dir, testX=X_test, test_n=200, gp=gp_csfic10, cutoff_rule=2, flag="_bin15")

    #print "testing leaf bins 100"
    #gp_csfic50 = SparseGP_CSFIC(fname=csgp, build_tree=True, leaf_bin_size=50)
    #eval_gp(bdir=csficmodel_dir, testX=X_test, test_n=200, gp=gp_csfic50, cutoff_rule=2, flag="_bin50")



    """
    semodel_dir = basename + "_py_se"
    segp = os.path.join(semodel_dir, 'trained.gp')
    mkdir_p(semodel_dir)
    if os.path.exists(segp):
        gp_se = SparseGP(fname=segp, build_tree=True, leaf_bin_size=0, sparse_invert=False)
    else:
        gp_se = load_matlab_semodel(basename, X_train, y_train)
        gp_se.save_trained_model(segp)

    test_predict(semodel_dir, sgp=gp_se, testX=X_test, testy=y_test)
    eval_gp(bdir=semodel_dir, testX=X_test, test_n=200, gp=gp_se)