def model_build(self): dim_r = 4 dim_h_hidden = 128 dim_g_hidden = 128 x_context = tf.placeholder(tf.float32, shape=(None, self.dim)) y_context = tf.placeholder(tf.float32, shape=(None, 1)) x_target = tf.placeholder(tf.float32, shape=(None, self.dim)) y_target = tf.placeholder(tf.float32, shape=(None, 1)) neural_process = NeuralProcess(x_context, y_context, x_target, y_target, dim_r, dim_h_hidden, dim_g_hidden) return neural_process
x_init = x[index_init] y_init = y[index_init] index_lef = np.setdiff1d(index_ori, index_init) ''' dim_r = 4 #dim_z = 2 dim_h_hidden = 128 dim_g_hidden = 128 sess = tf.Session() x_context = tf.placeholder(tf.float32, shape=(None, 2)) y_context = tf.placeholder(tf.float32, shape=(None, 1)) x_target = tf.placeholder(tf.float32, shape=(None, 2)) y_target = tf.placeholder(tf.float32, shape=(None, 1)) neural_process = NeuralProcess(x_context, y_context, x_target, y_target, dim_r, dim_h_hidden, dim_g_hidden) train_op_and_loss = neural_process.init_NP(learning_rate=0.001) init = tf.global_variables_initializer() sess.run(init) n_iter = 10001 plot_freq = 1000 x_1_t = np.reshape(x_1, (-1, 1)) x_2_t = np.reshape(x_2, (-1, 1)) x_star = np.concatenate((x_1_t, x_2_t), axis=1) # eps_value = np.random.normal(size=(n_draws, dim_r)) # epsilon = tf.constant(eps_value, dtype=tf.float32) predict_op = neural_process.posterior_predict(x_init, y_init, x_star)
dim_r = 2 #dim_z = 2 dim_h_hidden = 8 dim_g_hidden = 8 sess = tf.Session() x_context = tf.placeholder(tf.float32, shape=(None, 1)) y_context = tf.placeholder(tf.float32, shape=(None, 1)) x_target = tf.placeholder(tf.float32, shape=(None, 1)) y_target = tf.placeholder(tf.float32, shape=(None, 1)) #neural_process = NeuralProcess(x_context, y_context, x_target, y_target, # dim_r, dim_z, dim_h_hidden, dim_g_hidden) neural_process = NeuralProcess(x_context, y_context, x_target, y_target, dim_r, dim_h_hidden, dim_g_hidden) train_op_and_loss = neural_process.init_NP(learning_rate=0.001) init = tf.global_variables_initializer() sess.run(init) n_iter = 5000 plot_freq = 200 n_draws = 50 x_star_temp = np.linspace(x_min, x_max, n_f * 10) x_star = np.expand_dims(x_star_temp, axis=1) #eps_value = np.random.normal(size=(n_draws, dim_r)) eps_value = np.random.normal(size=(n_draws, 1)) epsilon = tf.constant(eps_value, dtype=tf.float32)