<jupyter_start><jupyter_text>The below cells are for making actual predictions<jupyter_code># Data processing
latent_vars = np.load("/content/drive/MyDrive/Colab Notebooks/data/cae_latent_sf_10vars_800steps_different.npy")

latent_vars_reshaped = np.moveaxis(latent_vars.reshape(800, 10, 10),
                                    0, 2)

train_data = latent_vars_reshaped[:]

# Scaling the latent variables
scaler = MinMaxScaler((-1, 1))
train_data = scaler.fit_transform(
  train_data.reshape(-1, 1)).reshape(train_data.shape)
# Create boundaries and initial values arrays for prediction later
boundaries = np.zeros((2, 10, 800))
boundaries[0] = train_data[2]
boundaries[1] = train_data[9]


init_values = np.zeros((12, 10))
init_values[:] = np.repeat(train_data[3:9, :, 0], 2, axis=0)
# Create boundaries and initial values arrays for prediction later
boundaries = np.zeros((2, 10, 800))
boundaries[0] = train_data[2]
boundaries[1] = train_data[9]


init_values = np.zeros((96, 10))
init_values[:] = np.repeat(train_data[3:9, :, 0], 16, axis=0)
# This is for predicting further into the future
boundaries = np.zeros((2, 10, 1200))
boundaries[0, :, :800] = train_data[2]
boundaries[1, :, :800] = train_data[9]

# Here we pick a particular inlet, this one is one with steady flow (half blue,
# half red). Produces a steady state in the subsequent domains
boundaries[:, :, 800:] = np.repeat(boundaries[:, :, ::6][:, :, 125:126], 400, axis=2)

init_values = np.zeros((96, 10))
init_values[:] = np.repeat(train_data[3:9, :, 0], 16, axis=0)
# This is for predicting further into the future with a changing boundary, 
# repeating an earlier value
boundaries = np.zeros((2, 10, 194))
boundaries[0, :, :134] = train_data[2, :, ::6]
boundaries[1, :, :134] = train_data[9, :, ::6]

# Here we pick a particular inlet, this one is one with steady flow (half blue,
# half red). Produces a steady state in the subsequent domains
boundaries[1, :, 134:] = np.repeat(boundaries[1:2, :, :][:, :, 125:126], 60, axis=2)
boundaries[0, :, 134:] = np.tile(np.concatenate((boundaries[0, :, 125:134], boundaries[0, :, 125:126]), axis=-1), (1,1,6))

init_values = np.zeros((12, 10))
init_values[:] = np.repeat(train_data[3:9, :, 0], 2, axis=0)
# This is for predicting further into the future with a random noise boundary

latent_vars = np.load("/content/drive/MyDrive/Colab Notebooks/latent_vars.npy")

latent_vars = np.expand_dims(np.swapaxes(latent_vars, 0, 1), 0)
#latent_vars = scaler.fit_transform(
#  latent_vars.reshape(-1, 1)).reshape(latent_vars.shape)
latent_vars.shape
boundaries = np.zeros((2, 10, 194))
boundaries[0, :, :134] = train_data[2, :, ::6]
boundaries[1, :, :134] = train_data[9, :, ::6]

# Here we pick a particular inlet, this one is one with steady flow (half blue,
# half red). Produces a steady state in the subsequent domains
boundaries[1, :, 134:] = np.repeat(boundaries[1:2, :, :][:, :, 125:126], 60, axis=2)
boundaries[0, :, 134:] = latent_vars[0, :, ::1][:, :60]

init_values = np.zeros((12, 10))
init_values[:] = np.repeat(train_data[3:9, :, 0], 2, axis=0)
plt.plot(boundaries[0, :, 0:190:].T)
train_point_1 = train_data[1:4, :, 125*6:134*6][:, :, 0]
train_point_2 = train_data[1:4, :, 125*6:134*6][:, :, 34]
train_point_3 = train_data[1:4, :, 125*6:134*6][:, :, 42]
initializer = tf.keras.initializers.RandomNormal(mean=0.0, stddev=0.05, seed=None)
optimizer = tf.keras.optimizers.Nadam(lr=0.0005, beta_1=0.98, beta_2=0.99999)

vars_latent = 100
nPOD = 10
#encoder = keras.models.load_model("/content/drive/MyDrive/Colab Notebooks/data/pred_aae_model_northern-sweep-1-5int/encoder") 
#decoder = keras.models.load_model("/content/drive/MyDrive/Colab Notebooks/data/pred_aae_model_northern-sweep-1-5int/decoder")
#discriminator = keras.models.load_model("/content/drive/MyDrive/Colab Notebooks/data/aae_model_mild-sweep-1/discriminator")

encoder = keras.models.load_model("/content/drive/MyDrive/Colab Notebooks/data/cae_pred_model_clear-sweep-1-6int/encoder") 
decoder = keras.models.load_model("/content/drive/MyDrive/Colab Notebooks/data/cae_pred_model_clear-sweep-1-6int/decoder")
discriminator =  discriminator = build_custom_wider_discriminator(
                vars_latent, initializer, info=True
            )
discriminator._name = "NAME"
pred_adv = Predictive_adversarial(encoder, decoder, discriminator, optimizer)
pred_adv.compile(nPOD)
pred_adv.interval = 6
predicted = pred_adv.predict(boundaries, init_values, 100, iters=3, sor=1, pre_interval=False)
plt.plot(train_data[0, :, ::6].T)
predicted = scaler.inverse_transform(
  predicted.reshape(-1, 1)).reshape(predicted.shape)
plt.plot(predicted[3, :3, :100].T)
plt.plot(latent_vars_reshaped[5, :3, :100*6:6].T)
latent_decoder = keras.models.load_model("/content/drive/MyDrive/Colab Notebooks/data/cae_model_different-sweep-1/decoder")
predicted_10doms = predicted_interpolated[0:10, :, 80:125]

out_reshaped = np.moveaxis(predicted_10doms, 2, 0).reshape(450, 10)
out_grids = latent_decoder.predict(out_reshaped)
out_grids.shape
np.save("out_grids", out_grids)
from scipy import interpolate

predicted_interpolated = np.zeros((10, 10, 198))

for i in range(10):
  f = interpolate.interp1d(np.arange(0, 100), predicted[i, :, :100])
  xnew = np.arange(0, 99, 0.50)
  predicted_interpolated[i, :, :] = f(xnew)
plt.plot(predicted_interpolated[1, :3, :198].T)
config.activation = "elu"
config.in_vars = 100
config.dense_activation = "relu" 
config.batch_size = 64 
config.learning_rate = 0.0005
config.architecture = "slimmer_vinicius"
config.discriminator_architecture = "custom"
config.dropout = 0.3
config.optimizer = "adam"
config.momentum = 0.8
config.beta_2 = 0.9
config.batch_normalization = True
config.regularization = 0.001
config.savemodel = True
config.latent_vars = 100
config.interval = 6
config.final_act = "sigmoid"
config.noise_std = 0.01
config.increment = False
config.epochs = 2
config.n_discriminator = 1
config.n_gradient_ascent = 15
config.domains = 10
config.datafile = "/content/drive/MyDrive/Colab Notebooks/data/cae_latent_sf_100vars_800steps_restful.npy"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15468158630903406, 'fraction_numerical': 0.06664472601612638, 'mean_word_length': 5.649890590809628, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '651380', 'license': 'MIT', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2312, 'n_words': 464, 'path': 'hpc/colab/train_wandb_pred.ipynb', 'repo_name': 'Zeff020/Adversarial_ROM', 'size': '6077'}