-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperformance_analysis.py
168 lines (149 loc) · 5.68 KB
/
performance_analysis.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 23 18:38:46 2021
@author: weilong
"""
import pickle
import os
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
from pathlib import Path
mpl.rcParams['font.size'] = 7
mpl.rcParams['pdf.fonttype'] = 42
mpl.rcParams['ps.fonttype'] = 42
mpl.rcParams['font.family'] = 'arial'
mpl.rcParams['axes.spines.left'] = True
mpl.rcParams['axes.spines.right'] = False
mpl.rcParams['axes.spines.top'] = False
mpl.rcParams['axes.spines.bottom'] = True
filename = Path('files\\final')
Num_MD = 10
Ncontexts = 2
PFClearn = False
seed_setup = [1,2,3,4,5,6,7,8,9,10]
#seed_setup = [1,3,5]
MDeffect = True
mse_md = list()
for RNGSEED in seed_setup:
file = 'train_numMD'+str(Num_MD)+'_numContext'+str(Ncontexts)+'_MD'+str(MDeffect)+'_PFC'+str(PFClearn)+'_R'+str(RNGSEED)+'.pkl'
file = open(filename / file,'rb')
data = pickle.load(file)
mse_md.append(data['mse'])
mse_md_mean = np.mean(mse_md,axis=0)
#import pdb;pdb.set_trace()
MDeffect = False
mse_mdoff = list()
for RNGSEED in seed_setup:
file = 'train_numMD'+str(Num_MD)+'_numContext'+str(Ncontexts)+'_MD'+str(MDeffect)+'_PFC'+str(PFClearn)+'_R'+str(RNGSEED)+'.pkl'
file = open(filename / file,'rb')
data = pickle.load(file)
mse_mdoff.append(data['mse'])
mse_mdoff_mean = np.mean(mse_mdoff,axis=0)
MDeffect = False
mse_ewc = list()
for RNGSEED in seed_setup:
file = 'train_ewc_numMD'+str(Num_MD)+'_numContext'+str(Ncontexts)+'_MD'+str(MDeffect)+'_PFC'+str(PFClearn)+'_R'+str(RNGSEED)+'.pkl'
file = open(filename / file,'rb')
data = pickle.load(file)
log = data['log']
mse_ewc.append(log['mse'])
mse_ewc_mean = np.mean(mse_ewc,axis=0)
filesave = Path('results')
os.makedirs(filesave, exist_ok=True)
plt.figure(figsize=(2.4,2.4))
plt.plot(mse_mdoff_mean,'darkgrey',label='PFC')
#ci_off = 1.96 * np.std(mse_mdoff,axis=0)/np.mean(mse_mdoff,axis=0)
ci_off = np.std(mse_mdoff,axis=0)
plt.fill_between(np.arange(len(mse_mdoff_mean)), (mse_mdoff_mean-ci_off), (mse_mdoff_mean+ci_off), color='darkgrey', alpha=.2)
plt.plot(mse_md_mean,'darkviolet',label='PFC-MD')
#ci_on = 1.96 * np.std(mse_md,axis=0)/np.mean(mse_md,axis=0)
ci_on = np.std(mse_md,axis=0)
plt.fill_between(np.arange(len(mse_md_mean)), (mse_md_mean-ci_on), (mse_md_mean+ci_on), color='darkviolet', alpha=.2)
#plt.plot(mse_ewc_mean,'tab:green',label='PFC-EWC')
##ci_on = 1.96 * np.std(mse_md,axis=0)/np.mean(mse_md,axis=0)
#ci_ewc = np.std(mse_ewc,axis=0)
#plt.fill_between(np.arange(len(mse_ewc_mean)), (mse_ewc_mean-ci_ewc), (mse_ewc_mean+ci_ewc), color='tab:green', alpha=.2)
plt.xticks(np.arange(0,301,100),np.arange(0,601,200))
plt.xlabel('Trials'),plt.ylabel('MSE')
plt.ylim(0, 0.6)
plt.legend(frameon=False)
plt.axvspan(0, 100, ymin=0, ymax=1, alpha=0.1, color='tab:orange')
plt.axvspan(200, 300, ymin=0, ymax=1, alpha=0.1, color='tab:orange')
plt.axvspan(100, 200, ymin=0, ymax=1, alpha=0.1, color='tab:green')
plt.title('Model Performance')
plt.tight_layout()
#plt.savefig(filesave/'mse.pdf')
plt.savefig(filesave/'mse_all.pdf', dpi=300)
plt.figure(figsize=(2.4,2.4))
plt.plot(mse_mdoff_mean[200:],'darkgrey',label='PFC')
ci_off = np.std(mse_mdoff,axis=0)
plt.fill_between(np.arange(len(mse_mdoff_mean[200:])), (mse_mdoff_mean[200:]-ci_off[200:]), (mse_mdoff_mean[200:]+ci_off[200:]), color='darkgrey', alpha=.2)
plt.plot(mse_md_mean[200:],'darkviolet',label='PFC-MD')
ci_on = np.std(mse_md,axis=0)
plt.fill_between(np.arange(len(mse_md_mean[200:])), (mse_md_mean[200:]-ci_on[200:]), (mse_md_mean[200:]+ci_on[200:]), color='darkviolet', alpha=.2)
#plt.plot(mse_ewc_mean[200:],'tab:green',label='PFC-EWC')
#ci_ewc = np.std(mse_ewc,axis=0)
#plt.fill_between(np.arange(len(mse_ewc_mean[200:])), (mse_ewc_mean[200:]-ci_ewc[200:]), (mse_ewc_mean[200:]+ci_ewc[200:]), color='tab:green', alpha=.2)
plt.xticks(np.arange(0,101,25),np.arange(400,601,50))
plt.xlabel('Trials'),plt.ylabel('MSE')
plt.legend(frameon=False)
plt.title('Model Performance')
plt.tight_layout()
plt.savefig(filesave/'mse_all_switch.pdf', dpi=300)
#"""
#MSE vs. cycles
#"""
#import pickle
#import os
#import matplotlib.pyplot as plt
#import numpy as np
#import matplotlib as mpl
#from pathlib import Path
#
#mpl.rcParams['font.size'] = 7
#mpl.rcParams['pdf.fonttype'] = 42
#mpl.rcParams['ps.fonttype'] = 42
#mpl.rcParams['font.family'] = 'arial'
#
#filename = Path('files')
#Num_MD = 10
#Ncontexts = 2
#PFClearn = False
#seed_setup = [1,3,5]
#
#MDeffect = True
#mse_md = list()
#for RNGSEED in seed_setup:
# file = 'train_softSwitch_numMD'+str(Num_MD)+'_numContext'+str(Ncontexts)+'_MD'+str(MDeffect)+'_PFC'+str(PFClearn)+'_R'+str(RNGSEED)+'.pkl'
# file = open(filename / file,'rb')
# data = pickle.load(file)
# mse_md.append(data['mse'])
#
#mse_md = np.mean(mse_md,axis=0)*2
##import pdb;pdb.set_trace()
#MDeffect = False
#mse_mdoff = list()
#for RNGSEED in seed_setup:
# file = 'train_softSwitch_numMD'+str(Num_MD)+'_numContext'+str(Ncontexts)+'_MD'+str(MDeffect)+'_PFC'+str(PFClearn)+'_R'+str(RNGSEED)+'.pkl'
# file = open(filename / file,'rb')
# data = pickle.load(file)
# mse_mdoff.append(data['mse'])
#
#mse_mdoff = np.mean(mse_mdoff,axis=0)*2
#
#filesave = Path('results')
#os.makedirs(filesave, exist_ok=True)
#
#plt.figure(figsize=(3,2.4))
#plt.plot(mse_mdoff,'tab:red',label='Without MD')
#plt.plot(mse_md,'tab:blue',label='With MD')
#plt.xticks(np.arange(0,301,100),np.arange(0,301,100))
#plt.xlabel('Cycles'),plt.ylabel('MSE')
#plt.legend(frameon=False)
#plt.tight_layout()
#plt.axvspan(0, 100, ymin=0, ymax=1, alpha=0.2, color='tab:orange')
#plt.axvspan(200, 300, ymin=0, ymax=1, alpha=0.2, color='tab:orange')
#plt.axvspan(100, 200, ymin=0, ymax=1, alpha=0.2, color='tab:green')
##plt.savefig(filesave/'mse.pdf')
#plt.savefig(filesave/'mse.png', dpi=300)