Пример #1
0
params[:, 4] = 1.0
params[:, 5] = 1.0

# set value of sims with different Omega_m
params[:11, 0] = np.linspace(0.1, 0.5, 11)
params[11:22, 1] = np.linspace(0.6, 1.0, 11)
params[22:33, 2] = np.logspace(np.log10(0.25), np.log10(4.00), 11)
params[33:44, 3] = np.logspace(np.log10(0.25), np.log10(4.00), 11)
params[44:55, 4] = np.logspace(np.log10(0.50), np.log10(2.00), 11)
params[55:66, 5] = np.logspace(np.log10(0.50), np.log10(2.00), 11)
params = (params - min_params) / (max_params - min_params)
params = params.astype(np.float32)
params = torch.from_numpy(params)

# get the parameters of the trained model
model = architecture.model_1hl(6, h1, bins_SFRH, dr)
#model = architecture.model_3hl(6, h1, h2, h3, bins_SFRH, dr)
model.load_state_dict(torch.load(fmodel))
model.to(device=device)

# get prediction
offset = 0
model.eval()
with torch.no_grad():
    params = params.to(device)
    SFRH = model(params)

# load all SFRH and compute mean and std
SFRH_all = data.read_all_SFRH(root_in, sim, realizations, bins_SFRH, root_out)
SFRH_all = np.log10(SFRH_all)
mean = np.mean(SFRH_all, axis=0, dtype=np.float64)
Пример #2
0
    device = torch.device('cpu')

# get the test dataset
test_loader = data.create_dataset('test', seed, fin, batch_size)

# get the number of elements in the test set
size = 0
for x, y in test_loader:
    size += x.shape[0]

# define the array with the results
pred = np.zeros((size, 1), dtype=np.float32)
true = np.zeros((size, 1), dtype=np.float32)

# get the parameters of the trained model
model = architecture.model_1hl(12, h1, 1, dropout_rate)
#model = architecture.model_2hl(12, h1, h2, 1, dropout_rate)
#model = architecture.model_3hl(12, h1, h2, h3, 1, dropout_rate)
model.load_state_dict(torch.load(fmodel, map_location=torch.device(device)))
model.to(device=device)

# loop over the different batches and get the prediction
offset = 0
model.eval()
for x, y in test_loader:
    with torch.no_grad():
        x = x.to(device)
        y = y.to(device)
        y_NN = model(x)
        length = x.shape[0]
        pred[offset:offset + length] = y_NN.cpu().numpy()