File qt_plot.py changed (mode: 100644) (index b4fcacb..e7f80b7) |
... |
... |
class QtGuiPlot2D: |
127 |
127 |
self.w.tabifyDockWidget(self.dockables[0], dock) |
self.w.tabifyDockWidget(self.dockables[0], dock) |
128 |
128 |
|
|
129 |
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
dock = dock_r = QtGui.QDockWidget("Simplex-based pf estimation", self.w) |
|
133 |
|
dock.setWidget(SimplexEstimationWidget(self, dock)) |
|
134 |
|
self.dockables.append(dock) |
|
135 |
|
self.w.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock) |
|
136 |
|
|
|
137 |
|
|
|
138 |
|
dock = QtGui.QDockWidget("Tesselation-based pf estimation", self.w) |
|
139 |
|
dock.setWidget(VoronoiEstimationWidget(self, dock)) |
|
140 |
|
self.dockables.append(dock) |
|
141 |
|
self.w.tabifyDockWidget(dock_r, dock) |
|
142 |
|
|
|
143 |
|
|
|
144 |
|
# graphy musí jít po těch stm widgetech - ať nejdřív zpracujou odhady |
130 |
145 |
dock = QtGui.QDockWidget("TRI_current estimation graph", self.w) |
dock = QtGui.QDockWidget("TRI_current estimation graph", self.w) |
131 |
146 |
dock.setWidget(TriEstimationGraph(self.sample_box, tri_estimation_name='TRI_current_estimations')) |
dock.setWidget(TriEstimationGraph(self.sample_box, tri_estimation_name='TRI_current_estimations')) |
132 |
147 |
self.dockables.append(dock) |
self.dockables.append(dock) |
|
... |
... |
class QtGuiPlot2D: |
137 |
152 |
self.dockables.append(dock) |
self.dockables.append(dock) |
138 |
153 |
self.w.tabifyDockWidget(self.dockables[0], dock) |
self.w.tabifyDockWidget(self.dockables[0], dock) |
139 |
154 |
|
|
140 |
|
dock = QtGui.QDockWidget("Voronoi estimation graph", self.w) |
|
141 |
|
dock.setWidget(VoronoiEstimationGraph(self.sample_box, dock)) |
|
|
155 |
|
dock = QtGui.QDockWidget("Simplex estimation graph", self.w) |
|
156 |
|
dock.setWidget(SimpleSimplexEstimationGraph(self.sample_box, dock)) |
142 |
157 |
self.dockables.append(dock) |
self.dockables.append(dock) |
143 |
158 |
self.w.tabifyDockWidget(self.dockables[0], dock) |
self.w.tabifyDockWidget(self.dockables[0], dock) |
144 |
159 |
|
|
145 |
160 |
|
|
146 |
|
|
|
147 |
|
dock = dock_r = QtGui.QDockWidget("Simplex-based pf estimation", self.w) |
|
148 |
|
dock.setWidget(SimplexEstimationWidget(self, dock)) |
|
149 |
|
self.dockables.append(dock) |
|
150 |
|
self.w.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock) |
|
151 |
|
|
|
152 |
|
|
|
153 |
|
dock = QtGui.QDockWidget("Tesselation-based pf estimation", self.w) |
|
154 |
|
dock.setWidget(VoronoiEstimationWidget(self, dock)) |
|
|
161 |
|
dock = QtGui.QDockWidget("Voronoi estimation graph", self.w) |
|
162 |
|
dock.setWidget(VoronoiEstimationGraph(self.sample_box, dock)) |
155 |
163 |
self.dockables.append(dock) |
self.dockables.append(dock) |
156 |
|
self.w.tabifyDockWidget(dock_r, dock) |
|
157 |
|
|
|
158 |
|
|
|
|
164 |
|
self.w.tabifyDockWidget(self.dockables[0], dock) |
159 |
165 |
|
|
160 |
166 |
|
|
161 |
167 |
for dock in self.dockables: |
for dock in self.dockables: |
|
... |
... |
class QtGuiPlot2D: |
217 |
223 |
self.slice_plot_data() |
self.slice_plot_data() |
218 |
224 |
|
|
219 |
225 |
def run_sb(self): |
def run_sb(self): |
220 |
|
sample = self.sample_box() |
|
221 |
|
|
|
222 |
|
# slider |
|
223 |
|
self.slider.setMaximum(self.sample_box.nsim) |
|
224 |
|
self.slider.setValue(self.sample_box.nsim) |
|
225 |
|
|
|
226 |
|
self.slice_plot_data(sample) |
|
227 |
|
#self.sb_runned.emit() |
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
|
# zatím tak |
|
232 |
|
for dock in self.dockables: |
|
233 |
|
try: |
|
234 |
|
dock.widget().redraw() |
|
235 |
|
except AttributeError: |
|
236 |
|
pass |
|
237 |
|
#dock.setFloating(True) |
|
|
226 |
|
with pg.BusyCursor(): |
|
227 |
|
sample = self.sample_box() |
|
228 |
|
|
|
229 |
|
# slider |
|
230 |
|
self.slider.setMaximum(self.sample_box.nsim) |
|
231 |
|
self.slider.setValue(self.sample_box.nsim) |
|
232 |
|
|
|
233 |
|
self.slice_plot_data(sample) |
|
234 |
|
#self.sb_runned.emit() |
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
|
238 |
|
# zatím tak |
|
239 |
|
for dock in self.dockables: |
|
240 |
|
try: |
|
241 |
|
dock.widget().redraw() |
|
242 |
|
except AttributeError: |
|
243 |
|
pass |
|
244 |
|
#dock.setFloating(True) |
238 |
245 |
|
|
239 |
246 |
def plot_widget_2d(self): |
def plot_widget_2d(self): |
240 |
247 |
self.plotWidget.clear() |
self.plotWidget.clear() |
|
... |
... |
class QtGuiPlot2D: |
350 |
357 |
#print("Медам сюреда!") |
#print("Медам сюреда!") |
351 |
358 |
for plot_item in self.triangulation: |
for plot_item in self.triangulation: |
352 |
359 |
plot_item.hide() |
plot_item.hide() |
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
|
|
|
364 |
|
""" |
|
365 |
|
============= |
|
366 |
|
График виӝет |
|
367 |
|
Grafy |
|
368 |
|
Estimation graph widgets |
|
369 |
|
======================== |
|
370 |
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
371 |
|
""" |
353 |
372 |
|
|
354 |
373 |
|
|
355 |
374 |
|
|
|
... |
... |
class TriEstimationGraph(pg.PlotWidget): |
407 |
426 |
|
|
408 |
427 |
|
|
409 |
428 |
|
|
410 |
|
class SimpleSimplexEstimationGraph(pg.LayoutWidget): |
|
411 |
|
def __init__(self, black_box, tri_estimation_name='TRI_current_estimations', parent=None, *args, **kwargs): |
|
|
429 |
|
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
|
430 |
|
def __init__(self, black_box, parent=None, *args, **kwargs): |
412 |
431 |
super().__init__(parent) |
super().__init__(parent) |
413 |
432 |
|
|
414 |
433 |
self.black_box = black_box |
self.black_box = black_box |
415 |
|
self.tri_estimation_name = tri_estimation_name |
|
|
434 |
|
|
|
435 |
|
|
|
436 |
|
self.log_x_chk = QtGui.QAction("Log X") |
|
437 |
|
self.log_x_chk.setCheckable(True) |
|
438 |
|
self.log_y_chk = QtGui.QAction("Log Y") |
|
439 |
|
self.log_y_chk.setCheckable(True) |
|
440 |
|
# setLogMode(self, x=None, y=None) |
|
441 |
|
self.log_x_chk.triggered.connect(lambda: self.setLogMode(x=self.log_x_chk.isChecked())) |
|
442 |
|
self.log_y_chk.triggered.connect(self.setup) |
|
443 |
|
|
|
444 |
|
self.reaction = QtGui.QAction("Redraw") |
|
445 |
|
self.reaction.triggered.connect(self.redraw) |
|
446 |
|
|
|
447 |
|
#pw.plotItem.ctrlMenu.actions() |
|
448 |
|
self.plotItem.ctrlMenu.removeAction(self.plotItem.ctrlMenu.actions()[0]) |
|
449 |
|
|
|
450 |
|
self.plotItem.ctrlMenu.insertAction(self.plotItem.ctrlMenu.actions()[0], self.log_y_chk) |
|
451 |
|
self.plotItem.ctrlMenu.insertAction(self.plotItem.ctrlMenu.actions()[0], self.log_x_chk) |
|
452 |
|
self.plotItem.ctrlMenu.insertAction(self.plotItem.ctrlMenu.actions()[0], self.reaction) |
|
453 |
|
|
|
454 |
|
|
|
455 |
|
self.setup() |
|
456 |
|
|
|
457 |
|
|
|
458 |
|
def setup(self, *args, **kwargs): |
|
459 |
|
self.clear() |
416 |
460 |
self.setBackground('w') |
self.setBackground('w') |
417 |
461 |
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
418 |
462 |
|
|
419 |
|
#self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
|
420 |
|
pen = pg.mkPen(color=(255, 0, 0), width=3)#, style=QtCore.Qt.DashLine) |
|
421 |
|
self.pen_f = self.plot(x, y, pen=pen) # red |
|
422 |
|
self.pen_mix = self.plot(x, y, fillLevel=0, brush=(255, 165, 0)) # orange |
|
423 |
|
self.pen_outside = self.plot(x, y, fillLevel=0, brush=0.8) # grey |
|
424 |
|
self.pen_success = self.plot(x, y, fillLevel=0, brush='g') # green |
|
425 |
|
self.pen_exact = self.plot(x, y, pen='b') # blue |
|
|
463 |
|
if self.log_y_chk.isChecked(): |
|
464 |
|
self.setLogMode(y=True) |
|
465 |
|
#self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
|
466 |
|
pen = pg.mkPen(color=(255, 0, 0), width=3)#, style=QtCore.Qt.DashLine) |
|
467 |
|
self.pen_f = self.plot(x, y, pen=pen) # red |
|
468 |
|
self.pen_mix = self.plot(x, y, fillLevel=0, brush=(255, 165, 0)) # orange |
|
469 |
|
self.pen_outside = self.plot(x, y, fillLevel=0, brush=0.8) # grey |
|
470 |
|
self.pen_success = self.plot(x, y, fillLevel=0, brush='g') # green |
|
471 |
|
self.pen_exact = self.plot(x, y, pen='b') # blue |
|
472 |
|
|
|
473 |
|
|
|
474 |
|
else: |
|
475 |
|
self.setLogMode(y=False) |
|
476 |
|
self.pen_success = self.plot(x, y, fillLevel=0, brush='g') # green |
|
477 |
|
self.pen_outside = self.plot(x, y, fillLevel=0, brush=0.8) # grey |
|
478 |
|
self.pen_mix = self.plot(x, y, fillLevel=0, brush=(255, 165, 0)) # orange |
|
479 |
|
self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
|
480 |
|
self.pen_exact = self.plot(x, y, pen='b') # blue |
426 |
481 |
|
|
427 |
|
self.setLogMode(False, True) |
|
428 |
482 |
|
|
429 |
483 |
self.redraw() |
self.redraw() |
430 |
484 |
|
|
431 |
485 |
|
|
432 |
486 |
def redraw(self): |
def redraw(self): |
|
487 |
|
xmin = np.inf |
|
488 |
|
xmax = -np.inf |
|
489 |
|
tri_estimation = dict() |
433 |
490 |
try: # тут всё что угодно может пойти не так |
try: # тут всё что угодно может пойти не так |
434 |
|
data = self.black_box.guessbox.estimations[self.tri_estimation_name] |
|
435 |
|
x = data[0] |
|
|
491 |
|
# kruci, ještě navic i generovať pokažde znovu... |
|
492 |
|
|
|
493 |
|
# new-style: šecko leží dohromady a každý si z toho |
|
494 |
|
# bere co chce a jak chce |
|
495 |
|
# ne že by to bylo nějak šetrný |
|
496 |
|
# estimation je slovníkem |
|
497 |
|
for estimation in self.black_box.estimations: |
|
498 |
|
# nsim musí mäť každej odhad |
|
499 |
|
# pokud nemá - je třeba jej prostě opravit |
|
500 |
|
nsim = estimation['nsim'] |
|
501 |
|
try: |
|
502 |
|
tri_estimation[nsim] = estimation['TRI_estimation'] |
|
503 |
|
if nsim > xmax: |
|
504 |
|
xmax = nsim |
|
505 |
|
if nsim < xmin: |
|
506 |
|
xmin = nsim |
|
507 |
|
except KeyError as e: |
|
508 |
|
pass #print(self.__class__.__name__ + ":", repr(e)) |
|
509 |
|
|
|
510 |
|
|
436 |
511 |
# it can be effectively done with pandas |
# it can be effectively done with pandas |
437 |
|
df = pd.DataFrame(data[1]) |
|
|
512 |
|
df = pd.DataFrame(tuple(tri_estimation.values())) |
438 |
513 |
# -1 = 'out', 0=success, 1=failure, 2=mix |
# -1 = 'out', 0=success, 1=failure, 2=mix |
439 |
514 |
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
440 |
|
|
|
441 |
|
# Update the data |
|
442 |
|
# když se někde objeví nula se zapnutým LogModem - qtpygraph hned spadne a není možne ten pad zachytit |
|
443 |
|
def nonzero(data): return np.where(data > 0, data, 1) |
|
444 |
|
self.pen_f.setData(np.array(x)[df.failure.to_numpy() > 0], df.failure.to_numpy()[df.failure.to_numpy() > 0]) |
|
445 |
|
self.pen_mix.setData(x, nonzero(df.failure)) |
|
446 |
|
self.pen_outside.setData(x, nonzero(df.failure+df.mix)) |
|
447 |
|
self.pen_success.setData(x, nonzero(df.failure+df.mix+df.out)) # kontrolu, zda je to 1, nechame uživateli |
|
|
515 |
|
df.insert(loc=0, column='x', value=tuple(tri_estimation.keys()), allow_duplicates=False) |
|
516 |
|
df.sort_values('x', inplace=True) |
|
517 |
|
x = df.x.to_numpy() |
448 |
518 |
|
|
449 |
|
self.pen_exact.setData((min(x),max(x)), (self.black_box.pf_exact, self.black_box.pf_exact)) |
|
|
519 |
|
if self.log_y_chk.isChecked(): |
|
520 |
|
# Update the data |
|
521 |
|
# když se někde objeví nula se zapnutým LogModem - qtpygraph hned spadne a není možne ten pad zachytit |
|
522 |
|
def nonzero(data): return np.where(data > 0, data, 1) |
|
523 |
|
self.pen_f.setData(x[df.failure.to_numpy() > 0], df.failure.to_numpy()[df.failure.to_numpy() > 0]) |
|
524 |
|
self.pen_mix.setData(x, nonzero(df.failure)) |
|
525 |
|
self.pen_outside.setData(x, nonzero(df.failure+df.mix)) |
|
526 |
|
self.pen_success.setData(x, nonzero(df.failure+df.mix+df.out)) # kontrolu, zda je to 1, nechame uživateli |
|
527 |
|
|
|
528 |
|
|
|
529 |
|
|
|
530 |
|
else: |
|
531 |
|
# Update the data |
|
532 |
|
self.pen_f.setData(x, df.failure) |
|
533 |
|
self.pen_mix.setData(x, df.failure+df.mix) |
|
534 |
|
self.pen_outside.setData(x, df.failure+df.mix+df.out) |
|
535 |
|
self.pen_success.setData(x, df.failure+df.mix+df.out+df.success) # kontrolu, zda je to 1, nechame uivateli |
|
536 |
|
|
|
537 |
|
|
|
538 |
|
|
|
539 |
|
if (xmax - xmin) > 0: |
|
540 |
|
if hasattr(self.black_box, 'pf_exact'): |
|
541 |
|
# poslední. I když spadne, tak už nikomu moc nevadí |
|
542 |
|
self.pen_exact.setData((xmin,xmax), (self.black_box.pf_exact, self.black_box.pf_exact)) |
450 |
543 |
|
|
451 |
544 |
except BaseException as e: |
except BaseException as e: |
452 |
545 |
print(self.__class__.__name__ + ":", repr(e)) |
print(self.__class__.__name__ + ":", repr(e)) |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.LayoutWidget): |
458 |
551 |
#f = pg.FillBetweenItem(curves[i], curves[i+1], brushes[i]) |
#f = pg.FillBetweenItem(curves[i], curves[i+1], brushes[i]) |
459 |
552 |
#win.addItem(f) |
#win.addItem(f) |
460 |
553 |
|
|
|
554 |
|
|
|
555 |
|
|
|
556 |
|
|
|
557 |
|
|
461 |
558 |
|
|
462 |
559 |
|
|
463 |
560 |
|
|
|
... |
... |
class SimpleSimplexEstimationGraph(pg.LayoutWidget): |
465 |
562 |
class VoronoiEstimationGraph(pg.PlotWidget): |
class VoronoiEstimationGraph(pg.PlotWidget): |
466 |
563 |
def __init__(self, black_box, parent=None, *args, **kwargs): |
def __init__(self, black_box, parent=None, *args, **kwargs): |
467 |
564 |
super().__init__(parent) |
super().__init__(parent) |
468 |
|
#self.plotItem.getContextMenus = self.getContextMenus |
|
469 |
|
self.contextMenu = QtGui.QMenu(self) |
|
470 |
|
self.act = self.contextMenu.addAction("New") |
|
471 |
|
self.openAct = self.contextMenu.addAction("Open") |
|
472 |
|
self.quitAct = self.contextMenu.addAction("Quit") |
|
473 |
565 |
|
|
474 |
|
#pw.plotItem.ctrlMenu.actions() |
|
475 |
|
self.plotItem.ctrlMenu.removeAction(self.plotItem.ctrlMenu.actions()[0]) |
|
|
566 |
|
self.black_box = black_box |
|
567 |
|
self.setBackground('w') |
476 |
568 |
|
|
477 |
|
self.plotItem.ctrlMenu.insertAction(self.plotItem.ctrlMenu.actions()[0], self.act) |
|
|
569 |
|
# implicitně Y je v logaritmickem měřítku |
|
570 |
|
self.setLogMode(False, True) |
|
571 |
|
|
|
572 |
|
x = y = () # zde jen vytvoříme kostru, nakrmíme daty v .redraw() |
478 |
573 |
|
|
479 |
|
#print(self.getPlotItem().getContextMenus(0)) |
|
480 |
574 |
|
|
|
575 |
|
# nechapu, proč těm Itemům ríkám "propíska" |
|
576 |
|
# propíska? Их есть у нас! |
481 |
577 |
|
|
|
578 |
|
self.Voronoi_2_point_upper_bound = self.plot(x, y, pen='y') |
|
579 |
|
self.Voronoi_2_point_lower_bound = self.plot(x, y, pen='y') |
482 |
580 |
|
|
|
581 |
|
fill_color = (255, 243, 154) # let's try xkcd: dark cream (#fff39a) |
|
582 |
|
self.fill = pg.FillBetweenItem(self.Voronoi_2_point_upper_bound, self.Voronoi_2_point_lower_bound, fill_color) |
|
583 |
|
self.addItem(self.fill) |
483 |
584 |
|
|
484 |
|
# self.black_box = black_box |
|
485 |
|
# self.plot = pg.PlotWidget() |
|
486 |
|
# self.plot.setBackground('w') |
|
487 |
|
# self.addWidget(self.plot, colspan=2) |
|
488 |
|
# |
|
489 |
|
# self.LogX = QtGui.QCheckBox('LogX') |
|
490 |
|
# self.addWidget(self.LogX, row=1, col=0) |
|
491 |
|
# self.LogY = QtGui.QCheckBox('LogY') |
|
492 |
|
# self.addWidget(self.LogY, row=1, col=1) |
|
493 |
|
# |
|
494 |
|
# self.logXCheck = QtGui.QCheckBox(self.transformGroup) |
|
495 |
|
# self.logXCheck.setObjectName(_fromUtf8("logXCheck")) |
|
496 |
|
# self.gridLayout.addWidget(self.logXCheck, 1, 0, 1, 1) |
|
497 |
|
# self.logYCheck = QtGui.QCheckBox(self.transformGroup) |
|
498 |
|
# self.logYCheck.setObjectName(_fromUtf8("logYCheck")) |
|
499 |
|
|
|
500 |
|
# self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) |
|
501 |
|
# quitAction = QtGui.QAction("Quit", self) |
|
502 |
|
# #quitAction.triggered.connect(qApp.quit) |
|
503 |
|
# self.addAction(quitAction) |
|
504 |
|
# |
|
505 |
|
# |
|
506 |
|
# self.addActions(self.getContextMenus(None)) |
|
|
585 |
|
self.Voronoi_2_point_failure_rate = self.plot(x, y, pen=(195,46,212)) |
|
586 |
|
self.Voronoi_2_point_pure_failure_rate = self.plot(x, y, pen='m') |
|
587 |
|
self.Voronoi_failure_rate = self.plot(x, y, pen='r') |
507 |
588 |
|
|
508 |
|
# |
|
509 |
|
# def getContextMenus(self, event): |
|
510 |
|
# ## called when another item is displaying its context menu; we get to add extras to the end of the menu. |
|
511 |
|
# if self.menuEnabled(): |
|
512 |
|
# return self.ctrlMenu |
|
513 |
|
# else: |
|
514 |
|
# return None |
|
515 |
|
|
|
516 |
|
# def contextMenuEvent(self, event): |
|
517 |
|
# |
|
518 |
|
# contextMenu = QMenu(self) |
|
519 |
|
# |
|
520 |
|
# newAct = contextMenu.addAction("New") |
|
521 |
|
# |
|
522 |
|
# openAct = contextMenu.addAction("Open") |
|
523 |
|
# |
|
524 |
|
# quitAct = contextMenu.addAction("Quit") |
|
525 |
|
# |
|
526 |
|
# action = contextMenu.exec_(self.mapToGlobal(event.pos())) |
|
527 |
|
# |
|
528 |
|
# if action == quitAct: |
|
529 |
|
# |
|
530 |
|
# self.close() |
|
531 |
|
|
|
532 |
|
|
|
533 |
|
# x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
|
534 |
|
# |
|
535 |
|
# #self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
|
536 |
|
# pen = pg.mkPen(color=(255, 0, 0), width=3)#, style=QtCore.Qt.DashLine) |
|
537 |
|
# self.pen_f = self.plot(x, y, pen=pen) # red |
|
538 |
|
# self.pen_mix = self.plot(x, y, fillLevel=0, brush=(255, 165, 0)) # orange |
|
539 |
|
# self.pen_outside = self.plot(x, y, fillLevel=0, brush=0.8) # grey |
|
540 |
|
# self.pen_success = self.plot(x, y, fillLevel=0, brush='g') # green |
|
541 |
|
# self.pen_exact = self.plot(x, y, pen='b') # blue |
|
542 |
|
# |
|
543 |
|
# self.setLogMode(False, True) |
|
544 |
|
# |
|
545 |
|
# self.redraw() |
|
|
589 |
|
self.pen_exact = self.plot(x, y, pen='b') # blue |
|
590 |
|
self.pen_one = self.plot(x, y, pen='k') # black |
546 |
591 |
|
|
|
592 |
|
self.redraw() |
|
593 |
|
|
547 |
594 |
|
|
548 |
595 |
def redraw(self): |
def redraw(self): |
|
596 |
|
# kruci, ještě navic i generovať pokažde znovu... |
|
597 |
|
metrics = {'Voronoi_2_point_upper_bound':{},\ |
|
598 |
|
'Voronoi_2_point_lower_bound':{},\ |
|
599 |
|
'Voronoi_2_point_failure_rate':{},\ |
|
600 |
|
'Voronoi_2_point_pure_failure_rate':{},\ |
|
601 |
|
'Voronoi_failure_rate':{},} |
|
602 |
|
xmin = np.inf |
|
603 |
|
xmax = -np.inf |
549 |
604 |
try: # тут всё что угодно может пойти не так |
try: # тут всё что угодно может пойти не так |
550 |
|
data = self.black_box.guessbox.estimations[self.tri_estimation_name] |
|
551 |
|
x = data[0] |
|
552 |
|
# it can be effectively done with pandas |
|
553 |
|
df = pd.DataFrame(data[1]) |
|
554 |
|
# -1 = 'out', 0=success, 1=failure, 2=mix |
|
555 |
|
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
|
556 |
|
|
|
557 |
|
# Update the data |
|
558 |
|
# když se někde objeví nula se zapnutým LogModem - qtpygraph hned spadne a není možne ten pad zachytit |
|
559 |
|
def nonzero(data): return np.where(data > 0, data, 1) |
|
560 |
|
self.pen_f.setData(np.array(x)[df.failure.to_numpy() > 0], df.failure.to_numpy()[df.failure.to_numpy() > 0]) |
|
561 |
|
self.pen_mix.setData(x, nonzero(df.failure)) |
|
562 |
|
self.pen_outside.setData(x, nonzero(df.failure+df.mix)) |
|
563 |
|
self.pen_success.setData(x, nonzero(df.failure+df.mix+df.out)) # kontrolu, zda je to 1, nechame uživateli |
|
|
605 |
|
# new-style: šecko leží dohromady a každý si z toho |
|
606 |
|
# bere co chce a jak chce |
|
607 |
|
# ne že by to bylo nějak šetrný |
|
608 |
|
# estimation je slovníkem |
|
609 |
|
for estimation in self.black_box.estimations: |
|
610 |
|
# nsim musí mäť každej odhad |
|
611 |
|
# pokud nemá - je třeba jej prostě opravit |
|
612 |
|
nsim = estimation['nsim'] |
|
613 |
|
|
|
614 |
|
|
|
615 |
|
for metric, metric_dict in metrics.items(): |
|
616 |
|
try: |
|
617 |
|
if estimation[metric] > 0: |
|
618 |
|
metric_dict[nsim] = estimation[metric] |
|
619 |
|
if nsim > xmax: |
|
620 |
|
xmax = nsim |
|
621 |
|
if nsim < xmin: |
|
622 |
|
xmin = nsim |
|
623 |
|
except KeyError as e: |
|
624 |
|
pass #print(self.__class__.__name__ + ":", repr(e)) |
564 |
625 |
|
|
565 |
|
self.pen_exact.setData((min(x),max(x)), (self.black_box.pf_exact, self.black_box.pf_exact)) |
|
|
626 |
|
for metric, metric_dict in metrics.items(): |
|
627 |
|
pen = getattr(self, metric) |
|
628 |
|
# nikdo neslibil, že budou v pořadí |
|
629 |
|
x = np.sort(tuple(metric_dict.keys())) |
|
630 |
|
y = np.array(tuple(metric_dict.values()))[np.argsort(tuple(metric_dict.keys()))] |
|
631 |
|
pen.setData(x, y) |
|
632 |
|
|
|
633 |
|
if (xmax - xmin) > 0: |
|
634 |
|
self.pen_one.setData((xmin,xmax), (1, 1)) |
|
635 |
|
if hasattr(self.black_box, 'pf_exact'): |
|
636 |
|
# poslední. I když spadne, tak už nikomu moc nevadí |
|
637 |
|
self.pen_exact.setData((xmin,xmax), (self.black_box.pf_exact, self.black_box.pf_exact)) |
566 |
638 |
|
|
567 |
639 |
except BaseException as e: |
except BaseException as e: |
568 |
640 |
print(self.__class__.__name__ + ":", repr(e)) |
print(self.__class__.__name__ + ":", repr(e)) |
|
... |
... |
class VoronoiEstimationGraph(pg.PlotWidget): |
575 |
647 |
#win.addItem(f) |
#win.addItem(f) |
576 |
648 |
|
|
577 |
649 |
|
|
|
650 |
|
|
|
651 |
|
|
|
652 |
|
|
|
653 |
|
|
|
654 |
|
|
|
655 |
|
""" |
|
656 |
|
============= |
|
657 |
|
Эксерон виӝет |
|
658 |
|
Widgety odhadů |
|
659 |
|
Estimation widgets |
|
660 |
|
=================== |
|
661 |
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
662 |
|
""" |
|
663 |
|
|
578 |
664 |
|
|
579 |
665 |
|
|
580 |
666 |
class SimplexEstimationWidget(pg.LayoutWidget): |
class SimplexEstimationWidget(pg.LayoutWidget): |
|
... |
... |
class SimplexEstimationWidget(pg.LayoutWidget): |
648 |
734 |
print(error_msg) |
print(error_msg) |
649 |
735 |
self.error.emit(error_msg) |
self.error.emit(error_msg) |
650 |
736 |
|
|
|
737 |
|
if hasattr(self.sb_item.sample_box, 'estimations'): |
|
738 |
|
self.sb_item.sample_box.estimations.append(data) |
|
739 |
|
|
651 |
740 |
# přebarvíme tečičky podle obsahu pravděpodobnosti |
# přebarvíme tečičky podle obsahu pravděpodobnosti |
652 |
741 |
for nodes, plot_item, cell_stats in self.simplices: |
for nodes, plot_item, cell_stats in self.simplices: |
653 |
742 |
plot_item.setSymbolBrush(self.get_color(cell_stats)) |
plot_item.setSymbolBrush(self.get_color(cell_stats)) |
|
... |
... |
class VoronoiEstimationWidget(pg.LayoutWidget): |
914 |
1003 |
data = stm_function(sample_box, model_space=model_space, sampling_space=sampling_space,\ |
data = stm_function(sample_box, model_space=model_space, sampling_space=sampling_space,\ |
915 |
1004 |
p_norm=p_norm, budget=budget, callback=coloring_function) |
p_norm=p_norm, budget=budget, callback=coloring_function) |
916 |
1005 |
self.table.setData(data) |
self.table.setData(data) |
|
1006 |
|
if hasattr(self.sb_item.sample_box, 'estimations'): |
|
1007 |
|
self.sb_item.sample_box.estimations.append(data) |
917 |
1008 |
except BaseException as e: |
except BaseException as e: |
918 |
1009 |
msg = "error during estimation " |
msg = "error during estimation " |
919 |
1010 |
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |
error_msg = self.__class__.__name__ + ": " + msg + repr(e) |