import numpy as np
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
import tensorflow_probability as tfp
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from etudes.gaussian_process import gp_sample_custom, dataframe_from_gp_samples
# shortcuts
tfd = tfp.distributions
kernels = tfp.math.psd_kernels
# constants
n_features = 1 # dimensionality
n_index_points = 256 # nbr of index points
n_samples = 5 # nbr of GP prior samples
jitter = 1e-15
kernel_cls = kernels.MaternFiveHalves
seed = 42 # set random seed for reproducibility
random_state = np.random.RandomState(seed)
# index points
X_q = np.linspace(-1.0, 1.0, n_index_points).reshape(-1, n_features)
# kernel specification
amplitude, length_scale_inv = np.ogrid[0.05:0.16:0.05, 10.0:0.5:-1.5]
length_scale = 1.0 / length_scale_inv
kernel = kernel_cls(amplitude=amplitude, length_scale=length_scale)
# instantiate Gaussian Process
gp = tfd.GaussianProcess(kernel=kernel, index_points=X_q, jitter=jitter)
gp_samples = gp_sample_custom(gp, n_samples, seed=seed)
with tf.Session() as sess:
gp_samples_arr = sess.run(gp_samples)
data = dataframe_from_gp_samples(gp_samples_arr, X_q, amplitude,
length_scale, n_samples)