#!/usr/bin/env python
# coding: utf-8
#č nazvy proměnných jsou v angličtině
#č Ale komenty teda ne)
#č sehnaní datarámu necháme uživateli
def tri_estimation_fill(ax, df):
# some default values
if not ax.get_xlabel():
ax.set_xlabel('Number of simulations')
if not ax.get_ylabel():
ax.set_ylabel('Probability measure')
#xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5
green = "#A7FFB5"
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5)
red = "#FDC1C5"
#xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a)
cream = "#FFF39A"
grey = "#DDDDDD"
colors = (red, cream, grey, green)
o = df['outside'].to_numpy()
s = df['success'].to_numpy()
f = df['failure'].to_numpy()
m = df['mix'].to_numpy()
labels = ("failure domain estimation", "mixed simplices measure",\
"out of sampling domain estimation", "success domain estimation")
return ax.stackplot(df.index, f, m, o, s, labels=labels, colors=colors)
#č sehnaní datarámu necháme uživateli
# inverted
def trii_estimation_fill(ax, df):
# some default values
if not ax.get_xlabel():
ax.set_xlabel('Number of simulations')
if not ax.get_ylabel():
ax.set_ylabel('Probability measure')
#xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5
green = "#A7FFB5"
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5)
red = "#FDC1C5"
#xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a)
cream = "#FFF39A"
grey = "#DDDDDD"
colors = (grey, red, cream, green)
o = df['outside'].to_numpy()
s = df['success'].to_numpy()
f = df['failure'].to_numpy()
m = df['mix'].to_numpy()
labels = ("out of sampling domain estimation", "failure domain estimation",\
"mixed simplices measure", "success domain estimation")
return ax.stackplot(df.index, o, f, m, s, labels=labels, colors=colors)
#č ok, tak uděláme všecko dohromady
#č datarám, jako vždy, uživatel donese svůj vlastní
def trii_estimation_plot(ax, df):
# fill
trii_estimation_fill(ax, df)
#č teď čáry
v = df['vertex_estimation'].to_numpy()
wv = df['weighted_vertex_estimation'].to_numpy()
# v trii grafu máme outside zdolu
mask = v > 0
o = df['outside'].to_numpy()[mask]
vo = v[mask] + o
wvo = wv[mask] + o
ax.plot(df.index[mask], vo, '-m', label="simple $p_f$ estimation")
ax.plot(df.index[mask], wvo, '-r', label="weighted $p_f$ estimation")
# pf_exact - povinné :)
ax.axhline(ax.sample_box.pf_exact, c='b', label=ax.sample_box.pf_exact_method)
##xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5
#green = (0, 255, 38, 96)
##xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5)
#red = (253, 0, 17, 96)
##xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a)
#cream = (255, 221, 0, 96)
#grey = (196, 196, 196, 96)
class SimplexErrorGraph:
def show_labels(self):
self.setLabel('left', "Failure probability estimation error")
self.setLabel('bottom', "Number of simulations")
def setup(self, *args, **kwargs):
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5)
#red = (253, 0, 17, 96)
#self.pen_f = self.plot(x, y, brush=red)#, name="failure domain estimation")
#self.pen_f.setZValue(-100)
pen = pg.mkPen(color='m', width=2)
self.pen_vertex = self.plot(x, y, pen=pen, name="simple pf estimation")
pen = pg.mkPen(color='r', width=2) #(118, 187, 255)
self.pen_weighted_vertex = self.plot(x, y, pen=pen, name="weighted pf estimation")
#č když se někde objeví nula se zapnutým LogModem -
#č qtpygraph hned spadne a není možne ten pad zachytit
def zerosafe(self, x, y, fallback_y=None):
x = np.array(x)
y = np.array(y)
if fallback_y is None:
fallback_y = y
y = np.where(y > 0, y, fallback_y)
mask = y > 0
return x[mask], y[mask]
def redraw(self):
#č neotravujme uživatele chybovejma hlaškama
if hasattr(self.simplex_data.dice_box, 'pf_exact'):
try: #ё тут всё что угодно может пойти не так
pf_exact = self.simplex_data.dice_box.pf_exact
df = self.simplex_data.df
#č zapíšeme do data rámu, snad nikomu nebude vadit
df['vertex_estimation_error'] = df['vertex_estimation'] - pf_exact
df['weighted_vertex_estimation_error'] = df['weighted_vertex_estimation'] - pf_exact
v = df['vertex_estimation_error'].abs()
wv = df['weighted_vertex_estimation_error'].abs()
x, y = self.zerosafe(v.index, v.to_numpy())
self.pen_vertex.setData(x, y)
x, y = self.zerosafe(wv.index, wv.to_numpy())
self.pen_weighted_vertex.setData(x, y)
except BaseException as e:
print(self.__class__.__name__ + ":", repr(e))