-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize.py
More file actions
72 lines (62 loc) · 2.27 KB
/
optimize.py
File metadata and controls
72 lines (62 loc) · 2.27 KB
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
import os
from oled_code.mfss_helper import *
import scipy.optimize as spo
import sys
Nfeval = 0
def callbackF(Xi):
global Nfeval
Nfeval += 1
if Nfeval % 1 == 0:
rate_dict= {
"rec": Xi[0],
"kr": Xi[1],
"eea": Xi[2],
"eca": Xi[3],
"sigma": Xi[4],
"kbi": Xi[5],
"PLQY": Xi[6],
"brec": Xi[7]
}
rates = get_rates(rate_dict,jobtyp)
print(Nfeval,rate_dict,objective(rates,jobtyp,fit,x_min,x_max,disr,Vol,shift))
return
inputfile = sys.argv[1]
jobname,exptfile,jobtyp,disr,Vol,shift,rate_dict,plot_title,plot_label = parse_input(inputfile)
rates=get_rates(rate_dict,jobtyp)
expt_x, expt_y, x_min, x_max, fit = read_file(exptfile)
print(objective(rates,jobtyp,fit,x_min,x_max,disr,Vol,shift))
res = spo.minimize(objective,rates, args = (jobtyp,fit,x_min,x_max,disr,Vol,shift), method='Nelder-Mead',options={'disp': True}, callback=callbackF)
#res = spo.minimize(objective,rates, args = (typ,fit,xmin,xmax,disr,Vol,shift), method='Powell',options={'disp': True}, callback=callbackF)
#res = spo.minimize(objective,rates, args = (typ,fit,xmin,xmax,disr,Vol,shift), method='CG',jac=False,options={'disp': True}, callback=callbackF)
print(res.x)
filepathlist = exptfile.split('/')
eqefile = filepathlist.pop()
plqyfilename = eqefile.split('_')[0] + "_plqy.csv"
plqyfile = '/'.join(filepathlist)+'/'+plqyfilename
if disr == 1:
disr_str = 'eea'
elif disr == 3:
disr_str = 'eca'
output_dict = {'figname': jobname+"_optimized",
'datafile': [exptfile,plqyfile],
'type': jobtyp,
'disr': disr_str,
'Vol': Vol1,
'shift':shift,
'rate_dict':
{
"rec": res.x[0],
"kr": res.x[1],
"eea": res.x[2],
"eca": res.x[3],
"sigma": res.x[4],
"kbi": res.x[5],
"PLQY": res.x[6],
"brec": res.x[7]
},
'plot_title': plot_title,
'plot_label': plot_label
}
outputfile = inputfile.split('.')[0] + ".out"
with open(outputfile,'w') as jsonfile:
json.dump(output_dict,jsonfile)