File mart.py changed (mode: 100644) (index c1e84b9..071b20e) |
8 |
8 |
import numpy as np |
import numpy as np |
9 |
9 |
import matplotlib.tri as mtri |
import matplotlib.tri as mtri |
10 |
10 |
import matplotlib.colors as mcolor |
import matplotlib.colors as mcolor |
|
11 |
|
import matplotlib.patches as mpatches |
|
12 |
|
|
|
13 |
|
from . import misc |
11 |
14 |
|
|
12 |
15 |
def get_simplices_colors(sb, simplices): #simplices = bx.tri.simplices |
def get_simplices_colors(sb, simplices): #simplices = bx.tri.simplices |
13 |
16 |
s = '#a7ffb5' #'xkcd:light seafoam green' #a7ffb5 |
s = '#a7ffb5' #'xkcd:light seafoam green' #a7ffb5 |
|
... |
... |
def convex_plot(ax, fmt='-m', ns=100, **kwargs): |
167 |
170 |
return lines |
return lines |
168 |
171 |
|
|
169 |
172 |
|
|
|
173 |
|
def gcircle(ax, r=1, nrod=200, **kwargs): |
|
174 |
|
if ax.space == 'G': |
|
175 |
|
circle = mpatches.Circle((0,0), r, **kwargs) |
|
176 |
|
else: |
|
177 |
|
phi = np.linspace(0, 6.283185307, nrod, endpoint=True) |
|
178 |
|
cos_phi = np.cos(phi) |
|
179 |
|
sin_phi = np.sin(phi) |
|
180 |
|
|
|
181 |
|
sample_G = np.array((cos_phi, sin_phi)).T * r |
|
182 |
|
|
|
183 |
|
f_model = ax.sample_box.f_model |
|
184 |
|
sample = f_model.new_sample(sample_G, space='G', extend=True) |
|
185 |
|
xy = getattr(sample, ax.space)[:,:2] |
|
186 |
|
circle = mpatches.Polygon(xy, **kwargs) |
|
187 |
|
|
|
188 |
|
#č vrací add_patch něco? |
|
189 |
|
return ax.add_patch(circle) |
170 |
190 |
|
|
171 |
191 |
|
|
|
192 |
|
def uframe(ax, **kwargs): |
|
193 |
|
if ax.space in ('P', 'aP', 'U', 'aU'): |
|
194 |
|
alpha = ax.sample_box.alpha |
|
195 |
|
frame = mpatches.Rectangle((0,0), alpha[0], alpha[1], fill=False, **kwargs) |
|
196 |
|
return ax.add_patch(frame) |
172 |
197 |
|
|
173 |
198 |
|
|
174 |
199 |
|
|
175 |
|
def isočáry(ax, space, ngrid=200, limits=None): |
|
|
200 |
|
def isocurves(ax, ngrid=200, limits=None, ncurves=5, **kwargs): |
176 |
201 |
if limits is None: |
if limits is None: |
177 |
|
xmin, xmax = ax.get_xlim() |
|
178 |
|
ymin, ymax = ax.get_ylim() |
|
|
202 |
|
#xmin, xmax = ax.get_xlim() |
|
203 |
|
#ymin, ymax = ax.get_ylim() |
|
204 |
|
|
|
205 |
|
sample_G = np.array([[-ncurves, -ncurves], [ncurves, ncurves]]) |
|
206 |
|
sample = ax.sample_box.f_model.new_sample(sample_G, space='G', extend=True) |
|
207 |
|
xy = getattr(sample, ax.space)[:,:2] |
|
208 |
|
xmin, ymin = np.min(xy, axis=0) |
|
209 |
|
xmax, ymax = np.max(xy, axis=0) |
|
210 |
|
|
179 |
211 |
else: # G-čko zlobí |
else: # G-čko zlobí |
180 |
212 |
xmin, xmax, ymin, ymax = limits |
xmin, xmax, ymin, ymax = limits |
181 |
|
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
182 |
216 |
x = np.linspace(xmin, xmax, ngrid) |
x = np.linspace(xmin, xmax, ngrid) |
183 |
217 |
y = np.linspace(ymin, ymax, ngrid) |
y = np.linspace(ymin, ymax, ngrid) |
184 |
218 |
X, Y = np.meshgrid(x, y) |
X, Y = np.meshgrid(x, y) |
185 |
219 |
XY = np.vstack((X.flatten(), Y.flatten())).T |
XY = np.vstack((X.flatten(), Y.flatten())).T |
186 |
|
Z = f.sample_pdf(XY, space) |
|
|
220 |
|
Z = ax.sample_box.f_model.sample_pdf(XY, ax.space) |
|
221 |
|
|
187 |
222 |
|
|
188 |
|
ncurves = 3 |
|
189 |
223 |
const = 1 / (xmax - xmin) / (ymax - ymin) |
const = 1 / (xmax - xmin) / (ymax - ymin) |
190 |
224 |
r_levels = np.arange(ncurves) + 1 |
r_levels = np.arange(ncurves) + 1 |
191 |
225 |
levels = misc.isolevels_2d(Z, const, np.flip(r_levels), from_top=False) |
levels = misc.isolevels_2d(Z, const, np.flip(r_levels), from_top=False) |
192 |
|
|
|
193 |
|
return ax.contour(X, Y, Z.reshape(ngrid, ngrid), levels, linewidths=lw, colors=[[96/255, 64/255, 96/255], [0.5, 0.25, 0.5], [161/255, 72/255, 162/255]])#, alpha=0.5) colors: h=300, s=50% |
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
|
|
226 |
|
return ax.contour(X, Y, Z.reshape(ngrid, ngrid), levels, **kwargs) |
207 |
227 |
|
|
208 |
228 |
|
|
209 |
229 |
|
|
|
... |
... |
def fix_locator(ax, loc): |
235 |
255 |
loc_y = mpl.ticker.FixedLocator(loc) |
loc_y = mpl.ticker.FixedLocator(loc) |
236 |
256 |
ax.yaxis.set_major_locator(loc_y) |
ax.yaxis.set_major_locator(loc_y) |
237 |
257 |
|
|
|
258 |
|
#č něco_kulatého |
|
259 |
|
def curly(ax, linewidths=[0.7, 0.5, 0.4, 0.3, 0.2, 0.1], nrid=200, color='k', **kwargs): |
|
260 |
|
if ax.space in ('U', 'aU'): |
|
261 |
|
return None |
|
262 |
|
|
|
263 |
|
elif (ax.sample_box.nvar==2) and (ax.space in ('Rn', 'aRn', 'R', 'aR', 'P', 'aP')): |
|
264 |
|
isocurves(ax, ngrid=nrid, limits=None, ncurves=len(linewidths),\ |
|
265 |
|
linewidths=np.flip(linewidths), colors=[color], **kwargs) |
|
266 |
|
|
|
267 |
|
else: |
|
268 |
|
for i, lw in zip(range(len(linewidths)), linewidths): |
|
269 |
|
gcircle(ax, r=i+1, nrod=nrid, color=color, linewidth=lw, fill=False) |
|
270 |
|
|
|
271 |
|
|
|
272 |
|
def setup(ax, lw=1): #č šup |
|
273 |
|
#ax.set_xlabel('$x_{1}$') |
|
274 |
|
#ax.set_ylabel('$x_{2}$') |
|
275 |
|
|
|
276 |
|
#ax.set_frame_on(False) #č pak se mi nezobrazí osy |
|
277 |
|
ax.set_aspect(1) |
|
278 |
|
#ax.set_box_aspect(1) |
|
279 |
|
if ax.space in ('P', 'aP', 'U', 'aU'): |
|
280 |
|
ax.margins(0) |
|
281 |
|
ax.set_frame_on(False) |
|
282 |
|
uframe(ax, linewidth=lw) |
|
283 |
|
else: |
|
284 |
|
center_spines(ax) |
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
|
288 |
|
|
File mgraph.py added (mode: 100644) (index 0000000..faac09f) |
|
1 |
|
#!/usr/bin/env python |
|
2 |
|
# coding: utf-8 |
|
3 |
|
|
|
4 |
|
|
|
5 |
|
#č nazvy proměnných jsou v angličtině |
|
6 |
|
#č Ale komenty teda ne) |
|
7 |
|
|
|
8 |
|
|
|
9 |
|
#č sehnaní datarámu necháme uživateli |
|
10 |
|
def tri_estimation_fill(ax, df): |
|
11 |
|
# some default values |
|
12 |
|
if not ax.get_xlabel(): |
|
13 |
|
ax.set_xlabel('Number of simulations') |
|
14 |
|
if not ax.get_ylabel(): |
|
15 |
|
ax.set_ylabel('Probability measure') |
|
16 |
|
|
|
17 |
|
#xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5 |
|
18 |
|
green = "#A7FFB5" |
|
19 |
|
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5) |
|
20 |
|
red = "#FDC1C5" |
|
21 |
|
#xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a) |
|
22 |
|
cream = "#FFF39A" |
|
23 |
|
grey = "#DDDDDD" |
|
24 |
|
colors = (red, cream, grey, green) |
|
25 |
|
o = df['outside'].to_numpy() |
|
26 |
|
s = df['success'].to_numpy() |
|
27 |
|
f = df['failure'].to_numpy() |
|
28 |
|
m = df['mix'].to_numpy() |
|
29 |
|
labels = ("failure domain estimation", "mixed simplices measure",\ |
|
30 |
|
"out of sampling domain estimation", "success domain estimation") |
|
31 |
|
return ax.stackplot(df.index, f, m, o, s, labels=labels, colors=colors) |
|
32 |
|
|
|
33 |
|
|
|
34 |
|
#č sehnaní datarámu necháme uživateli |
|
35 |
|
# inverted |
|
36 |
|
def trii_estimation_fill(ax, df): |
|
37 |
|
# some default values |
|
38 |
|
if not ax.get_xlabel(): |
|
39 |
|
ax.set_xlabel('Number of simulations') |
|
40 |
|
if not ax.get_ylabel(): |
|
41 |
|
ax.set_ylabel('Probability measure') |
|
42 |
|
|
|
43 |
|
#xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5 |
|
44 |
|
green = "#A7FFB5" |
|
45 |
|
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5) |
|
46 |
|
red = "#FDC1C5" |
|
47 |
|
#xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a) |
|
48 |
|
cream = "#FFF39A" |
|
49 |
|
grey = "#DDDDDD" |
|
50 |
|
colors = (grey, red, cream, green) |
|
51 |
|
o = df['outside'].to_numpy() |
|
52 |
|
s = df['success'].to_numpy() |
|
53 |
|
f = df['failure'].to_numpy() |
|
54 |
|
m = df['mix'].to_numpy() |
|
55 |
|
labels = ("out of sampling domain estimation", "failure domain estimation",\ |
|
56 |
|
"mixed simplices measure", "success domain estimation") |
|
57 |
|
return ax.stackplot(df.index, o, f, m, s, labels=labels, colors=colors) |
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
#č ok, tak uděláme všecko dohromady |
|
62 |
|
#č datarám, jako vždy, uživatel donese svůj vlastní |
|
63 |
|
def trii_estimation_plot(ax, df): |
|
64 |
|
# fill |
|
65 |
|
trii_estimation_fill(ax, df) |
|
66 |
|
|
|
67 |
|
#č teď čáry |
|
68 |
|
v = df['vertex_estimation'].to_numpy() |
|
69 |
|
wv = df['weighted_vertex_estimation'].to_numpy() |
|
70 |
|
# v trii grafu máme outside zdolu |
|
71 |
|
mask = v > 0 |
|
72 |
|
o = df['outside'].to_numpy()[mask] |
|
73 |
|
vo = v[mask] + o |
|
74 |
|
wvo = wv[mask] + o |
|
75 |
|
ax.plot(df.index[mask], vo, '-m', label="simple $p_f$ estimation") |
|
76 |
|
ax.plot(df.index[mask], wvo, '-r', label="weighted $p_f$ estimation") |
|
77 |
|
|
|
78 |
|
# pf_exact - povinné :) |
|
79 |
|
ax.axhline(ax.sample_box.pf_exact, c='b', label=ax.sample_box.pf_exact_method) |
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
##xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5 |
|
84 |
|
#green = (0, 255, 38, 96) |
|
85 |
|
##xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5) |
|
86 |
|
#red = (253, 0, 17, 96) |
|
87 |
|
##xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a) |
|
88 |
|
#cream = (255, 221, 0, 96) |
|
89 |
|
#grey = (196, 196, 196, 96) |
|
90 |
|
|
|
91 |
|
class SimplexErrorGraph: |
|
92 |
|
|
|
93 |
|
|
|
94 |
|
def show_labels(self): |
|
95 |
|
self.setLabel('left', "Failure probability estimation error") |
|
96 |
|
self.setLabel('bottom', "Number of simulations") |
|
97 |
|
|
|
98 |
|
|
|
99 |
|
def setup(self, *args, **kwargs): |
|
100 |
|
|
|
101 |
|
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5) |
|
102 |
|
#red = (253, 0, 17, 96) |
|
103 |
|
|
|
104 |
|
#self.pen_f = self.plot(x, y, brush=red)#, name="failure domain estimation") |
|
105 |
|
#self.pen_f.setZValue(-100) |
|
106 |
|
|
|
107 |
|
|
|
108 |
|
pen = pg.mkPen(color='m', width=2) |
|
109 |
|
self.pen_vertex = self.plot(x, y, pen=pen, name="simple pf estimation") |
|
110 |
|
pen = pg.mkPen(color='r', width=2) #(118, 187, 255) |
|
111 |
|
self.pen_weighted_vertex = self.plot(x, y, pen=pen, name="weighted pf estimation") |
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
#č když se někde objeví nula se zapnutým LogModem - |
|
116 |
|
#č qtpygraph hned spadne a není možne ten pad zachytit |
|
117 |
|
def zerosafe(self, x, y, fallback_y=None): |
|
118 |
|
x = np.array(x) |
|
119 |
|
y = np.array(y) |
|
120 |
|
if fallback_y is None: |
|
121 |
|
fallback_y = y |
|
122 |
|
y = np.where(y > 0, y, fallback_y) |
|
123 |
|
mask = y > 0 |
|
124 |
|
return x[mask], y[mask] |
|
125 |
|
|
|
126 |
|
|
|
127 |
|
def redraw(self): |
|
128 |
|
#č neotravujme uživatele chybovejma hlaškama |
|
129 |
|
if hasattr(self.simplex_data.dice_box, 'pf_exact'): |
|
130 |
|
try: #ё тут всё что угодно может пойти не так |
|
131 |
|
pf_exact = self.simplex_data.dice_box.pf_exact |
|
132 |
|
|
|
133 |
|
df = self.simplex_data.df |
|
134 |
|
#č zapíšeme do data rámu, snad nikomu nebude vadit |
|
135 |
|
df['vertex_estimation_error'] = df['vertex_estimation'] - pf_exact |
|
136 |
|
df['weighted_vertex_estimation_error'] = df['weighted_vertex_estimation'] - pf_exact |
|
137 |
|
|
|
138 |
|
v = df['vertex_estimation_error'].abs() |
|
139 |
|
wv = df['weighted_vertex_estimation_error'].abs() |
|
140 |
|
|
|
141 |
|
x, y = self.zerosafe(v.index, v.to_numpy()) |
|
142 |
|
self.pen_vertex.setData(x, y) |
|
143 |
|
|
|
144 |
|
x, y = self.zerosafe(wv.index, wv.to_numpy()) |
|
145 |
|
self.pen_weighted_vertex.setData(x, y) |
|
146 |
|
|
|
147 |
|
|
|
148 |
|
except BaseException as e: |
|
149 |
|
print(self.__class__.__name__ + ":", repr(e)) |
|
150 |
|
|
|
151 |
|
|
File mplot.py changed (mode: 100644) (index 1f6dd06..fe482f4) |
8 |
8 |
|
|
9 |
9 |
import matplotlib |
import matplotlib |
10 |
10 |
import matplotlib.pyplot as plt |
import matplotlib.pyplot as plt |
11 |
|
matplotlib.rcParams['mathtext.fontset'] = 'stix' |
|
|
11 |
|
matplotlib.rcParams['mathtext.fontset'] = 'cm' # Computer Modern (TeX) |
12 |
12 |
matplotlib.rcParams['font.family'] = 'STIXGeneral' |
matplotlib.rcParams['font.family'] = 'STIXGeneral' |
13 |
13 |
|
|
14 |
|
|
|
15 |
|
#from scipy.special import gamma, factorial |
|
16 |
|
|
|
17 |
|
#import numpy as np |
|
18 |
|
##import numpy.ma as ma |
|
19 |
|
#import scipy.stats as stats |
|
20 |
|
# |
|
21 |
|
##import scipy.integrate as integrate |
|
22 |
|
##from scipy.spatial import ConvexHull |
|
23 |
|
##from scipy.spatial import cKDTree |
|
24 |
|
# |
|
25 |
|
#from scipy import spatial |
|
26 |
|
# |
|
27 |
|
##import lukiskon as lk |
|
28 |
|
#import g_models |
|
29 |
|
#import f_models |
|
30 |
|
# |
|
31 |
|
#import whitebox |
|
32 |
|
# |
|
33 |
|
##import itertools |
|
34 |
|
# |
|
35 |
|
## patří to asi do user kódu |
|
36 |
|
## pro zobrazení v interaktivním okně (IPython) |
|
37 |
|
## get_ipython().run_line_magic('matplotlib', 'nbagg') |
|
38 |
|
# |
|
39 |
|
# |
|
40 |
|
# |
|
41 |
|
# |
|
42 |
|
## Estimation of pf given a list of red and green points (Voronoi) |
|
43 |
|
## |
|
44 |
|
# |
|
45 |
|
#def show_shape(patch): |
|
46 |
|
# ax=plt.gca() |
|
47 |
|
# ax.add_patch(patch) |
|
48 |
|
# #plt.axis('scaled') |
|
49 |
|
# plt.show() |
|
50 |
|
# |
|
51 |
|
#def show_shape(patch, ax): |
|
52 |
|
# ax.add_patch(patch) |
|
53 |
|
# #plt.axis('scaled') |
|
54 |
|
# plt.show() |
|
55 |
|
# |
|
56 |
|
#def draw_voronoi(ax, ns): |
|
57 |
|
# |
|
58 |
|
# plt=ax |
|
59 |
|
# |
|
60 |
|
# #%% Draw R-space |
|
61 |
|
# r = 4 # tato r-ko v local namespace, vid? |
|
62 |
|
# |
|
63 |
|
# x = bx.sampled_plan.R[:ns,0] |
|
64 |
|
# y = bx.sampled_plan.R[:ns,1] |
|
65 |
|
# |
|
66 |
|
# mask = bx.failsi[:ns] |
|
67 |
|
# |
|
68 |
|
# |
|
69 |
|
# plt.plot(x[ mask], y[ mask], 'o', c='r' , markersize=1.0) |
|
70 |
|
# plt.plot(x[~mask], y[~mask], 'o', c='g' , markersize=1.0) |
|
71 |
|
# |
|
72 |
|
# #for j, p in enumerate(sampled_plan_R): |
|
73 |
|
# # plt.text(p[0]-0.0, p[1]+0.0, j, ha='right') # label the points |
|
74 |
|
# |
|
75 |
|
# if gm.__class__.__name__ == 'S_ball': |
|
76 |
|
# xbound = np.linspace(-r, +r, 100) |
|
77 |
|
# plt.plot(xbound, +np.sqrt(r**2 - xbound**2), '--', c = 'blue', linewidth = 0.5) |
|
78 |
|
# plt.plot(xbound, -np.sqrt(r**2 - xbound**2), '--', c = 'blue', linewidth = 0.5) |
|
79 |
|
# |
|
80 |
|
# |
|
81 |
|
# if gm.__class__.__name__ == 'Sin2D': |
|
82 |
|
# xbound = np.linspace(-r, +r, 100) |
|
83 |
|
# plt.plot(xbound,- xbound/4 + np.sin(5*xbound) + 6, '--', c = 'blue', linewidth = 0.5) |
|
84 |
|
# |
|
85 |
|
# |
|
86 |
|
# |
|
87 |
|
# tree = cKDTree(bx.sampled_plan.R[:ns]) |
|
88 |
|
# |
|
89 |
|
# nis = 1500000 |
|
90 |
|
# pf = 0 # inicializace |
|
91 |
|
# ps = 0 |
|
92 |
|
# |
|
93 |
|
# points_weigths = np.zeros(len(bx)) |
|
94 |
|
# near_neighbors = np.zeros(len(bx)) |
|
95 |
|
# # loop over points (need to integrate red regions) |
|
96 |
|
# |
|
97 |
|
# |
|
98 |
|
# # set the minimum distance as the standard deviation of IS densisty |
|
99 |
|
# h_i = [stats.norm(0, 2) for j in range(nvar)] #! dosadit standard deviation pddle chutí |
|
100 |
|
# |
|
101 |
|
# |
|
102 |
|
# # use IS sampling density with center equal to the current "red" point |
|
103 |
|
# |
|
104 |
|
# # select nis = 100 points from IS density and |
|
105 |
|
# # if the point has its nearest neighbor any red point from the sampled_plan, |
|
106 |
|
# |
|
107 |
|
# h_plan = np.zeros((nis, nvar)) |
|
108 |
|
# for j in range(nvar): |
|
109 |
|
# h_plan[:, j] = h_i[j].rvs(nis) # realizace váhové funkce náhodné veličiny |
|
110 |
|
# |
|
111 |
|
# # Rozptyl corrected IS |
|
112 |
|
# weights_sim = bx.f.new_sample(h_plan).pdf_R / np.prod([h_i[j].pdf(h_plan[:, j]) |
|
113 |
|
# for j in range(nvar)], axis=0) # [f1/h1, ..., fn/hn] |
|
114 |
|
# |
|
115 |
|
# |
|
116 |
|
# |
|
117 |
|
# dd, ii = tree.query(h_plan) |
|
118 |
|
# |
|
119 |
|
# Vor_mask = np.empty(len(ii), dtype=bool)# np.where(ii==i, True, False) |
|
120 |
|
# |
|
121 |
|
# for k in range(len(ii)): |
|
122 |
|
# #points_weigths[ii[k]] = points_weigths[ii[k]] + weights_sim[k] / nis |
|
123 |
|
# #near_neighbors[ii[k]] = near_neighbors[ii[k]] + 1 |
|
124 |
|
# Vor_mask[k] = bx.failsi[ii[k]] |
|
125 |
|
# |
|
126 |
|
# pf = np.sum(weights_sim[Vor_mask])/nis |
|
127 |
|
# #print(pf) |
|
128 |
|
# |
|
129 |
|
# |
|
130 |
|
# # rohy. jasně |
|
131 |
|
# #plt.plot(сэрегъёс_R[:,0], сэрегъёс_R[:,1], 'o', c='b' ) |
|
132 |
|
# |
|
133 |
|
# |
|
134 |
|
# x_grid = h_plan[:,0] |
|
135 |
|
# y_grid = h_plan[:,1] |
|
136 |
|
# |
|
137 |
|
# marker_vole = matplotlib.markers.MarkerStyle(marker='.', fillstyle='full') |
|
138 |
|
# plt.scatter(x_grid[ Vor_mask], y_grid[ Vor_mask], c='xkcd:pale rose' , s=0.125**2, edgecolors='face', marker=marker_vole, alpha=1 ) #'YlOrRd' cmap='Wistia', |
|
139 |
|
# plt.scatter(x_grid[~Vor_mask], y_grid[~Vor_mask], c='xkcd:light seafoam green', s=0.125**2, edgecolors='face', marker=marker_vole, alpha=1 ) #'YlOrRd' cmap='Wistia', |
|
140 |
|
# |
|
141 |
|
# |
|
142 |
|
# #ax0.plot(x_w[fail_wgP], y_w[fail_wgP], 's', color='xkcd:mango', markersize=1) |
|
143 |
|
# # ax0.plot(x_w[fail_wsP], y_w[fail_wsP], 's', color='xkcd:light seafoam green', markersize=1) |
|
144 |
|
# # ax0.plot(x_w[fail_w1P], y_w[fail_w1P], 's', color='xkcd:pale rose', markersize=1) |
|
145 |
|
# # ax0.plot(x_w[fail_w2P], y_w[fail_w2P], 's', color='xkcd:khaki', markersize=1) |
|
146 |
|
# |
|
147 |
|
# |
|
148 |
|
# #plt.xlim(-8, 8); plt.ylim(-8, 8) |
|
149 |
|
# lim = 6.0 |
|
150 |
|
# ax.set_xlim(-lim, lim) |
|
151 |
|
# ax.set_ylim(-lim, lim) |
|
152 |
|
# ax.set_aspect('equal') |
|
153 |
|
# #ax.set_xticks([-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6]) |
|
154 |
|
# #ax.set_yticks([-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6]) |
|
155 |
|
# ax.set_xticks([-6,-4,-2,0,2,4,6]) |
|
156 |
|
# ax.set_yticks([-6,-4,-2,0,2,4,6]) |
|
157 |
|
# #plt.axis('equal') |
|
158 |
|
# |
|
159 |
|
# |
|
160 |
|
# |
|
161 |
|
# |
|
162 |
|
# |
|
163 |
|
# |
|
164 |
|
# #pf = np.sum(points_weigths[failsi]*1/near_neighbors[failsi]) |
|
165 |
|
# #pf = np.sum(points_weigths[failsi]) #/ nis / len(failure_points_indexes) |
|
166 |
|
# |
|
167 |
|
# print(pf) |
|
168 |
|
# |
|
169 |
|
# |
|
170 |
|
## In[66]: |
|
171 |
|
# |
|
172 |
|
# |
|
173 |
|
# |
|
174 |
|
# |
|
175 |
|
#from scipy.spatial import cKDTree |
|
176 |
|
# |
|
177 |
|
## workaround :D |
|
178 |
|
#from matplotlib.axes._axes import _log as matplotlib_axes_logger |
|
179 |
|
#matplotlib_axes_logger.setLevel("DEBUG") |
|
180 |
|
# |
|
181 |
|
#fig, ([ax1, ax2], [ax3, ax4]) = plt.subplots(nrows=2, ncols=2, figsize=(7, 6), tight_layout=True) |
|
182 |
|
# |
|
183 |
|
#nsim = bx.nsim |
|
184 |
|
# |
|
185 |
|
#draw_voronoi(ax1, int(nsim/8)) |
|
186 |
|
#ax1.set_title('n={0}'.format(int(nsim/8))) |
|
187 |
|
# |
|
188 |
|
#draw_voronoi(ax2, int(nsim/4)) |
|
189 |
|
#ax2.set_title('n={0}'.format(int(nsim/4))) |
|
190 |
|
# |
|
191 |
|
#draw_voronoi(ax3, int(nsim/2)) |
|
192 |
|
#ax3.set_title('n={0}'.format(int(nsim/2))) |
|
193 |
|
# |
|
194 |
|
#draw_voronoi(ax4, nsim) |
|
195 |
|
#ax4.set_title('n={0}'.format(nsim)) |
|
196 |
|
##ax1.set_ylabel('U prostor') |
|
197 |
|
##ax3.set_ylabel('R prostor') |
|
198 |
|
##ax1.set_title('Teselace v U prostoru') |
|
199 |
|
##ax2.set_title('Teselace v R prostoru') |
|
200 |
|
# |
|
201 |
|
# |
|
202 |
|
#ax1.set_xlabel('$x_{1}$') |
|
203 |
|
#ax1.set_ylabel('$x_{2}$') |
|
204 |
|
#ax2.set_xlabel('$x_{1}$') |
|
205 |
|
#ax2.set_ylabel('$x_{2}$') |
|
206 |
|
#ax3.set_xlabel('$x_{1}$') |
|
207 |
|
#ax3.set_ylabel('$x_{2}$') |
|
208 |
|
#ax4.set_xlabel('$x_{1}$') |
|
209 |
|
#ax4.set_ylabel('$x_{2}$') |
|
210 |
|
# |
|
211 |
|
##ax1.set_xlim(-8, 8) |
|
212 |
|
##ax1.set_ylim(-8, 8) |
|
213 |
|
##ax1.set_aspect('equal') |
|
214 |
|
# |
|
215 |
|
## plot unit circles for better orientation |
|
216 |
|
# |
|
217 |
|
#for ax in [ax1, ax2, ax3, ax4]: |
|
218 |
|
# circle1 = plt.Circle((0, 0), 1, color='k', linewidth = 0.7, fill=False) |
|
219 |
|
# circle2 = plt.Circle((0, 0), 2, color='k', linewidth = 0.5, fill=False) |
|
220 |
|
# circle3 = plt.Circle((0, 0), 3, color='k', linewidth = 0.4, fill=False) |
|
221 |
|
# circle4 = plt.Circle((0, 0), 4, color='k', linewidth = 0.3, fill=False) |
|
222 |
|
# circle5 = plt.Circle((0, 0), 5, color='k', linewidth = 0.2, fill=False) |
|
223 |
|
# circle6 = plt.Circle((0, 0), 6, color='k', linewidth = 0.1, fill=False) |
|
224 |
|
# show_shape(circle1, ax) |
|
225 |
|
# show_shape(circle2, ax) |
|
226 |
|
# show_shape(circle3, ax) |
|
227 |
|
##show_shape(circle4) |
|
228 |
|
##show_shape(circle5) |
|
229 |
|
##show_shape(circle6) |
|
230 |
|
# |
|
231 |
|
##plt.axis('square') |
|
232 |
|
# |
|
233 |
|
##fig.savefig("2x2_Deloneho_Zprod.png", dpi=300) |
|
234 |
|
##fig.savefig("2x2.eps") |
|
235 |
|
##fig.savefig("2x2.svg") |
|
236 |
|
##fig.savefig("2x2.pdf") |
|
237 |
|
|
|
|
14 |
|
from . import mart |
238 |
15 |
|
|
239 |
16 |
|
|
240 |
17 |
def subplot3D(sample_box, ax3d, space='R'): |
def subplot3D(sample_box, ax3d, space='R'): |
|
... |
... |
def subplot3D(sample_box, ax3d, space='R'): |
250 |
27 |
|
|
251 |
28 |
|
|
252 |
29 |
|
|
253 |
|
def plot3D(sample_box, space='R', filename=''): |
|
|
30 |
|
def plot3D(sample_box, space='R', filename='', format='pdf'): |
254 |
31 |
if not filename: |
if not filename: |
255 |
|
filename = 'store/%s_%s_%s'%(sample_box.gm_signature, space, sample_box.nsim) |
|
|
32 |
|
filename = 'store/%s_%s_%s_plot3D'%(sample_box.gm_signature, space, sample_box.nsim) |
256 |
33 |
fig = plt.figure() |
fig = plt.figure() |
257 |
34 |
ax3d = fig.add_subplot(111, projection='3d') |
ax3d = fig.add_subplot(111, projection='3d') |
258 |
35 |
subplot3D(sample_box, ax3d, space) |
subplot3D(sample_box, ax3d, space) |
259 |
36 |
|
|
260 |
37 |
try: # jen pro formu zkusíme, vždyť musí funkce formálně něco dělat, žejo? |
try: # jen pro formu zkusíme, vždyť musí funkce formálně něco dělat, žejo? |
261 |
|
fig.savefig(filename + ".png")#, dpi=300) |
|
|
38 |
|
fig.savefig(filename + "." + format)#, dpi=300) |
262 |
39 |
except: |
except: |
263 |
40 |
pass # nic se neděje |
pass # nic se neděje |
264 |
41 |
|
|
265 |
42 |
# vracím plt místo figury, protože nechcem sa trapiť ivent lupem |
# vracím plt místo figury, protože nechcem sa trapiť ivent lupem |
266 |
43 |
# return plt insted of just fig to bypass event loop issues |
# return plt insted of just fig to bypass event loop issues |
267 |
|
return plt |
|
|
44 |
|
return plt.show() |
|
45 |
|
|
268 |
46 |
|
|
269 |
47 |
|
|
270 |
|
# |
|
271 |
|
## nikdo mi neuvěří, že by tohle postačílo a nebylo by nutné tohlensto furt úpravovat |
|
272 |
|
#def gp_plot(sample_box, space='R', terminal='png', filename=''): |
|
273 |
|
# if not filename: |
|
274 |
|
# filename = 'store/%s_%s_%s'%(sample_box.gm_signature, space, sample_box.nsim) |
|
275 |
|
# if space in ['Rn', 'GK', 'G']: |
|
276 |
|
# gp.c('set autoscale xy') |
|
277 |
|
# gp.c('set size square') |
|
278 |
|
# gp.c('set zeroaxis') |
|
279 |
|
# elif space in ['P', 'U']: |
|
280 |
|
# gp.c('set xrange [0:1]') |
|
281 |
|
# gp.c('set yrange [0:1]') |
|
282 |
|
# gp.c('set size square') |
|
283 |
|
# #gp.c('set autoscale') |
|
284 |
|
# gp.c('unset zeroaxis') |
|
285 |
|
# else: # R teda? |
|
286 |
|
# gp.c('set size noratio') |
|
287 |
|
# gp.c('set autoscale') |
|
288 |
|
# gp.c('unset zeroaxis') |
|
289 |
|
# |
|
290 |
|
# gp.c('set terminal ' + terminal) |
|
291 |
|
# gp.c('set output "%s.%s"'%(filename, terminal)) |
|
292 |
|
# if os.name == 'posix': |
|
293 |
|
# gp.c('set decimalsign locale "POSIX"') |
|
294 |
|
# |
|
295 |
|
# # legenda |
|
296 |
|
# gp.c('unset key') |
|
297 |
|
# |
|
298 |
|
# # se mi zda, že gp bere data v řadcích |
|
299 |
|
# f_name = "%s_failure.dat" % (filename) |
|
300 |
|
# s_name = "%s_success.dat" % (filename) |
|
301 |
|
# gp.s(getattr(sample_box.failure_samples, space).T, f_name) |
|
302 |
|
# gp.s(getattr(sample_box.success_samples, space).T, s_name) |
|
303 |
|
# |
|
304 |
|
# |
|
305 |
|
# # rozkaz, který předaváme gnuplotovi |
|
306 |
|
# gp_plot = 'plot "%s" title "Success points" w p lc rgb "green", "%s" title "Failure points" w p lc rgb "red"' % (s_name, f_name) |
|
307 |
|
# |
|
308 |
|
# # Kružničky chcete? |
|
309 |
|
# # Кружочки ннада? |
|
310 |
|
# if space in ['Rn', 'G']: |
|
311 |
|
# gp.c('set parametric') |
|
312 |
|
# for i in range(5): |
|
313 |
|
# lw = 2 - i*0.3 |
|
314 |
|
# gp_plot += ', cos(t)*%s,sin(t)*%s notitle w l lc rgb "black" lw %s'%(i+1, i+1, lw) |
|
315 |
|
# |
|
316 |
|
# # ne všichni majó definované hranice |
|
317 |
|
# try: |
|
318 |
|
# bounds = sample_box.get_2D_boundary() |
|
319 |
|
# |
|
320 |
|
# for i in range(len(bounds)): |
|
321 |
|
# bound = getattr(bounds[i], space).T |
|
322 |
|
# gp.s(bound, "%s_boundary_%s.dat"%(filename, i+1)) |
|
323 |
|
# gp_plot += ', "%s_boundary_%s.dat" notitle w l lc rgb "blue"'%(filename, i+1) |
|
324 |
|
# except AttributeError: |
|
325 |
|
# pass |
|
326 |
|
# |
|
327 |
|
# # Plot! |
|
328 |
|
# gp.c(gp_plot) |
|
329 |
|
# |
|
330 |
|
# |
|
331 |
|
# |
|
332 |
|
## nikdo mi neuvěří, že by tohle postačílo a nebylo by nutné tohlensto furt úpravovat |
|
333 |
|
#def plot(data2D, terminal='png', filename=''): |
|
334 |
|
# if not filename: |
|
335 |
|
# filename = 'store/plot_%s'%(len(data2D[0])) |
|
336 |
|
# |
|
337 |
|
# gp.c('set terminal ' + terminal) |
|
338 |
|
# gp.c('set output "%s.%s"'%(filename, terminal)) |
|
339 |
|
# if os.name == 'posix': |
|
340 |
|
# gp.c('set decimalsign locale "POSIX"') |
|
341 |
|
# |
|
342 |
|
# |
|
343 |
|
# # se mi zda, že gp bere data v řadcích |
|
344 |
|
# gp.s(data2D, filename+'.dat') |
|
345 |
|
# |
|
346 |
|
# # Plot! |
|
347 |
|
# # rozkaz, který předaváme gnuplotovi |
|
348 |
|
# gp.c('plot "%s.dat" ' % (filename)) |
|
|
48 |
|
# nikdo mi neuvěří, že by tohle postačílo a nebylo by nutné tohlensto furt úpravovat |
|
49 |
|
def plot2D(sample_box, space='R', filename=None, format='pdf'): |
|
50 |
|
if filename is None: |
|
51 |
|
try: |
|
52 |
|
filename = sample_box.filename |
|
53 |
|
except: |
|
54 |
|
filename = 'store/%s_%s_%s_plot2D'%(sample_box.gm_signature, space, sample_box.nsim) |
|
55 |
|
|
|
56 |
|
fig = plt.figure() |
|
57 |
|
ax = fig.add_subplot(111) |
|
58 |
|
ax.space = space |
|
59 |
|
ax.sample_box = sample_box |
|
60 |
|
|
|
61 |
|
mart.setup(ax) |
|
62 |
|
mart.curly(ax) |
|
63 |
|
mart.plot_boundaries(ax, linewidth=0.7) |
|
64 |
|
mart.scatter_points(ax) |
|
65 |
|
try: |
|
66 |
|
mart.triplot(ax, color="grey", linewidth=0.4) |
|
67 |
|
except: |
|
68 |
|
pass |
|
69 |
|
|
|
70 |
|
try: # jen pro formu zkusíme, vždyť musí funkce formálně něco dělat, žejo? |
|
71 |
|
fig.savefig(filename + "." + format, dpi=300) |
|
72 |
|
except: |
|
73 |
|
pass # nic se neděje |
|
74 |
|
|
|
75 |
|
# vracím plt místo figury, protože nechcem sa trapiť ivent lupem |
|
76 |
|
# return plt insted of just fig to bypass event loop issues |
|
77 |
|
return plt.show() |