-
Notifications
You must be signed in to change notification settings - Fork 4
/
func.py
70 lines (56 loc) · 2.09 KB
/
func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import numpy as np
import matplotlib.pyplot as plt
import math
import h5py
import tensorflow as tf
def load_model(model_name, custom_objects=None):
name = model_name + '.json'
json_file = open(name, 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json, custom_objects=custom_objects)
model.load_weights(model_name + '.h5')
return model
def save_model(model_save_name, model):
with open(model_save_name + '.json', 'w') as json_file:
json_file.write(model.to_json())
model.save_weights(model_save_name + '.h5')
def find_min_max_range(true, pred):
minRange = min(true)
minPred = min(pred)
if minPred < minRange: minRange = minPred
maxRange = max(true)
maxPred = max(pred)
if maxPred > maxRange: maxRange = maxPred
return (minRange, maxRange)
def make_feature_plots(true, prediction, xlabel, particle, bins, density, ranges=None):
if ranges == None: ranges = find_min_max_range(true, prediction)
plt.figure(figsize=(7,5))
plt.hist(prediction, bins=bins, histtype='step', density=density, range = ranges)
plt.hist(true, bins=bins, histtype='step', density=density, range = ranges)
plt.yscale('log', nonpositive='clip')
plt.ylabel('Prob. Density(a.u.)')
plt.xlabel(xlabel)
plt.tight_layout()
plt.legend([particle+' Predicted', particle+' True'])
plt.show()
def mse_loss(true, prediction):
loss = np.mean(np.square(true - prediction),axis=-1)
return loss
def SetStyle():
from matplotlib import rc
rc('text', usetex=True)
import matplotlib as mpl
rc('font', family='serif')
rc('font', size=22)
rc('xtick', labelsize=15)
rc('ytick', labelsize=15)
rc('legend', fontsize=15)
# #
#mpl.rcParams.update({'legend.fontsize': 18})
mpl.rcParams['text.usetex'] = False
mpl.rcParams.update({'axes.labelsize': 18})
mpl.rcParams.update({'legend.frameon': False})
mpl.rcParams.update({'lines.linewidth': 2})
import matplotlib.pyplot as plt
mpl.rcParams.update({'font.size': 19})