Esempio n. 1
0
def test_update_grid(engine, N=100, D=1, seed=42):
    gp = GP_BACKEND(engine)

    rng = np.random.RandomState(seed)
    X = rng.normal(size=(N, D))

    # Test updating the grid
    gp.configure(**msgp_test_config)
    gp.update_data('tmp', X)
    gp.update_grid('tmp')
    gp.eng.eval("assert(exist('xg','var') ~= 0)")
Esempio n. 2
0
def test_update_data(engine, N=100, D=1, seed=42):
    gp = GP_BACKEND(engine)

    rng = np.random.RandomState(seed)
    X = rng.normal(size=(N, D))
    y = rng.normal(size=(N, D))

    # Test updating data
    gp.configure(**gp_test_config)
    gp.update_data('tmp', X, y)
    gp.eng.eval("assert(exist('X_tmp','var') ~= 0)")
    gp.eng.eval("assert(exist('y_tmp','var') ~= 0)")
Esempio n. 3
0
def test_evaluate(engine, N=100, D=1, seed=42):
    gp = GP_BACKEND(engine)

    rng = np.random.RandomState(seed)
    X = rng.normal(size=(N, D))
    y = rng.normal(size=(N, D))
    gp.update_data('tmp', X, y)

    # Evaluate GP
    gp.configure(**gp_test_config)
    nlZ = gp.evaluate('tmp')

    # Evaluate MSGP
    gp.configure(**msgp_test_config)
    gp.update_grid('tmp')
    nlZ = gp.evaluate('tmp')
Esempio n. 4
0
def test_get_dlik_dx(engine, N=100, D=1, seed=42):
    gp = GP_BACKEND(engine)

    rng = np.random.RandomState(seed)
    X = rng.normal(size=(N, D))
    y = rng.normal(size=(N, D))
    gp.update_data('tmp', X, y)

    # GP
    gp.configure(**gp_test_config)
    dlik_dx = gp.get_dlik_dx('tmp')
    assert type(dlik_dx) is np.ndarray
    assert dlik_dx.shape == (N, D)

    # MSGP
    gp.configure(**msgp_test_config)
    gp.update_grid('tmp')
    dlik_dx = gp.get_dlik_dx('tmp')
    assert type(dlik_dx) is np.ndarray
    assert dlik_dx.shape == (N, D)
Esempio n. 5
0
def test_train(engine, N=100, D=1, seed=42):
    gp = GP_BACKEND(engine)

    rng = np.random.RandomState(seed)
    X_tr = rng.normal(size=(N, D))
    y_tr = rng.normal(size=(N, D))

    # Train a GP
    gp.configure(**gp_test_config)
    hyp = gp.train(5, X_tr, y_tr)

    assert type(hyp) is dict
    assert set(hyp.keys()) == set(gp_test_config['hyp'].keys())

    # Train an MSGP
    gp.configure(**msgp_test_config)
    gp.update_data('tr', X_tr, y_tr)
    gp.update_grid('tr')
    hyp = gp.train(5)

    assert type(hyp) is dict
    assert set(hyp.keys()) == set(gp_test_config['hyp'].keys())
Esempio n. 6
0
def test_predict(engine, N=100, D=1, seed=42):
    gp = GP_BACKEND(engine)

    rng = np.random.RandomState(seed)
    X_tr = rng.normal(size=(N, D))
    y_tr = rng.normal(size=(N, D))
    X_tst = rng.normal(size=(N, D))
    gp.update_data('tr', X_tr, y_tr)

    # Predict using GP
    gp.configure(**gp_test_config)
    ymu, ys2 = gp.predict(X_tst, return_var=True)

    assert type(ymu) is np.ndarray and type(ys2) is np.ndarray
    assert ymu.shape == ys2.shape

    # Predict using MSGP
    gp.configure(**msgp_test_config)
    gp.update_grid('tr')
    ymu, ys2 = gp.predict(X_tst, return_var=True)

    assert type(ymu) is np.ndarray and type(ys2) is np.ndarray
    assert ymu.shape == ys2.shape