from core.preprocessing import create_x_plot from data.toy_regression import ( create_split_periodic_data_heteroscedastic, ground_truth_periodic_function, ) tfd = tfp.distributions # %% codecell np.random.seed(0) n_train = 90 batch_size = n_train epochs = 10000 x_train, y_train = create_split_periodic_data_heteroscedastic(n_data=n_train, sigma1=0.1, sigma2=0.8, seed=42) x_plot = create_x_plot(x_train) # preprocessor = StandardPreprocessor() # x_train, _x_plot, x_plot = preprocessor.preprocess_create_x_train_x_plot(_x_train) y_ground_truth = ground_truth_periodic_function(x_plot) input_shape = [1] layer_units = [50, 20] + [2] layer_activations = ["relu"] * (len(layer_units) - 1) + ["linear"] weight_prior = tfd.Normal(0, 1) bias_prior = weight_prior a = 0.5 b = 0.01 _var_d = tfd.InverseGamma(a, b)
figure_dir.mkdir(parents=True, exist_ok=True) experiment_name = "non-linear-gap" # %% seed = 0 n_train = 50 # train and test variables beginning with an underscore are unprocessed. amplitude = 1 p = 2 _x_train, y_train = create_split_periodic_data_heteroscedastic( n_data=n_train, lower1=-4.0, upper1=-1.3, lower2=4.0, upper2=7.0, sigma1=0.1, sigma2=0.1, p=p, amplitude=amplitude, seed=seed, ) preprocessor = StandardPreprocessor() x_train, _x_plot, x_plot = preprocessor.preprocess_create_x_train_x_plot( _x_train, test_ds=0.03) y_ground_truth = ground_truth_periodic_function(_x_plot, p=p, amplitude=amplitude) layer_units = [50, 20] + [2] layer_activations = ["relu"] * (len(layer_units) - 1) + ["linear"]
ground_truth_periodic_function, ) tfd = tfp.distributions # %% data_seed = 0 n_train = 20 # train and test variables beginning with an underscore are unprocessed. _x_train, _y_train = create_split_periodic_data_heteroscedastic( n_data=n_train, lower1=-1, upper1=0, lower2=1, upper2=2, sigma1=0.2, sigma2=0.2, seed=42, ) preprocessor = StandardPreprocessor() x_train, _x_plot, x_plot = preprocessor.preprocess_create_x_train_x_plot( _x_train, test_ds=0.5, n_test=200 ) _y_ground_truth = ground_truth_periodic_function(_x_plot) y_preprocessor = StandardPreprocessor() y_train = y_preprocessor.fit_transform(_y_train) y_ground_truth = y_preprocessor.transform(_y_ground_truth) # %% markdown # If we simply used two neurons in the output layer we can model heteroscedastic noise
) from core.preprocessing import StandardPreprocessor from data.toy_regression import ( create_split_periodic_data_heteroscedastic, ground_truth_periodic_function, ) tfd = tfp.distributions # %% codecell np.random.seed(0) n_train = 150 batchsize_train = 20 # train and test variables beginning with an underscore are unprocessed. _x_train, y_train = create_split_periodic_data_heteroscedastic(n_data=n_train, seed=42) preprocessor = StandardPreprocessor() x_train, _x_plot, x_plot = preprocessor.preprocess_create_x_train_x_plot( _x_train, test_ds=0.5) y_ground_truth = ground_truth_periodic_function(_x_plot) layer_units = [20, 20] + [1] layer_activations = ["relu"] * (len(layer_units) - 1) + ["linear"] # %% codecell y_lim = [-5, 5] fig, ax = plt.subplots(figsize=(8, 8)) plot_training_data(_x_train, y_train, fig=fig, ax=ax, y_lim=y_lim) plot_ground_truth(_x_plot, y_ground_truth, fig=fig, ax=ax) ax.legend()