Beispiel #1
0
def gp_interpolator(x, y, res=1000, Nparam=3, decouple_sfr=False):

    yerr = np.zeros_like(y)
    yerr[2:(2 + Nparam)] = 0.001 / np.sqrt(Nparam)
    if len(yerr) > 26:
        yerr[2:(2 + Nparam)] = 0.1 / np.sqrt(Nparam)
    if decouple_sfr == True:
        yerr[(2 + Nparam):] = 0.1
    #if decouple_sfr == True:
    #    yerr[-2:] = 0.1/np.sqrt(Nparam)
    #else:
    #    yerr[-2:] = 0.01/np.sqrt(Nparam)

    #kernel = np.var(yax) * kernels.ExpSquaredKernel(np.median(yax)+np.std(yax))
    #k2 = np.var(yax) * kernels.LinearKernel(np.median(yax),order=1)
    #kernel = np.var(y) * kernels.Matern32Kernel(np.median(y)) #+ k2
    kernel = np.var(y) * (kernels.Matern32Kernel(np.median(y)) +
                          kernels.LinearKernel(np.median(y), order=2))
    gp = george.GP(kernel, solver=george.HODLRSolver)

    #print(xax.shape, yerr.shape)
    gp.compute(x.ravel(), yerr.ravel())

    # optimize kernel parameters
    #     p0 = gp.get_parameter_vector()
    #     results = minimize(nll, p0, jac=grad_nll, method="L-BFGS-B", args = (gp, y))
    #     gp.set_parameter_vector(results.x)

    x_pred = np.linspace(np.amin(x), np.amax(x), res)
    y_pred, pred_var = gp.predict(y.ravel(), x_pred, return_var=True)

    return x_pred, y_pred
Beispiel #2
0
def generate_data(kernel, N=50, rng=(-5, 5)):
    var = np.random.randn() * 0.5
    if kernel == 'SE':
        gp = george.GP(0.1 * kernels.ExpSquaredKernel(5 + var))
    elif kernel == 'M32':
        gp = george.GP(0.1 * kernels.Matern32Kernel(5 + var))
    elif kernel == 'PER':
        gp = george.GP(0.1 * kernels.CosineKernel(log_period=0.25 + var / 8))
    elif kernel == 'LIN':
        gp = george.GP(0.1 *
                       kernels.LinearKernel(order=1, log_gamma2=1.25 + var))
    else:
        gp = None
    x = rng[0] + np.diff(rng) * np.sort(np.random.rand(N))
    y = gp.sample(x)
    return x, y
Beispiel #3
0
def gp_interpolator(x,y,res = 1000, Nparam = 3):
    
    yerr = np.zeros_like(y)
    yerr[2:(2+Nparam)] = 0.001/np.sqrt(Nparam)
    if len(yerr) > 26:
        yerr[2:(2+Nparam)] = 0.1/np.sqrt(Nparam)

    #kernel = np.var(yax) * kernels.ExpSquaredKernel(np.median(yax)+np.std(yax))
    #k2 = np.var(yax) * kernels.LinearKernel(np.median(yax),order=1)
    #kernel = np.var(y) * kernels.Matern32Kernel(np.median(y)) #+ k2
    kernel = np.var(y) * (kernels.Matern32Kernel(np.median(y)) + kernels.LinearKernel(np.median(y), order=2))
    gp = george.GP(kernel)

    #print(xax.shape, yerr.shape)

    gp.compute(x.ravel(), yerr.ravel())

    x_pred = np.linspace(np.amin(x), np.amax(x), res)
    y_pred, pred_var = gp.predict(y.ravel(), x_pred, return_var=True)
    return x_pred, y_pred
