File blackbox.py changed (mode: 100644) (index 55465d3..db9cde3) |
... |
... |
class Censoring(BlackBox): |
284 |
284 |
|
|
285 |
285 |
def regen(bx): |
def regen(bx): |
286 |
286 |
super().regen() |
super().regen() |
287 |
|
# chcu zachytit spadnuti QHull na začatku, kdy ještě není dostatek teček. |
|
288 |
|
# Jinak je třeba nechat QHull spadnout |
|
|
287 |
|
#č chcu zachytit spadnuti QHull na začatku, kdy ještě není dostatek teček. |
|
288 |
|
#č Jinak je třeba nechat QHull spadnout |
289 |
289 |
if bx.nsim > 2*bx.nvar + 3: |
if bx.nsim > 2*bx.nvar + 3: |
290 |
290 |
# tady je to OK |
# tady je to OK |
291 |
291 |
bx.tri = spatial.Delaunay(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
bx.tri = spatial.Delaunay(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
|
... |
... |
class Censoring(BlackBox): |
299 |
299 |
else: # lze přípustit chybu triangulace |
else: # lze přípustit chybu triangulace |
300 |
300 |
try: |
try: |
301 |
301 |
bx.tri = spatial.Delaunay(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
bx.tri = spatial.Delaunay(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
|
302 |
|
if len(bx.tri.coplanar): |
|
303 |
|
#print('triangulace v pořádku není') |
|
304 |
|
bx._logger(msg='triangulation is coplanar') |
|
305 |
|
else: |
|
306 |
|
#print('triangulace je v pořádku') |
|
307 |
|
bx._logger(msg='triangulation is OK') |
302 |
308 |
except: |
except: |
303 |
309 |
bx._logger(msg='triangulation failed') |
bx._logger(msg='triangulation failed') |
304 |
310 |
|
|
305 |
|
|
|
306 |
|
# pokud tecek nestaci na vytvareni aspon jedneho simplexu - pokrcim rameny |
|
307 |
|
try: |
|
308 |
|
# tady je to OK |
|
309 |
|
bx.tri = spatial.Delaunay(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
|
310 |
|
if len(bx.tri.coplanar): # pokud triangulace je v pořadku |
|
311 |
|
#print('triangulace v pořádku není') |
|
312 |
|
bx._log('triangulation is coplanar') |
|
313 |
|
else: |
|
314 |
|
#print('triangulace je v pořádku') |
|
315 |
|
bx._log('triangulation is OK') |
|
316 |
|
except: |
|
317 |
|
# kdyby neco - berem kramle |
|
318 |
|
bx._log('triangulation failed') |
|
319 |
311 |
|
|
320 |
312 |
|
|
321 |
313 |
# tato metoda je vlastně pro MinEnergyCensoredSampling |
# tato metoda je vlastně pro MinEnergyCensoredSampling |
|
... |
... |
class AdaptiveCensoring(Censoring): |
743 |
735 |
class MinEnergyCensoredSampling(Censoring): |
class MinEnergyCensoredSampling(Censoring): |
744 |
736 |
# už mě to dědění nebaví |
# už mě to dědění nebaví |
745 |
737 |
# без поллитры не разберёшься, что этот слоёный пирог делает |
# без поллитры не разберёшься, что этот слоёный пирог делает |
746 |
|
def __init__(bx, sample_object, tri_space='Rn', tree_space=None, sampling_space=None, kechato_space='U', \ |
|
747 |
|
potencial='ksee', p_norm=2, budget=1000, simplex_budget=100): |
|
|
738 |
|
def __init__(bx, sample_object, tri_space='Rn', tree_space=None,\ |
|
739 |
|
sampling_space=None, kechato_space='U', \ |
|
740 |
|
potencial='ksee', p_norm=2, budget=1000, simplex_budget=100): |
748 |
741 |
|
|
749 |
742 |
bx.sball = sball.Sball(sample_object.nvar) |
bx.sball = sball.Sball(sample_object.nvar) |
750 |
743 |
bx.base_r = bx.sball.get_r(0.5) |
bx.base_r = bx.sball.get_r(0.5) |
|
... |
... |
class MinEnergyCensoredSampling(Censoring): |
788 |
781 |
regen() recreates data structures of the box. |
regen() recreates data structures of the box. |
789 |
782 |
It shouldn't be called without reason, changed distribution, settings or so. |
It shouldn't be called without reason, changed distribution, settings or so. |
790 |
783 |
""" |
""" |
|
784 |
|
# super TRYES to create .tri triangulation |
791 |
785 |
super().regen() |
super().regen() |
792 |
786 |
# zás mám vyhodit odhady? |
# zás mám vyhodit odhady? |
793 |
787 |
bx.siss = IS_stat.ISSI() |
bx.siss = IS_stat.ISSI() |
|
788 |
|
# kind of interface to CandidatesWidget |
794 |
789 |
bx.candidates_index = dict() |
bx.candidates_index = dict() |
795 |
790 |
|
|
|
791 |
|
# needed for potencial calculation |
796 |
792 |
sampled_plan_tree = getattr(bx.sample_box, bx.tree_space) |
sampled_plan_tree = getattr(bx.sample_box, bx.tree_space) |
797 |
793 |
bx.tree = spatial.cKDTree(sampled_plan_tree) |
bx.tree = spatial.cKDTree(sampled_plan_tree) |
798 |
794 |
|
|
|
795 |
|
|
|
796 |
|
bx._regen_outside() |
|
797 |
|
bx._regen_inside() |
|
798 |
|
|
|
799 |
|
|
|
800 |
|
|
|
801 |
|
def _regen_outside(bx): |
|
802 |
|
# function reserved for childs |
|
803 |
|
pass |
|
804 |
|
|
|
805 |
|
|
|
806 |
|
def _regen_inside(bx): |
799 |
807 |
if "tri" in dir(bx): |
if "tri" in dir(bx): |
800 |
808 |
# tri - Deloneho triangulace |
# tri - Deloneho triangulace |
801 |
809 |
bx.simplex_events = bx.get_events() |
bx.simplex_events = bx.get_events() |
|
... |
... |
class MinEnergyCensoredSampling(Censoring): |
804 |
812 |
# zde jen počítame |
# zde jen počítame |
805 |
813 |
bx.estimate_simplex(simplex_id) |
bx.estimate_simplex(simplex_id) |
806 |
814 |
|
|
807 |
|
|
|
808 |
815 |
elif bx.nsim > 0: # požaduji, aby nějaké těčíčky byly vždy pritomné |
elif bx.nsim > 0: # požaduji, aby nějaké těčíčky byly vždy pritomné |
809 |
|
|
|
810 |
|
candidates = IS_stat.IS(bx.f, bx.h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
|
811 |
|
# nevím co tam bylo za h-ko, ale nechť IM zůstane 1 |
|
812 |
|
implicit_multiplicator = 1 |
|
813 |
|
|
|
814 |
|
# teoreticky lze |
|
815 |
|
#bx.siss.add_IS_serie(candidates.w, candidates.simplex, implicit_multiplicator) |
|
816 |
|
|
|
|
816 |
|
#č IS nesmí modifikovat f-ko, |
|
817 |
|
#č a vidím, že tam je to v pořádku |
|
818 |
|
candidates = IS_stat.IS(bx.f_model, bx.h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
817 |
819 |
bx.assess_candidates(candidates) |
bx.assess_candidates(candidates) |
818 |
820 |
# uložíme |
# uložíme |
819 |
821 |
bx.candidates_index[-1] = candidates |
bx.candidates_index[-1] = candidates |
820 |
|
|
|
821 |
|
|
|
822 |
|
|
|
823 |
|
|
|
|
822 |
|
|
|
823 |
|
|
|
824 |
|
|
824 |
825 |
|
|
825 |
826 |
|
|
826 |
827 |
def export_estimation(bx): |
def export_estimation(bx): |
|
... |
... |
class MinEnergyCensoredSampling(Censoring): |
1250 |
1251 |
class OptimizedCensoredSampling(MinEnergyCensoredSampling): |
class OptimizedCensoredSampling(MinEnergyCensoredSampling): |
1251 |
1252 |
|
|
1252 |
1253 |
|
|
1253 |
|
def regen(bx): |
|
1254 |
|
""" |
|
1255 |
|
regen() recreates data structures of the box. |
|
1256 |
|
It shouldn't be called without reason, changed distribution, settings or so. |
|
1257 |
|
""" |
|
|
1254 |
|
def _regen_outside(bx): |
1258 |
1255 |
if bx.nsim >= bx.nvar + 1: |
if bx.nsim >= bx.nvar + 1: |
1259 |
1256 |
try: |
try: |
1260 |
1257 |
bx.convex_hull = spatial.ConvexHull(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
bx.convex_hull = spatial.ConvexHull(getattr(bx.sampled_plan, bx.tri_space), incremental=True) |
|
1258 |
|
bx.estimate_outside() |
|
1259 |
|
#č a máme hotovo |
|
1260 |
|
return # Ok, go away |
1261 |
1261 |
except BaseException as e: |
except BaseException as e: |
1262 |
1262 |
msg = "error of creating ConvexHull " |
msg = "error of creating ConvexHull " |
1263 |
1263 |
error_msg = bx.__class__.__name__ + ": " + msg + repr(e) |
error_msg = bx.__class__.__name__ + ": " + msg + repr(e) |
1264 |
1264 |
bx._logger(msg=error_msg) |
bx._logger(msg=error_msg) |
|
1265 |
|
|
|
1266 |
|
# nothing happened? We are still here? |
|
1267 |
|
# we need to generate at least something |
|
1268 |
|
if bx.nsim > 0: #č požaduji, aby nějaké těčíčky byly vždy pritomné |
|
1269 |
|
|
|
1270 |
|
#č IS nesmí modifikovat f-ko, |
|
1271 |
|
#č a vidím, že tam je to v pořádku |
|
1272 |
|
candidates = IS_stat.IS(bx.f_model, bx.h, space_from_h='R', space_to_f=bx.sampling_space, Nsim=bx.budget) |
1265 |
1273 |
|
|
1266 |
|
super().regen() |
|
|
1274 |
|
bx.assess_candidates(candidates) |
|
1275 |
|
# uložíme |
|
1276 |
|
bx.candidates_index[-1] = candidates |
1267 |
1277 |
|
|
1268 |
1278 |
|
|
1269 |
1279 |
|
|
|
1280 |
|
def _regen_inside(bx): |
|
1281 |
|
#č .tri nemusí vůbec existovat |
|
1282 |
|
if "tri" in dir(bx): |
|
1283 |
|
#č tri - Deloneho triangulace |
|
1284 |
|
bx.simplex_events = bx.get_events() |
|
1285 |
|
for simplex_id in range(bx.tri.nsimplex): |
|
1286 |
|
# zde jen počítame |
|
1287 |
|
bx.estimate_simplex(simplex_id) |
|
1288 |
|
|
|
1289 |
|
|
1270 |
1290 |
|
|
1271 |
1291 |
|
|
1272 |
1292 |
|
|
|
... |
... |
class OptimizedCensoredSampling(MinEnergyCensoredSampling): |
1359 |
1379 |
|
|
1360 |
1380 |
|
|
1361 |
1381 |
def estimate_outside(bx): |
def estimate_outside(bx): |
1362 |
|
# předpokládám, že triangulece jíž existuje |
|
|
1382 |
|
# předpokládám, že convex_hull jíž existuje |
1363 |
1383 |
|
|
1364 |
1384 |
# -1 = 'out', 0=success, 1=failure, 2=mix |
# -1 = 'out', 0=success, 1=failure, 2=mix |
1365 |
1385 |
#current outside probability estimation |
#current outside probability estimation |
|
... |
... |
class OptimizedCensoredSampling(MinEnergyCensoredSampling): |
1444 |
1464 |
|
|
1445 |
1465 |
|
|
1446 |
1466 |
class FastSimpleX(OptimizedCensoredSampling): |
class FastSimpleX(OptimizedCensoredSampling): |
1447 |
|
|
|
|
1467 |
|
|
|
1468 |
|
|
|
1469 |
|
def _regen_inside(bx): |
|
1470 |
|
#č .tri nemusí vůbec existovat |
|
1471 |
|
if "tri" in dir(bx): |
|
1472 |
|
#č tri - Deloneho triangulace |
|
1473 |
|
bx.simplex_events = bx.get_events() |
|
1474 |
|
for simplex_id in range(bx.tri.nsimplex): |
|
1475 |
|
# zde jen počítame |
|
1476 |
|
bx.estimate_simplex(simplex_id) |
|
1477 |
|
|
|
1478 |
|
|
|
1479 |
|
|
1448 |
1480 |
|
|
1449 |
1481 |
def estimate_simplex(bx, simplex_id): |
def estimate_simplex(bx, simplex_id): |
1450 |
1482 |
""" |
""" |