-
Notifications
You must be signed in to change notification settings - Fork 0
/
angle_of_modes.py
114 lines (90 loc) · 4.08 KB
/
angle_of_modes.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import h5py
import numpy as np
from numpy import einsum
import configparser
import matplotlib.pyplot as plt
from pathlib import Path
config = configparser.ConfigParser()
config.read('_system.ini')
results_dir = config['system_info']['alternate_location']
parent_folder = Path(results_dir,'experiment_nonlinear_regularisation')
ls0 = [*parent_folder.glob('rmb00-*')]
ls01 = [*parent_folder.glob('rmb01-*')]
ls001 = [*parent_folder.glob('rmb001-*')]
angles0 = []
angles01 = []
angles001 = []
for folder in ls0:
folder_path = Path(parent_folder,folder)
filename = Path(folder_path,'results.h5')
with h5py.File(filename,'r') as hf:
modes_train = np.array(hf.get('modes_train'))
Ntrain = modes_train.shape[1]
# calculate orthogonality
mode1 = einsum('t y z u-> y z t u',np.squeeze(modes_train[0,...]))
mode2 = einsum('t y z u-> y z t u',np.squeeze(modes_train[1,...]))
mode1 = np.vstack((mode1[:,:,:,0],mode1[:,:,:,1]))
mode2 = np.vstack((mode2[:,:,:,0],mode2[:,:,:,1]))
mode1 = np.reshape(mode1,(-1,Ntrain))
mode2 = np.reshape(mode2,(-1,Ntrain))
magnitude1 = np.sqrt(einsum('x t -> t', mode1**2))
magnitude2 = np.sqrt(einsum('x t -> t', mode2**2))
magnitude = magnitude1*magnitude2
modes_dot_product = np.diag(einsum('ij,ik',mode1,mode2))
angles = np.arccos(modes_dot_product / magnitude)
angles0.extend(angles)
angles0 = np.array(angles0)
for folder in ls01:
folder_path = Path(parent_folder,folder)
filename = Path(folder_path,'results.h5')
with h5py.File(filename,'r') as hf:
modes_train = np.array(hf.get('modes_train'))
Ntrain = modes_train.shape[1]
# calculate orthogonality
mode1 = einsum('t y z u-> y z t u',np.squeeze(modes_train[0,...]))
mode2 = einsum('t y z u-> y z t u',np.squeeze(modes_train[1,...]))
mode1 = np.vstack((mode1[:,:,:,0],mode1[:,:,:,1]))
mode2 = np.vstack((mode2[:,:,:,0],mode2[:,:,:,1]))
mode1 = np.reshape(mode1,(-1,Ntrain))
mode2 = np.reshape(mode2,(-1,Ntrain))
magnitude1 = np.sqrt(einsum('x t -> t', mode1**2))
magnitude2 = np.sqrt(einsum('x t -> t', mode2**2))
magnitude = magnitude1*magnitude2
modes_dot_product = np.diag(einsum('ij,ik',mode1,mode2))
angles = np.arccos(modes_dot_product / magnitude)
angles01.extend(angles)
angles01 = np.array(angles01)
for folder in ls001:
folder_path = Path(parent_folder,folder)
filename = Path(folder_path,'results.h5')
with h5py.File(filename,'r') as hf:
modes_train = np.array(hf.get('modes_train'))
Ntrain = modes_train.shape[1]
# calculate orthogonality
mode1 = einsum('t y z u-> y z t u',np.squeeze(modes_train[0,...]))
mode2 = einsum('t y z u-> y z t u',np.squeeze(modes_train[1,...]))
mode1 = np.vstack((mode1[:,:,:,0],mode1[:,:,:,1]))
mode2 = np.vstack((mode2[:,:,:,0],mode2[:,:,:,1]))
mode1 = np.reshape(mode1,(-1,Ntrain))
mode2 = np.reshape(mode2,(-1,Ntrain))
magnitude1 = np.sqrt(einsum('x t -> t', mode1**2))
magnitude2 = np.sqrt(einsum('x t -> t', mode2**2))
magnitude = magnitude1*magnitude2
modes_dot_product = np.diag(einsum('ij,ik',mode1,mode2))
angles = np.arccos(modes_dot_product / magnitude)
angles001.extend(angles)
angles001 = np.array(angles001)
plt.figure(figsize=(7,5))
plt.boxplot([angles0,angles001,angles01],sym='.',zorder=2)
plt.xticks([1,2,3],['$\gamma = 0.0$','$\gamma = 0.01$','$\gamma = 0.1$'],fontsize='large')
plt.ylabel('$\\alpha$ (rad)' ,fontsize='large')
plt.ylim([0.8,2.6])
plt.hlines(np.pi/2,xmin=0.5,xmax=3.5,linestyles='dotted',colors='k',zorder=1,label='$\pi/2$')
plt.text(0.87,2.52,f'$\sigma$={np.std(angles0):.3f}',fontsize='large')
plt.text(0.87,2.45,f'$\mu$={np.mean(angles0):.3f}',fontsize='large')
plt.text(1.83,2.52,f'$\sigma$={np.std(angles01):.3f}',fontsize='large')
plt.text(1.83,2.45,f'$\mu$={np.mean(angles01):.3f}',fontsize='large')
plt.text(2.87,2.52,f'$\sigma$={np.std(angles001):.3f}',fontsize='large')
plt.text(2.87,2.45,f'$\mu$={np.mean(angles001):.3f}',fontsize='large')
plt.legend(loc='best', bbox_to_anchor=(0.7, 0.5, 0.3, 0.3))
plt.savefig('regularisation-orthogonality.pdf')