text_plain_output_4.png text_plain_output_6.png application_vnd.jupyter.stderr_output_3.png application_vnd.jupyter.stderr_output_5.png text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png
from tqdm import tqdm

import numpy as np

import pandas as pd

import torch

device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
a = 100
b = 100
dim_mesh = (a - 1) * (b - 1)
bias_bo = True
bias_bo_g = True
bias_bo_d = True
train_samples = 1200
end_samples = 1600
path = '../input/2stage-simon/f_set_nonl.npy'
ffine_all = 10000 * np.load(path)
ffine = ffine_all[:train_samples]
nb_samples = np.shape(ffine)[0]
nb_times = np.shape(ffine)[1]
fcoarse_reshape = np.reshape(ffine, (nb_samples, nb_times, a - 1, b - 1))
fcoarse_reshape_torch_before = torch.tensor(fcoarse_reshape, dtype=torch.float32, device=device)
ffine_test = ffine_all[train_samples:end_samples]
nb_samples_test = np.shape(ffine_test)[0]
nb_times_test = np.shape(ffine_test)[1]
fcoarse_reshape_test = np.reshape(ffine_test, (nb_samples_test, nb_times_test, a - 1, b - 1))
fcoarse_reshape_test_torch_before = torch.tensor(fcoarse_reshape_test, dtype=torch.float32, device=device)

path = '../input/cem100/cembasis_10.npy'
_R_ = np.load(path)
Rt = np.transpose(_R_)
print('Rt shape', np.shape(Rt))
RtFh = []
for jx in tqdm(range(nb_samples)):
    RtFh_t = []
    for ix in range(nb_times):
        RtFh_t.append(np.matmul(Rt, ffine[jx, ix, :]))
    RtFh.append(RtFh_t)
print('np.shape(RtFh):  R^t*F_h', np.shape(RtFh))
RtFh = np.array(RtFh)
RtFh0 = RtFh[:, :, 0::3]
Rtfh0_torch = torch.tensor(RtFh0, dtype=torch.float32, device=device)
print('Rtfh0_torch', Rtfh0_torch.size())
nb_model_phy0 = Rtfh0_torch.size()[-1]
print('nb_model_phy0', nb_model_phy0)
RtFh1 = RtFh[:, :, 1::3]
Rtfh1_torch = torch.tensor(RtFh1, dtype=torch.float32, device=device)
print('Rtf1torch', Rtfh1_torch.size())
nb_model_phy1 = Rtfh1_torch.size()[-1]
print('nb_model_phy1', nb_model_phy1)
RtFh2 = RtFh[:, :, 2::3]
Rtfh2_torch = torch.tensor(RtFh2, dtype=torch.float32, device=device)
print('Rtfh2_torch', Rtfh2_torch.size())
nb_model_phy2 = Rtfh2_torch.size()[-1]
print('nb_model_phy2', nb_model_phy2)
Rtfh_torch = torch.tensor(RtFh, dtype=torch.float32, device=device)
print('Rtfh_torch', Rtfh_torch.size())
nb_model_phy = Rtfh_torch.size()[-1]
print('nb_model_phy', nb_model_phy)
RtFh_test = []
for jx in tqdm(range(nb_samples_test)):
    RtFh_t = []
    for ix in range(nb_times_test):
        RtFh_t.append(np.matmul(Rt, ffine_test[jx, ix, :]))
    RtFh_test.append(RtFh_t)
print('np.shape(RtFh_test):  R^t*F_h', np.shape(RtFh_test))
RtFh_test = np.array(RtFh_test)
RtFh_test0 = RtFh_test[:, :, 0::3]
Rtfh0_torch_test = torch.tensor(RtFh_test0, dtype=torch.float32, device=device)
print('Rtfh0_torch_test', Rtfh0_torch_test.size())
nb_model_phy0_test = Rtfh0_torch_test.size()[-1]
print('nb_model_phy0_test', nb_model_phy0_test)
RtFh_test1 = RtFh_test[:, :, 1::3]
Rtfh1_torch_test = torch.tensor(RtFh_test1, dtype=torch.float32, device=device)
print('Rtfh1_torch_test', Rtfh1_torch_test.size())
nb_model_phy1_test = Rtfh1_torch_test.size()[-1]
print('nb_model_phy1_test', nb_model_phy1_test)
invRtR = LA.inv(np.matmul(Rt, _R_))
path = '../input/2stage-simon/sol_set_nonl.txt'
u_f_all = 10000 * pd.read_csv(path, sep=' ', header=None).values
print('u_f_all', np.shape(u_f_all))
u_f = u_f_all[:train_samples]
print('u_f', np.shape(u_f))
u_H = []
for ix in range(nb_samples):
    u_H.append(np.matmul(invRtR, np.matmul(Rt, u_f[ix])))
u_H = np.array(u_H)
print('u_H', np.shape(u_H))
nb_rdm = np.shape(u_H)[1]
print('nb_rdm', nb_rdm)
u_f_test = u_f_all[train_samples:end_samples]
print('u_f_test', np.shape(u_f_test))
u_H_test = []
for ix in range(nb_samples_test):
    u_H_test.append(np.matmul(invRtR, np.matmul(Rt, u_f_test[ix])))
u_H_test = np.array(u_H_test)
print('u_H_test', np.shape(u_H_test))
nb_rdm_test = np.shape(u_H_test)[1]
print('nb_rdm_test', nb_rdm_test)