Ejemplo n.º 1
0
    def test_networks(self,
                      momenta,
                      nj,
                      models,
                      x_means,
                      x_stds,
                      y_means,
                      y_stds,
                      return_predictions=False):

        try:
            momenta = momenta.tolist()
        except:
            pass

        if self.all_legs:
            all_jets = False
            nlegs = self.nlegs + 2
        else:
            all_jets = True
            nlegs = self.nlegs

        NN = Model(input_size=(nlegs) * 4,
                   momenta=momenta,
                   labels=nj,
                   all_jets=all_jets,
                   all_legs=self.all_legs,
                   model_datset=self.model_dataset,
                   high_precision=self.high_precision)

        _, _, _, _, _, _, _, _ = NN.process_training_data()

        for i in range(self.training_reruns):
            print('Predicting on model {}'.format(i))
            model_dir_new = self.model_base_dir + self.model_dir + '_{}/'.format(
                i)
            x_standard = NN.process_testing_data(moms=momenta,
                                                 x_mean=x_means[i],
                                                 x_std=x_stds[i],
                                                 y_mean=y_means[i],
                                                 y_std=y_stds[i])
            pred = models[i].predict(x_standard)
            y_pred = NN.destandardise_data(y_pred=pred.reshape(-1),
                                           x_mean=x_means[i],
                                           x_std=x_stds[i],
                                           y_mean=y_means[i],
                                           y_std=y_stds[i])

            if not return_predictions:
                np.save(model_dir_new + '/pred_{}'.format(len(momenta)),
                        y_pred)
            else:
                return y_pred

        print('############### Finished ###############')
Ejemplo n.º 2
0
    y_mean=y_mean,
    y_std=y_std
)

test_momenta = [
    [500., 0., 0., 500.],
    [500., 0., 0., -500.],
    [253.58419798, -239.58965912, 66.81985738, -49.36443422],
    [373.92489886, 7.43568582, -321.18384469, 191.32558238],
    [372.49090317, 232.1539733, 254.36398731, -141.96114816]
]

testing_X = NN.process_testing_data(moms=test_momenta)

pred_std = model.predict(testing_X)
pred_destd = NN.destandardise_data(y_pred=pred_std)

with open ('./single_test_arch.json', 'w') as fout:
    fout.write(model.to_json())
model.save_weights(args.weights)

print ('Model JSON and weights save')

print ('Saving out sample data')
with open('./data/single_test_sample.dat', 'w') as fin:
    fin.write("{}\n".format(len(testing_X[0])))
    for idx, i in enumerate(testing_X[0]):
        if idx == len(testing_X[0]) - 1:
            fin.write(str(i) + "\n")
        else:
            fin.write(str(i) + " ")