Beispiel #4
0
def get_kernel(architecture, kernel_name, domain_name_lst, n_dims):

    if architecture == "trans":
        mapping = trans_domain_kernel_mapping
    else:
        mapping = None

    kernel = None
    initial_ls = np.ones([n_dims])

    if kernel_name == "constant":
        kernel = kernels.ConstantKernel(1, ndim=n_dims)
    elif kernel_name == "polynomial":
        kernel = kernels.PolynomialKernel(log_sigma2=1, order=3, ndim=n_dims)
    elif kernel_name == "linear":
        kernel = kernels.LinearKernel(log_gamma2=1, order=3, ndim=n_dims)
    elif kernel_name == "dotproduct":
        kernel = kernels.DotProductKernel(ndim=n_dims)
    elif kernel_name == "exp":
        kernel = kernels.ExpKernel(initial_ls, ndim=n_dims)
    elif kernel_name == "expsquared":
        kernel = kernels.ExpSquaredKernel(initial_ls, ndim=n_dims)
    elif kernel_name == "matern32":
        kernel = kernels.Matern32Kernel(initial_ls, ndim=n_dims)
    elif kernel_name == "matern52":
        kernel = kernels.Matern52Kernel(initial_ls, ndim=n_dims)
    elif kernel_name == "rationalquadratic":
        kernel = kernels.RationalQuadraticKernel(log_alpha=1,
                                                 metric=initial_ls,
                                                 ndim=n_dims)
    elif kernel_name == "expsine2":
        kernel = kernels.ExpSine2Kernel(1, 2, ndim=n_dims)
    elif kernel_name == "heuristic":
        kernel = mapping[domain_name_lst[0]](ndim=n_dims, axes=0)
        for i in range(len(domain_name_lst[1:])):
            d = domain_name_lst[1:][i]
            kernel += mapping[d](ndim=n_dims, axes=i)
    elif kernel_name == "logsquared":
        kernel = kernels.LogSquaredKernel(initial_ls, ndim=n_dims)

    return kernel
Beispiel #5
0
    kernels.CosineKernel(log_period=0.5, ndim=2, axes=1),
    kernels.CosineKernel(log_period=0.75, ndim=5, axes=[2, 3]),
    kernels.ExpSine2Kernel(gamma=0.4, log_period=1.0),
    kernels.ExpSine2Kernel(gamma=12., log_period=0.5, ndim=2),
    kernels.ExpSine2Kernel(gamma=17., log_period=0.5, ndim=2, axes=1),
    kernels.ExpSine2Kernel(gamma=13.7, log_period=-0.75, ndim=5, axes=[2, 3]),
    kernels.ExpSine2Kernel(gamma=-0.7, log_period=0.75, ndim=5, axes=[2, 3]),
    kernels.ExpSine2Kernel(gamma=-10, log_period=0.75),
    kernels.LocalGaussianKernel(log_width=0.5, location=1.0),
    kernels.LocalGaussianKernel(log_width=0.1, location=0.5, ndim=2),
    kernels.LocalGaussianKernel(log_width=1.5, location=-0.5, ndim=2, axes=1),
    kernels.LocalGaussianKernel(log_width=2.0,
                                location=0.75,
                                ndim=5,
                                axes=[2, 3]),
    kernels.LinearKernel(order=0, log_gamma2=0.0),
    kernels.LinearKernel(order=2, log_gamma2=0.0),
    kernels.LinearKernel(order=2, log_gamma2=0.0),
    kernels.LinearKernel(order=5, log_gamma2=1.0, ndim=2),
    kernels.LinearKernel(order=3, log_gamma2=-1.0, ndim=5, axes=2),
    kernels.LinearKernel(order=0, log_gamma2=0.0) +
    kernels.LinearKernel(order=1, log_gamma2=-1.0) +
    kernels.LinearKernel(order=2, log_gamma2=-2.0),
    kernels.PolynomialKernel(order=0, log_sigma2=-10.0),
    kernels.PolynomialKernel(order=2, log_sigma2=-10.0),
    kernels.PolynomialKernel(order=2, log_sigma2=0.0),
    kernels.PolynomialKernel(order=5, log_sigma2=1.0, ndim=2),
    kernels.PolynomialKernel(order=3, log_sigma2=-1.0, ndim=5, axes=2),
    12. * kernels.ExpSine2Kernel(gamma=0.4, log_period=1.0, ndim=5),
    12. * kernels.ExpSquaredKernel(0.4, ndim=3) + 0.1,
]