Esempio n. 1
0
def try_bec():

    # get train and test data
    in_provider = InputProvider()
    harmonic_sims, tr, te, va = in_provider.get_bec_data()
    data = bec.get_within_range(tr, g_low=30, g_high=50, n=100)
    # data_test = te.sample(100)

    # get gp model and fit
    gp = GP()
    gp.fit(torch.FloatTensor(data[['g', 'x']].to_numpy()),
           torch.FloatTensor(data.psi.to_numpy()), True)

    # predict around one some fixed Dim
    df = bec.get_closest_sim(harmonic_sims, g=30.)
    test_gx = np.stack([30. * np.ones(df.x.shape[0]), df.x]).transpose()

    y_pred, sigma = gp.predict(torch.FloatTensor(test_gx))
    print(y_pred, sigma)

    # plot subplots with multiple fixed dimensions

    # specify input dimensions,
    # the first entry is fixed for each iteration
    # the second entry is plotted against the fixed dimension
    input_dimensions = ['g', 'x']
    out_dimensions = 'psi'
    sub_plot_multiple_gp(gp, harmonic_sims, [5, 30, 60, 90], input_dimensions,
                         out_dimensions)
Esempio n. 2
0
def try_1D():

    ip = InputProvider()
    x_data, y_data, x_test = ip.get_1d_regression_data()

    gp = GP()
    gp.fit(x_data, y_data, True)
    gp.plot(x_test)
Esempio n. 3
0
import matplotlib.pyplot as plt
from torch.optim import Adam
import torch
import numpy as np

from gp import GP


if __name__ == '__main__':
  gp = GP()
  f = lambda x: ( torch.cos(2 * x[:, 0]) + torch.sin(x[:, 1]) ).view(-1)
  n1, n2, ny = 40, 100, 5
  domain = (-5, 5)
  X_data = torch.distributions.Uniform(
      domain[0] + 2, domain[1] - 2).sample((n1, 2))
  y_data = f(X_data)
  X_test = torch.linspace(domain[0], domain[1], n2)
  X_test = torch.stack([X_test, X_test]).view(-1, 2)
  y_test = f(X_test)

  gp.fit(X_data, y_data, True, epochs=10000)
  y_pred, _ = gp.predict(X_test)
  print('MSE : ', ((y_pred - y_test)**2).mean().item() )