-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfive_models.py
722 lines (624 loc) · 30.2 KB
/
five_models.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
from pyexpat import model
import tkinter as tk
from tkinter import *
from tkinter.font import Font
from scipy.optimize import minimize
from tkinter.ttk import *
from tkinter.messagebox import *
from routines import *
import numpy as np
import pandas as pd
# routine to display estimated parameters
def display():
# CHECK FOR NONE NULL MODELS, AND PRINT RESPECTIVE VALUES
computedModels = []
for model in modelMap:
param = modelMap[model]
if param:
computedModels.append(model)
if len(computedModels) == 0:
showinfo(title='Parameter Display', message='No parameters have been estimated')
else:
rootDisp = Toplevel(root)
rootDisp.title("Estimated Parameters")
for i in range(len(computedModels)):
model = computedModels[i]
labelParams = paramMap[model]
estimatedParams = modelMap[model]
estimatedMSE = mseMap[model]
paramString = ""
# CREATING THE STRING FOR PARAMETERS
for j in range(len(labelParams)):
# PARAMETER STRING = PARAMETER LABEL + PARAMETER VALUE
parameter = labelParams[j]
parameterValue = "{:.4e}".format(estimatedParams[j])
paramString += parameter + " : " + parameterValue + "\n"
# A LITTLE FORMATTING OF DATA
model = model + " "
# ADDING MSE TO ESTIMATED PARAMETERS
paramString += "MSE" + " : " + str(np.round_(estimatedMSE, decimals=4)) + "\n"
paramString = "\n" + paramString
# ADDING MODEL AND PARAMETERS FOR DISPLAY IN THE WINDOW
modelLabel = Label(rootDisp, text=model)
modelParams = Label(rootDisp, text=paramString)
modelLabel.grid(row=i, column=0, padx=25)
modelParams.grid(row=i, column=1, padx=25)
rootDisp.mainloop()
# routine to calculate ranks
def computeR(path):
rootR = Toplevel(root)
rootR.title("Techniques")
rootR.geometry("250x200")
var = IntVar()
def calculateRanks(path):
if var.get() == 1:
data = []
# CHECKING IF MODEL PARAMETERS ARE EVEN ENTERED BY THE USER OR NOT, IF THEY ARE THE DATA LIST IS POPULATED
# WITH MODEL ALONG WITH THE ESTIMATED PARAMETERS
for model in modelMap:
param = modelMap[model]
if param:
data.append([model, param]) # THE FIRST ARG ---> STRING, SECOND ARG ---> PARAMETERS
if len(data) < 2:
showerror(title='Cannot run TOPSIS', message="None or less models have been selected, TOPSIS requires atleast 2 models.")
else:
# GETTING THE DATA FROM DATASET IN ORDER TO CALCULATE PERFORMANCE CRITERIA
dataset = pd.read_csv(path)
X = np.arange(1, len(dataset.Time)+1)
Y = dataset['CDF']
# FOR CREATING ENTRIES IN data:
rootRank = Toplevel(root)
rootRank.title("Ranks")
rootRank.resizable(False, False)
modelRoutines = [
gomodel,
pnz,
delayedS,
yamadaImperfect2,
vtub
]
criteriaData = []
# VALIDATING THE DATABASE KEYS WITH MODEL NAMES
for selected in data:
criterias = []
for model in modelRoutines:
if selected[0] == model.name:
params = selected[1]
mse = model.mse(params, X, Y)
r2 = model.rsquare(params, X, Y)
aic = model.aic(params, X, Y)
bic = model.bic(params, X, Y)
pc = model.pc(params, X, Y)
criterias = [mse, r2, aic, bic, pc] # WHILE ADDING COLUMNS TO THE TREEVIEW MAKE SURE TO ENTER THE COLUMNS IN THIS ORDER OF CRITERIA ONLY
break
criterias.insert(0, selected[0])
criteriaData.append(criterias)
# CALCULATE TOPSIS OVER HERE--------------------------------
cdata = []
for modelData in criteriaData:
cdata.append(modelData[1:])
cdata = np.array(cdata)
n = cdata.shape[0] # number of models
m = cdata.shape[1] # number of criterias
# SO FAR SO GOOD
# CALCULATING THE WEIGHT MATRIX ----------------------------------------------
# normalizing the weight matrix
P = cdata / np.sum(cdata, axis=0)
# calculating the entropy vector
e = (-1) * np.sum(P * np.log(P), axis=0) / np.log(n)
# calculating the degree of diversification
d = 1-e
# calculating the weights
w = d / np.sum(d)
print('W', w)
# CALCULATED THE WEIGHT MATRIX -----------------------------------------------
# CALCULATING THE RANK -------------------------------------------------------
y = cdata / np.sqrt(np.sum(cdata**2, axis=0))
v = w * y
vpos = []
vneg = []
criteria_map = {
}
stringCriterias = ['mse', 'r2','aic', 'bic', 'pc']
for i in range(len(stringCriterias)):
cr = stringCriterias[i]
criteria_map[cr] = v[:, i]
maximizer = ['r2']
minimizer = ['mse', 'aic', 'bic', 'pc']
for criteria in criteria_map:
if criteria in maximizer:
best = np.amax(criteria_map[criteria])
worst = np.amin(criteria_map[criteria])
vpos.append(best)
vneg.append(worst)
if criteria in minimizer:
best = np.amin(criteria_map[criteria])
worst = np.amax(criteria_map[criteria])
vpos.append(best)
vneg.append(worst)
# converting ideal best and ideal worst data to usable form
vpos = np.array(vpos)
vneg = np.array(vneg)
spos = np.sqrt(np.sum( (v-vpos)**2 , axis=1))
sneg = np.sqrt(np.sum( (v-vneg)**2 , axis=1))
print('S+', spos)
print('S-',sneg)
# final relative closeness results
c = sneg / (spos + sneg)
print('C', c)
# ranking the models
ranked = {}
rankArr = [0 for _ in range(n)] # CHANGED HERE
initialRank = 1
for _ in range(n):
# populating rank list
index = np.argmax(c)
ranked[index] = initialRank
# discarding the considered index
c[index] = -1
initialRank += 1
for i in range(n):
rankArr[i] = ranked[i]
rankArr = [[i] for i in rankArr] # CHANGED HERE
# CALCULATED THE RANKS -----------------------------------------------
modelsWithRank = []
for i in range(len(rankArr)):
row = [data[i][0], rankArr[i][0]]
modelsWithRank.append(row)
print(modelsWithRank)
print(w)
#-----------------------------------------------------------
# ADDING TO TABLE
columns = ('models', 'rank')
columnsText = ('Models', 'Rank')
tree = Treeview(rootRank, columns=columns, show='headings')
for i in range(len(columns)):
tree.heading(columns[i], text=columnsText[i])
tree.column(columns[i], anchor=CENTER)
for i in modelsWithRank:
# ADDING TO THE TREE VIEW
tree.insert('', END, values=tuple(i))
tree.grid(row=0, column=0)
rootRank.mainloop()
else:
showinfo(title="Technique Missing", message="Please select a technique to rank the models")
r1 = Radiobutton(rootR, text='Entropy & TOPSIS', variable=var, value=1)
submitButton = Button(rootR, text='Submit', command=lambda: calculateRanks(path))
closeButton = Button(rootR, text="Close", command=rootR.destroy)
r1.place(relx=0.25, rely=0.15)
submitButton.place(relx=0.35, rely=0.3, relwidth=0.25, relheight=0.2)
closeButton.place(relx=0.35, rely=0.5, relwidth=0.25, relheight=0.2)
rootR.mainloop()
# rountine to calculate criteria
def computeC(path):
data = []
# CHECKING IF MODEL PARAMETERS ARE EVEN ENTERED BY THE USER OR NOT, IF THEY ARE THE DATA LIST IS POPULATED
# WITH MODEL ALONG WITH THE ESTIMATED PARAMETERS
for model in modelMap:
param = modelMap[model]
if param:
data.append([model, param]) # THE FIRST ARG ---> STRING, SECOND ARG ---> PARAMETERS
if len(data) < 1:
showerror(title='No models selected', message="None or less models have been selected, select atleast 1 model to view the criterias.")
else:
# GETTING THE DATA FROM DATASET IN ORDER TO CALCULATE PERFORMANCE CRITERIA
dataset = pd.read_csv(path)
X = np.arange(1, len(dataset.Time)+1)
Y = dataset['CDF']
# FOR CREATING ENTRIES IN data:
rootCriteria = Toplevel(root)
rootCriteria.title("Criteria Results")
rootCriteria.geometry("700x300")
rootCriteria.resizable(False, False)
modelRoutines = [
gomodel,
pnz,
delayedS,
yamadaImperfect2,
vtub
]
criteriaData = []
# VALIDATING THE DATABASE KEYS WITH MODEL NAMES
for selected in data:
criterias = []
for model in modelRoutines:
if selected[0] == model.name:
params = selected[1]
mse = model.mse(params, X, Y)
r2 = model.rsquare(params, X, Y) # IF ANY PROBLEM OCCURS IT IS IN PP, AIC, MEOP or TS
aic = model.aic(params, X, Y)
bic = model.bic(params, X, Y)
pc = model.pc(params, X, Y)
criterias = [mse, r2, aic, bic, pc] # WHILE ADDING COLUMNS TO THE TREEVIEW MAKE SURE TO ENTER THE COLUMNS IN THIS ORDER OF CRITERIA ONLY
break
criterias.insert(0, selected[0])
criteriaData.append(criterias)
# ADDING TO TABLE
columns = ('models', 'mse', 'rsquare', 'aic', 'bic', 'pc')
columnsText = ('Models', 'MSE', 'R\u00b2', 'AIC', 'BIC', 'PC')
tree = Treeview(rootCriteria, columns=columns, show='headings')
for i in range(len(columns)):
if i == 0:
tree.heading(columns[i], text=columnsText[i], anchor=CENTER)
tree.column(columns[i], minwidth=145, width=145, anchor=CENTER)
else:
tree.heading(columns[i], text=columnsText[i], anchor=CENTER)
tree.column(columns[i], minwidth=110, width=110, anchor=CENTER)
for i in criteriaData:
# SHORTENING THE NUMBERS TILL 5 DECIMAL PLACES
model = i[0]
temp = [np.round_(j, decimals=5) for j in i[1:]]
temp.insert(0, model)
# ADDING TO THE TREE VIEW
tree.insert('', END, values=tuple(temp))
tree.place(relx=0, rely=0)
# RANK BUTTON
rankButton = Button(rootCriteria, text="Click to calculate rank of models", command=lambda: computeR(path))
rankButton.place(relx=0.375, rely=0.775, relwidth=0.25, relheight=0.2)
rootCriteria.mainloop()
# main function to access the mainframe of the dss
def main():
global root
root = Tk()
root.title("SRGM DSS")
root.geometry("1240x500")
myFont = Font(weight="bold")
# some variables that are required
path = StringVar()
loaded = BooleanVar()
# hashmaps for essential data
global paramMap, modelMap, mseMap
modelMap = {
'GO model': None,
'Delayed S-Shaped model': None,
'Inflection S-Shaped model': None,
'PNZ model': None,
'Yamada Imperfect 1 model': None,
'Vtub-Shaped model': None,
'Yamada Imperfect 2 model': None,
'RMD model`': None,
'Yamada Exponential model': None,
'Chang et al\'s model': None
}
mseMap = {
'GO model': np.inf,
'Delayed S-Shaped model': np.inf,
'Inflection S-Shaped model': np.inf,
'PNZ model': np.inf,
'Yamada Imperfect 1 model': np.inf,
'Yamada Imperfect 2 model': np.inf,
'Yamada Exponential model': np.inf,
'Vtub-Shaped model': np.inf,
'RMD model': np.inf,
'Chang et al\'s model': np.inf
}
paramMap = {
'GO model': ['a', 'b'], # a, b
'Delayed S-Shaped model': ['a', 'b'], # a, b
'Inflection S-Shaped model': ['a', 'b', '\u03B2'], # a, b, beta
'PNZ model': ['a', 'b', '\u03B1', '\u03B2'], # a, b, alpha, beta
'Yamada Imperfect 1 model': ['a', 'b', '\u03B1'], # a, b, alpha
'Yamada Imperfect 2 model': ['a', 'b', '\u03B1'], # a, b, alpha
'Yamada Exponential model': ['a', '\u03B1', '\u03B2', '\u03B3'], # a, alpha, beta, gamma
'Vtub-Shaped model': ['a', 'b', '\u03B1', '\u03B2', 'N'], # a, b, alpha, beta, N
'RMD model': ['a', 'b', '\u03B1', '\u03B2'], # a, b, alpha, beta
'Chang et al\'s model':['a', 'b', '\u03B1', '\u03B2', 'N'] # a, b, alpha, beta, N
}
# subroutine to view the datase
def viewDataset(stringvar):
data = pd.read_csv(stringvar.get())
# defining the treeview
tree = Treeview(root, show='headings')
# define columns
tree['columns'] = ('time', 'cdf')
tree.column('time', anchor=CENTER)
tree.column('cdf', anchor=CENTER)
# define headings
tree.heading('time', text='Time', anchor=CENTER)
tree.heading('cdf', text='CDF', anchor=CENTER)
# add data to the treeview
for i in range(len(data)):
tree.insert('', END, values=(data.loc[i].Time, data.loc[i].CDF))
# placing the tree on the canvas and removing the
# surrogate dataset canvas
tree.place(relx=0.65, rely=0.45)
datasetCanvas.destroy()
# subroutine to load the dataset
def loadDataset(path, stringvar, loaded):
try:
data = pd.read_csv(path)
stringvar.set(path)
loaded.set(True)
viewDataset(stringvar)
showinfo(title='Load successful', message='The dataset has been loaded successfuly.')
except FileNotFoundError or PermissionError:
return showerror(title="Incorrect path", message='The path entered does not exist. Please make sure to enter correct path.')
# below subroutines are written to estimate the parameters of the models
# go model param estimation
def goModelParamEst(modelObject, stringvar):
rootPar = Toplevel(root)
rootPar.title("GO Model Initial Parameters")
rootPar.geometry("350x175")
# getting the fitting data
data = pd.read_csv(stringvar.get())
X, Y = data.Time, data.CDF
def _sub():
arrToOptimize = [
float(param1.get()),
float(param2.get())
]
minimizationResults = minimize(fun=modelObject.OLS, x0=arrToOptimize, args=(X, Y), method='Nelder-Mead')
estimatesdParams = list(minimizationResults.x)
mse = np.round_(modelObject.mse(estimatesdParams, X, Y), decimals=4)
# saving data
mseMap[modelObject.name] = mse
modelMap[modelObject.name] = list(minimizationResults.x)
rootPar.destroy()
def _removeModel():
try:
modelMap[modelObject.name] = None
rootPar.destroy()
showinfo(title='Model Removal', message="Model has been successfuly removed")
except:
showinfo(title='Model Removal', message="Error occured while removing model")
param1Label = Label(rootPar, text="a (cummulative faults)")
param2Label = Label(rootPar, text="b (detection rate)")
param1 = Entry(rootPar, width=30) # THIS IS PARAMETER 'a' FOR GO MODEL
param2 = Entry(rootPar, width=30) # THIS IS PARAMETER 'b' FOR GO MODEL
submitAndEstimate = Button(rootPar, text="Submit", command=_sub)
removeModel = Button(rootPar, text="Remove", command=_removeModel)
# LABELS PLACING
param1Label.place(relx=0, rely=0)
param2Label.place(relx=0, rely=0.15)
# ENTRY PLACING
param1.place(relx=0.4, rely=0)
param2.place(relx=0.4, rely=0.15)
submitAndEstimate.place(relx=0.3, rely=0.5, relwidth=0.35, relheight=0.2)
removeModel.place(relx=0.3, rely=0.7, relwidth=0.35, relheight=0.2)
rootPar.mainloop()
# delayed s model param estimator
def delayedSParamEst(modelObject, stringvar):
rootPar = Toplevel(root)
rootPar.title("Delayed S Shaped Model Initial Parameters")
rootPar.geometry("400x175")
# getting the fitting data
data = pd.read_csv(stringvar.get())
X, Y = data.Time, data.CDF
def _sub():
arrToOptimize = [
float(param1.get()),
float(param2.get())
]
minimizationResults = minimize(fun=modelObject.OLS, x0=arrToOptimize, args=(X, Y), method='Nelder-Mead')
estimatesdParams = list(minimizationResults.x)
mse = np.round_(modelObject.mse(estimatesdParams, X, Y), decimals=4)
# saving data
mseMap[modelObject.name] = mse
modelMap[modelObject.name] = list(minimizationResults.x)
rootPar.destroy()
rootPar.destroy()
def _removeModel():
try:
modelMap[modelObject.name] = None
rootPar.destroy()
showinfo(title='Model Removal', message="Model has been successfuly removed")
except:
showinfo(title='Model Removal', message="Error occured while removing model")
param1Label = Label(rootPar, text="a (cummulative faults)")
param2Label = Label(rootPar, text="b (detection rate)")
param1 = Entry(rootPar, width=35) # THIS IS PARAMETER 'a' FOR DELAYED S MODEL
param2 = Entry(rootPar, width=35) # THIS IS PARAMETER 'b' FOR DELAYED S MODEL
submitAndEstimate = Button(rootPar, text="Submit", command=_sub)
removeModel = Button(rootPar, text="Remove", command=_removeModel)
# LABELS PLACING
param1Label.place(relx=0, rely=0)
param2Label.place(relx=0, rely=0.15)
# ENTRY PLACING
param1.place(relx=0.4, rely=0)
param2.place(relx=0.4, rely=0.15)
submitAndEstimate.place(relx=0.3, rely=0.5, relwidth=0.35, relheight=0.2)
removeModel.place(relx=0.3, rely=0.7, relwidth=0.35, relheight=0.2)
rootPar.mainloop()
# pnz model param est
def pnzParamEst(modelObject, stringvar):
rootPar = Toplevel(root)
rootPar.title("PNZ Model Initial Parameters")
rootPar.geometry("400x250")
# getting the fitting data
data = pd.read_csv(stringvar.get())
X, Y = data.Time, data.CDF
def _sub():
arrToOptimize = [
float(param1.get()),
float(param2.get()),
float(param3.get()),
float(param4.get())
]
minimizationResults = minimize(fun=modelObject.OLS, x0=arrToOptimize, args=(X, Y), method='Nelder-Mead')
estimatesdParams = list(minimizationResults.x)
mse = np.round_(modelObject.mse(estimatesdParams, X, Y), decimals=4)
# saving data
mseMap[modelObject.name] = mse
modelMap[modelObject.name] = list(minimizationResults.x)
rootPar.destroy()
def _removeModel():
try:
mseMap[modelObject.name] = np.inf
modelMap[modelObject.name] = None
rootPar.destroy()
showinfo(title='Model Removal', message="Model has been successfuly removed")
except:
showinfo(title='Model Removal', message="Error occured while removing model")
param1Label = Label(rootPar, text="a (cummulative faults)") # THIS IS PARAMETER 'a' FOR YAMADA RAYLEIGH MODEL
param2Label = Label(rootPar, text="b (detection rate)") # THIS IS PARAMETER 'alpha' FOR YAMADA RAYLEIGH MODEL
param3Label = Label(rootPar, text="\u03B1 (total expenditure)") # THIS IS PARAMETER 'beta' FOR YAMADA RAYLEIGH MODEL
param4Label = Label(rootPar, text="\u03B2 (scale parameter)") # THIS IS PARAMETER 'gamma' FOR YAMADA RAYLEIGH MODEL
param1 = Entry(rootPar, width=35)
param2 = Entry(rootPar, width=35)
param3 = Entry(rootPar, width=35)
param4 = Entry(rootPar, width=35)
submitAndEstimate = Button(rootPar, text="Submit", command=_sub)
removeModel = Button(rootPar, text="Remove", command=_removeModel)
# LABELS PLACING
param1Label.place(relx=0, rely=0)
param2Label.place(relx=0, rely=0.1)
param3Label.place(relx=0, rely=0.2)
param4Label.place(relx=0, rely=0.3)
# ENTRY PLACING
param1.place(relx=0.4, rely=0)
param2.place(relx=0.4, rely=0.1)
param3.place(relx=0.4, rely=0.2)
param4.place(relx=0.4, rely=0.3)
submitAndEstimate.place(relx=0.3, rely=0.50, relwidth=0.35, relheight=0.2)
removeModel.place(relx=0.3, rely=0.70, relwidth=0.35, relheight=0.2)
rootPar.mainloop()
# pnz model param est
def yamadaImperfect2ParamEst(modelObject, stringvar):
rootPar = Toplevel(root)
rootPar.title("Yamada Imperfect2 Model Initial Parameters")
rootPar.geometry("400x200")
# getting the fitting data
data = pd.read_csv(stringvar.get())
X, Y = data.Time, data.CDF
def _sub():
arrToOptimize = [
float(param1.get()),
float(param2.get()),
float(param3.get())
]
minimizationResults = minimize(fun=modelObject.OLS, x0=arrToOptimize, args=(X, Y), method='Nelder-Mead')
estimatesdParams = list(minimizationResults.x)
mse = np.round_(modelObject.mse(estimatesdParams, X, Y), decimals=4)
# saving data
mseMap[modelObject.name] = mse
modelMap[modelObject.name] = list(minimizationResults.x)
rootPar.destroy()
def _removeModel():
try:
mseMap[modelObject.name] = np.inf
modelMap[modelObject.name] = None
rootPar.destroy()
showinfo(title='Model Removal', message="Model has been successfuly removed")
except:
showinfo(title='Model Removal', message="Error occured while removing model")
param1Label = Label(rootPar, text="a (cummulative faults)") # THIS IS PARAMETER 'a' FOR YAMADA IMPERFECT 1 MODEL
param2Label = Label(rootPar, text="b (detection rate)") # THIS IS PARAMETER 'b' FOR YAMADA IMPERFECT 1 MODEL
param3Label = Label(rootPar, text="\u03B1 (total expenditure)") # THIS IS PARAMETER 'alpha' FOR YAMADA IMPERFECT 1 MODEL
param1 = Entry(rootPar, width=35)
param2 = Entry(rootPar, width=35)
param3 = Entry(rootPar, width=35)
submitAndEstimate = Button(rootPar, text="Submit", command=_sub)
removeModel = Button(rootPar, text="Remove", command=_removeModel)
# LABELS PLACING
param1Label.place(relx=0, rely=0)
param2Label.place(relx=0, rely=0.125)
param3Label.place(relx=0, rely=0.25)
# ENTRY PLACING
param1.place(relx=0.4, rely=0)
param2.place(relx=0.4, rely=0.125)
param3.place(relx=0.4, rely=0.25)
submitAndEstimate.place(relx=0.3, rely=0.50, relwidth=0.35, relheight=0.2)
removeModel.place(relx=0.3, rely=0.70, relwidth=0.35, relheight=0.2)
rootPar.mainloop()
# vtub model param est
def vtubParamEst(modelObject, stringvar):
rootPar = Toplevel(root)
rootPar.title("VTub Model Initial Parameters")
rootPar.geometry("400x275")
# getting the fitting data
data = pd.read_csv(stringvar.get())
X, Y = data.Time, data.CDF
def _sub():
arrToOptimize = [
float(param1.get()),
float(param2.get()),
float(param3.get()),
float(param4.get()),
float(param5.get())
]
minimizationResults = minimize(fun=modelObject.OLS, x0=arrToOptimize, args=(X, Y), method='Nelder-Mead')
estimatesdParams = list(minimizationResults.x)
mse = np.round_(modelObject.mse(estimatesdParams, X, Y), decimals=4)
# saving data
mseMap[modelObject.name] = mse
modelMap[modelObject.name] = list(minimizationResults.x)
rootPar.destroy()
def _removeModel():
try:
mseMap[modelObject.name] = np.inf
modelMap[modelObject.name] = None
rootPar.destroy()
showinfo(title='Model Removal', message="Model has been successfuly removed")
except:
showinfo(title='Model Removal', message="Error occured while removing model")
param1Label = Label(rootPar, text="a (cummulative faults)") # THIS IS PARAMETER 'a' FOR YAMADA RAYLEIGH MODEL
param2Label = Label(rootPar, text="b (detection rate)") # THIS IS PARAMETER 'b' FOR YAMADA RAYLEIGH MODEL
param3Label = Label(rootPar, text="\u03B1 (total expenditure)") # THIS IS PARAMETER 'alpha' FOR YAMADA RAYLEIGH MODEL
param4Label = Label(rootPar, text="\u03B2 (scale parameter)") # THIS IS PARAMETER 'beta' FOR YAMADA RAYLEIGH MODEL
param5label = Label(rootPar, text="n") # THIS IS PARAMETER 'n' FOR YAMADA RAYLEIGH MODEL
param1 = Entry(rootPar, width=35)
param2 = Entry(rootPar, width=35)
param3 = Entry(rootPar, width=35)
param4 = Entry(rootPar, width=35)
param5 = Entry(rootPar, width=35)
submitAndEstimate = Button(rootPar, text="Submit", command=_sub)
removeModel = Button(rootPar, text="Remove", command=_removeModel)
# LABELS PLACING
param1Label.place(relx=0, rely=0)
param2Label.place(relx=0, rely=0.09)
param3Label.place(relx=0, rely=0.18)
param4Label.place(relx=0, rely=0.27)
param5label.place(relx=0, rely=0.36)
# ENTRY PLACING
param1.place(relx=0.4, rely=0)
param2.place(relx=0.4, rely=0.09)
param3.place(relx=0.4, rely=0.18)
param4.place(relx=0.4, rely=0.27)
param5.place(relx=0.4, rely=0.36)
submitAndEstimate.place(relx=0.3, rely=0.50, relwidth=0.35, relheight=0.2)
removeModel.place(relx=0.3, rely=0.7, relwidth=0.35, relheight=0.2)
rootPar.mainloop()
# computation buttons
computeLabel = Label(root, text='Computation Processes')
estParamsButton = Button(root, text='Estimated Parameters', command=display)
criteriaButton = Button(root, text='Calculate Criteria', command=lambda: computeC(path.get()))
rankButton = Button(root, text='Calculate Ranks', command=lambda: computeR(path.get()))
# model buttons
modelsLabel = Label(root, text='Model Selection')
model1 = Button(root, text='GO model', command=lambda: goModelParamEst(gomodel, path))
model2 = Button(root, text='PNZ model', command=lambda: pnzParamEst(pnz, path))
model3 = Button(root, text='Yamada Imperfect 2 model', command=lambda: yamadaImperfect2ParamEst(yamadaImperfect2, path))
model4 = Button(root, text='Delayed S-Shaped model', command=lambda: delayedSParamEst(delayedS, path))
model5 = Button(root, text='V-tub Shaped model', command=lambda: vtubParamEst(vtub, path))
# dataset elements
datasetLabel = Label(root, text='Dataset Handling')
pathEntryLabel = Label(root, text="Enter path of dataset")
pathEntry = Entry(root, width=22)
loadButton = Button(root, text='Load Dataset', command=lambda: loadDataset(pathEntry.get(), path, loaded))
# dataset canvas
datasetCanvas = Canvas(root, width=400, height=225, bg='#ffdac9')
datasetMessage = tk.Label(datasetCanvas, text='Dataset Not Loaded.', bg='#ffdac9').place(relx=0.5, rely=0.5, anchor=CENTER)
# placing compute labels
computeLabel.place(relx=0.1, rely=0.1)
modelsLabel.place(relx=0.45, rely=0.1)
datasetLabel.place(relx=0.75, rely=0.1)
# placing model buttons
model1.place(relx= 0.37, rely=0.17, relwidth=0.25, relheight=0.1)
model2.place(relx= 0.37, rely=0.27, relwidth=0.25, relheight=0.1)
model3.place(relx= 0.37, rely=0.37, relwidth=0.25, relheight=0.1)
model4.place(relx= 0.37, rely=0.47, relwidth=0.25, relheight=0.1)
model5.place(relx= 0.37, rely=0.57, relwidth=0.25, relheight=0.1)
# placing compute buttons
estParamsButton.place(relx=0.03, rely=0.17, relwidth=0.25, relheight=0.1)
criteriaButton.place(relx=0.03, rely=0.27, relwidth=0.25, relheight=0.1)
rankButton.place(relx=0.03, rely=0.37 , relwidth=0.25, relheight=0.1)
# placing dataset entry and butons dataset window
(
pathEntryLabel.place(relx=0.7, rely=0.2),
pathEntry.place(relx=0.8, rely=0.2),
loadButton.place(relx=0.7, rely=0.3, relwidth=0.25, relheight=0.1)
)
# placing the surrogate canvas for the dataset
datasetCanvas.place(relx=0.65, rely=0.45)
root.mainloop()
main()